[ Index ] |
|
Code source de WordPress 2.1.2 |
1 <?php 2 require( dirname(__FILE__) . '/wp-config.php' ); 3 4 $action = $_REQUEST['action']; 5 $errors = array(); 6 7 if ( isset($_GET['key']) ) 8 $action = 'resetpass'; 9 10 nocache_headers(); 11 12 header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset')); 13 14 if ( defined('RELOCATE') ) { // Move flag is set 15 if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) ) 16 $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] ); 17 18 $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://'; 19 if ( dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_option('siteurl') ) 20 update_option('siteurl', dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) ); 21 } 22 23 24 // Rather than duplicating this HTML all over the place, we'll stick it in function 25 function login_header($title = 'Login', $message = '') { 26 global $errors, $error, $wp_locale; 27 28 ?> 29 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 30 <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> 31 <head> 32 <title><?php bloginfo('name'); ?> › <?php echo $title; ?></title> 33 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> 34 <link rel="stylesheet" href="<?php bloginfo('wpurl'); ?>/wp-admin/wp-admin.css?version=<?php bloginfo('version'); ?>" type="text/css" /> 35 <?php if ( ('rtl' == $wp_locale->text_direction) ) : ?> 36 <link rel="stylesheet" href="<?php bloginfo('wpurl'); ?>/wp-admin/rtl.css?version=<?php bloginfo('version'); ?>" type="text/css" /> 37 <?php endif; ?> 38 <!--[if IE]><style type="text/css">#login h1 a { margin-top: 35px; } #login #login_error { margin-bottom: 10px; }</style><![endif]--><!-- Curse you, IE! --> 39 <script type="text/javascript"> 40 function focusit() { 41 document.getElementById('user_login').focus(); 42 } 43 window.onload = focusit; 44 </script> 45 <?php do_action('login_head'); ?> 46 </head> 47 <body class="login"> 48 49 <div id="login"><h1><a href="<?php echo apply_filters('login_headerurl', 'http://wordpress.org/'); ?>" title="<?php echo apply_filters('login_headertitle', __('Powered by WordPress')); ?>"><span class="hide"><?php bloginfo('name'); ?></span></a></h1> 50 <?php 51 if ( !empty( $message ) ) echo apply_filters('login_message', $message) . "\n"; 52 53 // Incase a plugin uses $error rather than the $errors array 54 if ( !empty( $error ) ) { 55 $errors['error'] = $error; 56 unset($error); 57 } 58 59 if ( !empty( $errors ) ) { 60 if ( is_array( $errors ) ) { 61 $newerrors = "\n"; 62 foreach ( $errors as $error ) $newerrors .= ' ' . $error . "<br />\n"; 63 $errors = $newerrors; 64 } 65 66 echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n"; 67 } 68 } // End of login_header() 69 70 71 switch ($action) { 72 73 case 'logout' : 74 75 wp_clearcookie(); 76 do_action('wp_logout'); 77 78 $redirect_to = 'wp-login.php?loggedout=true'; 79 if ( isset( $_REQUEST['redirect_to'] ) ) 80 $redirect_to = $_REQUEST['redirect_to']; 81 82 wp_redirect($redirect_to); 83 exit(); 84 85 break; 86 87 case 'lostpassword' : 88 case 'retrievepassword' : 89 $user_login = ''; 90 $user_pass = ''; 91 92 if ( $_POST ) { 93 if ( empty( $_POST['user_login'] ) ) 94 $errors['user_login'] = __('<strong>ERROR</strong>: The username field is empty.'); 95 if ( empty( $_POST['user_email'] ) ) 96 $errors['user_email'] = __('<strong>ERROR</strong>: The e-mail field is empty.'); 97 98 do_action('lostpassword_post'); 99 100 if ( empty( $errors ) ) { 101 $user_data = get_userdatabylogin(trim($_POST['user_login'])); 102 // redefining user_login ensures we return the right case in the email 103 $user_login = $user_data->user_login; 104 $user_email = $user_data->user_email; 105 106 if (!$user_email || $user_email != $_POST['user_email']) { 107 $errors['invalidcombo'] = __('<strong>ERROR</strong>: Invalid username / e-mail combination.'); 108 } else { 109 do_action('retreive_password', $user_login); // Misspelled and deprecated 110 do_action('retrieve_password', $user_login); 111 112 // Generate something random for a password... md5'ing current time with a rand salt 113 $key = substr( md5( uniqid( microtime() ) ), 0, 8); 114 // Now insert the new pass md5'd into the db 115 $wpdb->query("UPDATE $wpdb->users SET user_activation_key = '$key' WHERE user_login = '$user_login'"); 116 $message = __('Someone has asked to reset the password for the following site and username.') . "\r\n\r\n"; 117 $message .= get_option('siteurl') . "\r\n\r\n"; 118 $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n"; 119 $message .= __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.') . "\r\n\r\n"; 120 $message .= get_option('siteurl') . "/wp-login.php?action=rp&key=$key\r\n"; 121 122 if (FALSE == wp_mail($user_email, sprintf(__('[%s] Password Reset'), get_option('blogname')), $message)) { 123 die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>'); 124 } else { 125 wp_redirect('wp-login.php?checkemail=confirm'); 126 exit(); 127 } 128 } 129 } 130 } 131 132 if ( 'invalidkey' == $_GET['error'] ) $errors['invalidkey'] = __('Sorry, that key does not appear to be valid.'); 133 134 do_action('lost_password'); 135 login_header(__('Lost Password'), '<p class="message">' . __('Please enter your username and e-mail address. You will receive a new password via e-mail.') . '</p>'); 136 ?> 137 138 <form name="lostpasswordform" id="lostpasswordform" action="wp-login.php?action=lostpassword" method="post"> 139 <p> 140 <label><?php _e('Username:') ?><br /> 141 <input type="text" name="user_login" id="user_login" class="input" value="<?php echo attribute_escape(stripslashes($_POST['user_login'])); ?>" size="20" tabindex="10" /></label> 142 </p> 143 <p> 144 <label><?php _e('E-mail:') ?><br /> 145 <input type="text" name="user_email" id="user_email" class="input" value="<?php echo attribute_escape(stripslashes($_POST['user_email'])); ?>" size="25" tabindex="20" /></label> 146 </p> 147 <?php do_action('lostpassword_form'); ?> 148 <p class="submit"><input type="submit" name="submit" id="submit" value="<?php _e('Get New Password »'); ?>" tabindex="100" /></p> 149 </form> 150 </div> 151 152 <ul> 153 <?php if (get_option('users_can_register')) : ?> 154 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php"><?php _e('Login') ?></a></li> 155 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=register"><?php _e('Register') ?></a></li> 156 <li><a href="<?php bloginfo('home'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title')); ?></a></li> 157 <?php else : ?> 158 <li><a href="<?php bloginfo('home'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title')); ?></a></li> 159 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php"><?php _e('Login') ?></a></li> 160 <?php endif; ?> 161 </ul> 162 163 </body> 164 </html> 165 <?php 166 break; 167 168 case 'resetpass' : 169 case 'rp' : 170 $key = preg_replace('/[^a-z0-9]/i', '', $_GET['key']); 171 if ( empty( $key ) ) { 172 wp_redirect('wp-login.php?action=lostpassword&error=invalidkey'); 173 exit(); 174 } 175 176 $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_activation_key = '$key'"); 177 if ( empty( $user ) ) { 178 wp_redirect('wp-login.php?action=lostpassword&error=invalidkey'); 179 exit(); 180 } 181 182 do_action('password_reset'); 183 184 // Generate something random for a password... md5'ing current time with a rand salt 185 $new_pass = substr( md5( uniqid( microtime() ) ), 0, 7); 186 $wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$new_pass'), user_activation_key = '' WHERE user_login = '$user->user_login'"); 187 wp_cache_delete($user->ID, 'users'); 188 wp_cache_delete($user->user_login, 'userlogins'); 189 $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n"; 190 $message .= sprintf(__('Password: %s'), $new_pass) . "\r\n"; 191 $message .= get_option('siteurl') . "/wp-login.php\r\n"; 192 193 if (FALSE == wp_mail($user->user_email, sprintf(__('[%s] Your new password'), get_option('blogname')), $message)) { 194 die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>'); 195 } else { 196 // send a copy of password change notification to the admin 197 $message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "\r\n"; 198 wp_mail(get_option('admin_email'), sprintf(__('[%s] Password Lost/Changed'), get_option('blogname')), $message); 199 200 wp_redirect('wp-login.php?checkemail=newpass'); 201 exit(); 202 } 203 break; 204 205 case 'register' : 206 if ( FALSE == get_option('users_can_register') ) { 207 wp_redirect('wp-login.php?registration=disabled'); 208 exit(); 209 } 210 211 if ( $_POST ) { 212 require_once( ABSPATH . WPINC . '/registration.php'); 213 214 $user_login = sanitize_user( $_POST['user_login'] ); 215 $user_email = apply_filters( 'user_registration_email', $_POST['user_email'] ); 216 217 // Check the username 218 if ( $user_login == '' ) 219 $errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.'); 220 elseif ( !validate_username( $user_login ) ) { 221 $errors['user_login'] = __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.'); 222 $user_login = ''; 223 } elseif ( username_exists( $user_login ) ) 224 $errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.'); 225 226 // Check the e-mail address 227 if ($user_email == '') { 228 $errors['user_email'] = __('<strong>ERROR</strong>: Please type your e-mail address.'); 229 } elseif ( !is_email( $user_email ) ) { 230 $errors['user_email'] = __('<strong>ERROR</strong>: The email address isn’t correct.'); 231 $user_email = ''; 232 } elseif ( email_exists( $user_email ) ) 233 $errors['user_email'] = __('<strong>ERROR</strong>: This email is already registered, please choose another one.'); 234 235 do_action('register_post'); 236 237 $errors = apply_filters( 'registration_errors', $errors ); 238 239 if ( empty( $errors ) ) { 240 $user_pass = substr( md5( uniqid( microtime() ) ), 0, 7); 241 242 $user_id = wp_create_user( $user_login, $user_pass, $user_email ); 243 if ( !$user_id ) 244 $errors['registerfail'] = sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email')); 245 else { 246 wp_new_user_notification($user_id, $user_pass); 247 248 wp_redirect('wp-login.php?checkemail=registered'); 249 exit(); 250 } 251 } 252 } 253 254 login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>'); 255 ?> 256 257 <form name="registerform" id="registerform" action="wp-login.php?action=register" method="post"> 258 <p> 259 <label><?php _e('Username:') ?><br /> 260 <input type="text" name="user_login" id="user_login" class="input" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" size="20" tabindex="10" /></label> 261 </p> 262 <p> 263 <label><?php _e('E-mail:') ?><br /> 264 <input type="text" name="user_email" id="user_email" class="input" value="<?php echo attribute_escape(stripslashes($user_email)); ?>" size="25" tabindex="20" /></label> 265 </p> 266 <?php do_action('register_form'); ?> 267 <p id="reg_passmail"><?php _e('A password will be e-mailed to you.') ?></p> 268 <p class="submit"><input type="submit" name="submit" id="submit" value="<?php _e('Register »'); ?>" tabindex="100" /></p> 269 </form> 270 </div> 271 272 <ul> 273 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php"><?php _e('Login') ?></a></li> 274 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=lostpassword" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a></li> 275 <li><a href="<?php bloginfo('home'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title')); ?></a></li> 276 </ul> 277 278 </body> 279 </html> 280 <?php 281 break; 282 283 case 'login' : 284 default: 285 $user_login = ''; 286 $user_pass = ''; 287 $using_cookie = FALSE; 288 289 if ( !isset( $_REQUEST['redirect_to'] ) ) 290 $redirect_to = 'wp-admin/'; 291 else 292 $redirect_to = $_REQUEST['redirect_to']; 293 294 if ( $_POST ) { 295 $user_login = $_POST['log']; 296 $user_login = sanitize_user( $user_login ); 297 $user_pass = $_POST['pwd']; 298 $rememberme = $_POST['rememberme']; 299 } else { 300 $cookie_login = wp_get_cookie_login(); 301 if ( ! empty($cookie_login) ) { 302 $using_cookie = true; 303 $user_login = $cookie_login['login']; 304 $user_pass = $cookie_login['password']; 305 } 306 } 307 308 do_action_ref_array('wp_authenticate', array(&$user_login, &$user_pass)); 309 310 if ( $user_login && $user_pass && empty( $errors ) ) { 311 $user = new WP_User(0, $user_login); 312 313 // If the user can't edit posts, send them to their profile. 314 if ( !$user->has_cap('edit_posts') && ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' ) ) 315 $redirect_to = get_option('siteurl') . '/wp-admin/profile.php'; 316 317 if ( wp_login($user_login, $user_pass, $using_cookie) ) { 318 if ( !$using_cookie ) 319 wp_setcookie($user_login, $user_pass, false, '', '', $rememberme); 320 do_action('wp_login', $user_login); 321 wp_redirect($redirect_to); 322 exit(); 323 } else { 324 if ( $using_cookie ) 325 $errors['expiredsession'] = __('Your session has expired.'); 326 } 327 } 328 329 if ( $_POST && empty( $user_login ) ) 330 $errors['user_login'] = __('<strong>ERROR</strong>: The username field is empty.'); 331 if ( $_POST && empty( $user_pass ) ) 332 $errors['user_pass'] = __('<strong>ERROR</strong>: The password field is empty.'); 333 334 // Some parts of this script use the main login form to display a message 335 if ( TRUE == $_GET['loggedout'] ) $errors['loggedout'] = __('Successfully logged you out.'); 336 elseif ( 'disabled' == $_GET['registration'] ) $errors['registerdiabled'] = __('User registration is currently not allowed.'); 337 elseif ( 'confirm' == $_GET['checkemail'] ) $errors['confirm'] = __('Check your e-mail for the confirmation link.'); 338 elseif ( 'newpass' == $_GET['checkemail'] ) $errors['newpass'] = __('Check your e-mail for your new password.'); 339 elseif ( 'registered' == $_GET['checkemail'] ) $errors['registered'] = __('Registration complete. Please check your e-mail.'); 340 341 login_header(__('Login')); 342 ?> 343 344 <form name="loginform" id="loginform" action="wp-login.php" method="post"> 345 <p> 346 <label><?php _e('Username:') ?><br /> 347 <input type="text" name="log" id="user_login" class="input" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" size="20" tabindex="10" /></label> 348 </p> 349 <p> 350 <label><?php _e('Password:') ?><br /> 351 <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" tabindex="20" /></label> 352 </p> 353 <?php do_action('login_form'); ?> 354 <p><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="90" /> <?php _e('Remember me'); ?></label></p> 355 <p class="submit"> 356 <input type="submit" name="submit" id="submit" value="<?php _e('Login'); ?> »" tabindex="100" /> 357 <input type="hidden" name="redirect_to" value="<?php echo attribute_escape($redirect_to); ?>" /> 358 </p> 359 </form> 360 </div> 361 362 <ul> 363 <?php if (get_option('users_can_register')) : ?> 364 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=register"><?php _e('Register') ?></a></li> 365 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=lostpassword" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a></li> 366 <li><a href="<?php bloginfo('home'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title')); ?></a></li> 367 <?php else : ?> 368 <li><a href="<?php bloginfo('home'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title')); ?></a></li> 369 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php?action=lostpassword" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a></li> 370 <?php endif; ?> 371 </ul> 372 373 374 </body> 375 </html> 376 <?php 377 378 break; 379 } // end action switch 380 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 30 19:41:27 2007 | par Balluche grâce à PHPXref 0.7 |