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