PHP Cross Reference of WordPress Latest 2.0 Branch |
| [ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] |
[Summary view] [Print] [Text view]
1 <?php 2 require( dirname(__FILE__) . '/wp-config.php' ); 3 4 $action = $_REQUEST['action']; 5 $error = ''; 6 7 nocache_headers(); 8 9 header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset')); 10 11 if ( defined('RELOCATE') ) { // Move flag is set 12 if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) ) 13 $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] ); 14 15 $schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://'; 16 if ( dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_settings('siteurl') ) 17 update_option('siteurl', dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) ); 18 } 19 20 switch($action) { 21 22 case 'logout': 23 24 wp_clearcookie(); 25 do_action('wp_logout'); 26 nocache_headers(); 27 28 $redirect_to = 'wp-login.php'; 29 if ( isset($_REQUEST['redirect_to']) ) 30 $redirect_to = $_REQUEST['redirect_to']; 31 32 wp_redirect($redirect_to); 33 exit(); 34 35 break; 36 37 case 'lostpassword': 38 do_action('lost_password'); 39 ?> 40 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 41 <html xmlns="http://www.w3.org/1999/xhtml"> 42 <head> 43 <title>WordPress » <?php _e('Lost Password') ?></title> 44 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> 45 <link rel="stylesheet" href="<?php echo get_settings('siteurl'); ?>/wp-admin/wp-admin.css" type="text/css" /> 46 <script type="text/javascript"> 47 function focusit() { 48 // focus on first input field 49 document.getElementById('user_login').focus(); 50 } 51 window.onload = focusit; 52 </script> 53 <style type="text/css"> 54 #user_login, #email, #submit { 55 font-size: 1.7em; 56 } 57 </style> 58 </head> 59 <body> 60 <div id="login"> 61 <h1><a href="http://wordpress.org/">WordPress</a></h1> 62 <p><?php _e('Please enter your information here. We will send you a new password.') ?></p> 63 <?php 64 if ($error) 65 echo "<div id='login_error'>$error</div>"; 66 ?> 67 68 <form name="lostpass" action="wp-login.php" method="post" id="lostpass"> 69 <p> 70 <input type="hidden" name="action" value="retrievepassword" /> 71 <label><?php _e('Username:') ?><br /> 72 <input type="text" name="user_login" id="user_login" value="" size="20" tabindex="1" /></label></p> 73 <p><label><?php _e('E-mail:') ?><br /> 74 <input type="text" name="email" id="email" value="" size="25" tabindex="2" /></label><br /> 75 </p> 76 <p class="submit"><input type="submit" name="submit" id="submit" value="<?php _e('Retrieve Password'); ?> »" tabindex="3" /></p> 77 </form> 78 <ul> 79 <li><a href="<?php bloginfo('home'); ?>/" title="<?php _e('Are you lost?') ?>">« <?php _e('Back to blog') ?></a></li> 80 <?php if (get_settings('users_can_register')) : ?> 81 <li><a href="<?php bloginfo('wpurl'); ?>/wp-register.php"><?php _e('Register') ?></a></li> 82 <?php endif; ?> 83 <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php"><?php _e('Login') ?></a></li> 84 </ul> 85 </div> 86 </body> 87 </html> 88 <?php 89 break; 90 91 case 'retrievepassword': 92 $user_data = get_userdatabylogin($_POST['user_login']); 93 // redefining user_login ensures we return the right case in the email 94 $user_login = $user_data->user_login; 95 $user_email = $user_data->user_email; 96 97 if (!$user_email || $user_email != $_POST['email']) 98 die(sprintf(__('Sorry, that user does not seem to exist in our database. Perhaps you have the wrong username or e-mail address? <a href="%s">Try again</a>.'), 'wp-login.php?action=lostpassword')); 99 100 do_action('retreive_password', $user_login); // Misspelled and deprecated. 101 do_action('retrieve_password', $user_login); 102 103 // Generate something random for a password... md5'ing current time with a rand salt 104 $key = substr( md5( uniqid( microtime() ) ), 0, 50); 105 // now insert the new pass md5'd into the db 106 $wpdb->query("UPDATE $wpdb->users SET user_activation_key = '$key' WHERE user_login = '$user_login'"); 107 $message = __('Someone has asked to reset the password for the following site and username.') . "\r\n\r\n"; 108 $message .= get_option('siteurl') . "\r\n\r\n"; 109 $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n"; 110 $message .= __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.') . "\r\n\r\n"; 111 $message .= get_settings('siteurl') . "/wp-login.php?action=resetpass&key=$key\r\n"; 112 113 $m = wp_mail($user_email, sprintf(__('[%s] Password Reset'), get_settings('blogname')), $message); 114 115 if ($m == false) { 116 echo '<p>' . __('The e-mail could not be sent.') . "<br />\n"; 117 echo __('Possible reason: your host may have disabled the mail() function...') . "</p>"; 118 die(); 119 } else { 120 echo '<p>' . sprintf(__("The e-mail was sent successfully to %s's e-mail address."), $user_login) . '<br />'; 121 echo "<a href='wp-login.php' title='" . __('Check your e-mail first, of course') . "'>" . __('Click here to login!') . '</a></p>'; 122 die(); 123 } 124 125 break; 126 127 case 'resetpass' : 128 129 // Generate something random for a password... md5'ing current time with a rand salt 130 $key = preg_replace('/[^a-z0-9]/i', '', $_GET['key']); 131 if ( empty($key) ) 132 die( __('Sorry, that key does not appear to be valid.') ); 133 $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_activation_key = '$key'"); 134 if ( !$user ) 135 die( __('Sorry, that key does not appear to be valid.') ); 136 137 do_action('password_reset'); 138 139 $new_pass = substr( md5( uniqid( microtime() ) ), 0, 7); 140 $wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$new_pass'), user_activation_key = '' WHERE user_login = '$user->user_login'"); 141 wp_cache_delete($user->ID, 'users'); 142 wp_cache_delete($user->user_login, 'userlogins'); 143 $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n"; 144 $message .= sprintf(__('Password: %s'), $new_pass) . "\r\n"; 145 $message .= get_settings('siteurl') . "/wp-login.php\r\n"; 146 147 $m = wp_mail($user->user_email, sprintf(__('[%s] Your new password'), get_settings('blogname')), $message); 148 149 if ($m == false) { 150 echo '<p>' . __('The e-mail could not be sent.') . "<br />\n"; 151 echo __('Possible reason: your host may have disabled the mail() function...') . '</p>'; 152 die(); 153 } else { 154 echo '<p>' . sprintf(__('Your new password is in the mail.'), $user_login) . '<br />'; 155 echo "<a href='wp-login.php' title='" . __('Check your e-mail first, of course') . "'>" . __('Click here to login!') . '</a></p>'; 156 // send a copy of password change notification to the admin 157 $message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "\r\n"; 158 wp_mail(get_settings('admin_email'), sprintf(__('[%s] Password Lost/Change'), get_settings('blogname')), $message); 159 die(); 160 } 161 break; 162 163 case 'login' : 164 default: 165 166 $user_login = ''; 167 $user_pass = ''; 168 $using_cookie = false; 169 if ( !isset( $_REQUEST['redirect_to'] ) || is_user_logged_in() ) 170 $redirect_to = 'wp-admin/'; 171 else 172 $redirect_to = $_REQUEST['redirect_to']; 173 174 if( $_POST ) { 175 $user_login = $_POST['log']; 176 $user_login = sanitize_user( $user_login ); 177 $user_pass = $_POST['pwd']; 178 $rememberme = $_POST['rememberme']; 179 } else { 180 $cookie_login = wp_get_cookie_login(); 181 if ( ! empty($cookie_login) ) { 182 $using_cookie = true; 183 $user_login = $cookie_login['login']; 184 $user_pass = $cookie_login['password']; 185 } 186 } 187 188 do_action('wp_authenticate', array(&$user_login, &$user_pass)); 189 190 if ( $user_login && $user_pass ) { 191 $user = new WP_User(0, $user_login); 192 193 // If the user can't edit posts, send them to their profile. 194 if ( !$user->has_cap('edit_posts') && ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' ) ) 195 $redirect_to = get_settings('siteurl') . '/wp-admin/profile.php'; 196 197 if ( wp_login($user_login, $user_pass, $using_cookie) ) { 198 if ( !$using_cookie ) 199 wp_setcookie($user_login, $user_pass, false, '', '', $rememberme); 200 do_action('wp_login', $user_login); 201 wp_redirect($redirect_to); 202 exit; 203 } else { 204 if ( $using_cookie ) 205 $error = __('Your session has expired.'); 206 } 207 } else if ( $user_login || $user_pass ) { 208 $error = __('<strong>Error</strong>: The password field is empty.'); 209 } 210 ?> 211 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 212 <html xmlns="http://www.w3.org/1999/xhtml"> 213 <head> 214 <title>WordPress › <?php _e('Login') ?></title> 215 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> 216 <link rel="stylesheet" href="<?php bloginfo('wpurl'); ?>/wp-admin/wp-admin.css" type="text/css" /> 217 <script type="text/javascript"> 218 function focusit() { 219 document.getElementById('log').focus(); 220 } 221 window.onload = focusit; 222 </script> 223 </head> 224 <body> 225 226 <div id="login"> 227 <h1><a href="http://wordpress.org/">WordPress</a></h1> 228 <?php 229 if ( $error ) 230 echo "<div id='login_error'>$error</div>"; 231 ?> 232 233 <form name="loginform" id="loginform" action="wp-login.php" method="post"> 234 <p><label><?php _e('Username:') ?><br /><input type="text" name="log" id="log" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" size="20" tabindex="1" /></label></p> 235 <p><label><?php _e('Password:') ?><br /> <input type="password" name="pwd" id="pwd" value="" size="20" tabindex="2" /></label></p> 236 <p> 237 <label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="3" /> 238 <?php _e('Remember me'); ?></label></p> 239 <p class="submit"> 240 <input type="submit" name="submit" id="submit" value="<?php _e('Login'); ?> »" tabindex="4" /> 241 <input type="hidden" name="redirect_to" value="<?php echo attribute_escape($redirect_to); ?>" /> 242 </p> 243 </form> 244 <ul> 245 <li><a href="<?php bloginfo('home'); ?>/" title="<?php _e('Are you lost?') ?>">« <?php _e('Back to blog') ?></a></li> 246 <?php if (get_settings('users_can_register')) : ?> 247 <li><a href="<?php bloginfo('wpurl'); ?>/wp-register.php"><?php _e('Register') ?></a></li> 248 <?php endif; ?> 249 <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> 250 </ul> 251 </div> 252 253 </body> 254 </html> 255 <?php 256 257 break; 258 } // end action switch 259 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated Sun Dec 2 06:47:37 2007 for RedAlt XRefs | Cross-referenced by PHPXref 0.6 and RedAlt |