| 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') ) { |
|---|
| 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 |
setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN); |
|---|
| 25 |
if ( SITECOOKIEPATH != COOKIEPATH ) |
|---|
| 26 |
setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN); |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
function login_header($title = 'Login', $message = '') { |
|---|
| 30 |
global $errors, $error, $wp_locale, $current_site; |
|---|
| 31 |
|
|---|
| 32 |
?> |
|---|
| 33 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| 34 |
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>> |
|---|
| 35 |
<head> |
|---|
| 36 |
<title><?php bloginfo('name'); ?> › <?php echo $title; ?></title> |
|---|
| 37 |
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> |
|---|
| 38 |
<?php wp_admin_css(); ?> |
|---|
| 39 |
<!--[if IE]><style type="text/css">#login h1 a { margin-top: 35px; } #login #login_error { margin-bottom: 10px; }</style><![endif]--><!-- Curse you, IE! --> |
|---|
| 40 |
<script type="text/javascript"> |
|---|
| 41 |
function focusit() { |
|---|
| 42 |
document.getElementById('user_login').focus(); |
|---|
| 43 |
} |
|---|
| 44 |
window.onload = focusit; |
|---|
| 45 |
</script> |
|---|
| 46 |
<?php do_action('login_head'); ?> |
|---|
| 47 |
</head> |
|---|
| 48 |
<body class="login"> |
|---|
| 49 |
|
|---|
| 50 |
<div id="login"><h1><a href="<?php echo apply_filters('login_headerurl', 'http://' . $current_site->domain . $current_site->path ); ?>" title="<?php echo apply_filters('login_headertitle', $current_site->site_name ); ?>"><span class="hide"><?php bloginfo('name'); ?></span></a></h1> |
|---|
| 51 |
<?php |
|---|
| 52 |
if ( !empty( $message ) ) echo apply_filters('login_message', $message) . "\n"; |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
if ( !empty( $error ) ) { |
|---|
| 56 |
$errors['error'] = $error; |
|---|
| 57 |
unset($error); |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
if ( !empty( $errors ) ) { |
|---|
| 61 |
if ( is_array( $errors ) ) { |
|---|
| 62 |
$newerrors = "\n"; |
|---|
| 63 |
foreach ( $errors as $error ) $newerrors .= ' ' . $error . "<br />\n"; |
|---|
| 64 |
$errors = $newerrors; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n"; |
|---|
| 68 |
echo "<p align='center'>".__("<strong>Note:</strong> You must <a style=\"color: #fff;\" href='http://www.google.com/cookies.html'>enable cookies</a> to use this site.")."</p>"; |
|---|
| 69 |
} |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
switch ($action) { |
|---|
| 74 |
|
|---|
| 75 |
case 'logout' : |
|---|
| 76 |
|
|---|
| 77 |
wp_clearcookie(); |
|---|
| 78 |
do_action('wp_logout'); |
|---|
| 79 |
|
|---|
| 80 |
$redirect_to = 'wp-login.php?loggedout=true'; |
|---|
| 81 |
if ( isset( $_REQUEST['redirect_to'] ) ) |
|---|
| 82 |
$redirect_to = $_REQUEST['redirect_to']; |
|---|
| 83 |
|
|---|
| 84 |
wp_safe_redirect($redirect_to); |
|---|
| 85 |
exit(); |
|---|
| 86 |
|
|---|
| 87 |
break; |
|---|
| 88 |
|
|---|
| 89 |
case 'lostpassword' : |
|---|
| 90 |
case 'retrievepassword' : |
|---|
| 91 |
$user_login = ''; |
|---|
| 92 |
$user_pass = ''; |
|---|
| 93 |
|
|---|
| 94 |
if ( $_POST ) { |
|---|
| 95 |
if ( empty( $_POST['user_login'] ) ) |
|---|
| 96 |
$errors['user_login'] = __('<strong>ERROR</strong>: The username field is empty.'); |
|---|
| 97 |
if ( empty( $_POST['user_email'] ) ) |
|---|
| 98 |
$errors['user_email'] = __('<strong>ERROR</strong>: The e-mail field is empty.'); |
|---|
| 99 |
|
|---|
| 100 |
do_action('lostpassword_post'); |
|---|
| 101 |
|
|---|
| 102 |
if ( empty( $errors ) ) { |
|---|
| 103 |
$user_data = get_userdatabylogin(trim($_POST['user_login'])); |
|---|
| 104 |
|
|---|
| 105 |
$user_login = $user_data->user_login; |
|---|
| 106 |
$user_email = $user_data->user_email; |
|---|
| 107 |
|
|---|
| 108 |
if (!$user_email || $user_email != $_POST['user_email']) { |
|---|
| 109 |
$errors['invalidcombo'] = __('<strong>ERROR</strong>: Invalid username / e-mail combination.'); |
|---|
| 110 |
} else { |
|---|
| 111 |
do_action('retreive_password', $user_login); |
|---|
| 112 |
do_action('retrieve_password', $user_login); |
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 |
$key = substr( md5( uniqid( microtime() ) ), 0, 8); |
|---|
| 116 |
|
|---|
| 117 |
$wpdb->query("UPDATE $wpdb->users SET user_activation_key = '$key' WHERE user_login = '$user_login'"); |
|---|
| 118 |
$message = __('Someone has asked to reset the password for the following site and username.') . "\r\n\r\n"; |
|---|
| 119 |
$message .= get_option('siteurl') . "\r\n\r\n"; |
|---|
| 120 |
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n"; |
|---|
| 121 |
$message .= __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.') . "\r\n\r\n"; |
|---|
| 122 |
$message .= get_option('siteurl') . "/wp-login.php?action=rp&key=$key\r\n"; |
|---|
| 123 |
|
|---|
| 124 |
if (FALSE == wp_mail($user_email, sprintf(__('[%s] Password Reset'), get_option('blogname')), $message)) { |
|---|
| 125 |
die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>'); |
|---|
| 126 |
} else { |
|---|
| 127 |
wp_redirect('wp-login.php?checkemail=confirm'); |
|---|
| 128 |
exit(); |
|---|
| 129 |
} |
|---|
| 130 |
} |
|---|
| 131 |
} |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
if ( 'invalidkey' == $_GET['error'] ) $errors['invalidkey'] = __('Sorry, that key does not appear to be valid.'); |
|---|
| 135 |
|
|---|
| 136 |
do_action('lost_password'); |
|---|
| 137 |
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>'); |
|---|
| 138 |
?> |
|---|
| 139 |
|
|---|
| 140 |
<form name="lostpasswordform" id="lostpasswordform" action="wp-login.php?action=lostpassword" method="post"> |
|---|
| 141 |
<p> |
|---|
| 142 |
<label><?php _e('Username:') ?><br /> |
|---|
| 143 |
<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> |
|---|
| 144 |
</p> |
|---|
| 145 |
<p> |
|---|
| 146 |
<label><?php _e('E-mail:') ?><br /> |
|---|
| 147 |
<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> |
|---|
| 148 |
</p> |
|---|
| 149 |
<?php do_action('lostpassword_form'); ?> |
|---|
| 150 |
<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Get New Password »'); ?>" tabindex="100" /></p> |
|---|
| 151 |
</form> |
|---|
| 152 |
</div> |
|---|
| 153 |
|
|---|
| 154 |
<ul> |
|---|
| 155 |
<?php if (get_option('users_can_register')) : ?> |
|---|
| 156 |
<li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php"><?php _e('Login') ?></a></li> |
|---|
| 157 |
<li><a href="<?php bloginfo('wpurl'); ?>/wp-signup.php"><?php _e('Register') ?></a></li> |
|---|
| 158 |
<li><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title')); ?></a></li> |
|---|
| 159 |
<?php else : ?> |
|---|
| 160 |
<li><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title')); ?></a></li> |
|---|
| 161 |
<li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php"><?php _e('Login') ?></a></li> |
|---|
| 162 |
<?php endif; ?> |
|---|
| 163 |
</ul> |
|---|
| 164 |
|
|---|
| 165 |
</body> |
|---|
| 166 |
</html> |
|---|
| 167 |
<?php |
|---|
| 168 |
break; |
|---|
| 169 |
|
|---|
| 170 |
case 'resetpass' : |
|---|
| 171 |
case 'rp' : |
|---|
| 172 |
$key = preg_replace('/[^a-z0-9]/i', '', $_GET['key']); |
|---|
| 173 |
if ( empty( $key ) ) { |
|---|
| 174 |
wp_redirect('wp-login.php?action=lostpassword&error=invalidkey'); |
|---|
| 175 |
exit(); |
|---|
| 176 |
} |
|---|
| 177 |
|
|---|
| 178 |
$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_activation_key = '$key'"); |
|---|
| 179 |
if ( empty( $user ) ) { |
|---|
| 180 |
wp_redirect('wp-login.php?action=lostpassword&error=invalidkey'); |
|---|
| 181 |
exit(); |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
do_action('password_reset'); |
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
$new_pass = substr( md5( uniqid( microtime() ) ), 0, 7); |
|---|
| 188 |
$wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$new_pass'), user_activation_key = '' WHERE user_login = '$user->user_login'"); |
|---|
| 189 |
wp_cache_delete($user->ID, 'users'); |
|---|
| 190 |
wp_cache_delete($user->user_login, 'userlogins'); |
|---|
| 191 |
$message = sprintf(__('Username: %s'), $user->user_login) . "\r\n"; |
|---|
| 192 |
$message .= sprintf(__('Password: %s'), $new_pass) . "\r\n"; |
|---|
| 193 |
$message .= get_option('siteurl') . "/wp-login.php\r\n"; |
|---|
| 194 |
|
|---|
| 195 |
if (FALSE == wp_mail($user->user_email, sprintf(__('[%s] Your new password'), get_option('blogname')), $message)) { |
|---|
| 196 |
die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>'); |
|---|
| 197 |
} else { |
|---|
| 198 |
wp_redirect('wp-login.php?checkemail=newpass'); |
|---|
| 199 |
exit(); |
|---|
| 200 |
} |
|---|
| 201 |
break; |
|---|
| 202 |
|
|---|
| 203 |
case 'auth' : |
|---|
| 204 |
$_COOKIE = array(); |
|---|
| 205 |
|
|---|
| 206 |
case 'login' : |
|---|
| 207 |
default: |
|---|
| 208 |
$user_login = ''; |
|---|
| 209 |
$user_pass = ''; |
|---|
| 210 |
$using_cookie = FALSE; |
|---|
| 211 |
|
|---|
| 212 |
if ( !isset( $_REQUEST['redirect_to'] ) || is_user_logged_in() ) |
|---|
| 213 |
$redirect_to = 'wp-admin/'; |
|---|
| 214 |
else |
|---|
| 215 |
$redirect_to = $_REQUEST['redirect_to']; |
|---|
| 216 |
|
|---|
| 217 |
if ( $_POST ) { |
|---|
| 218 |
$user_login = $_POST['log']; |
|---|
| 219 |
$user_login = sanitize_user( $user_login ); |
|---|
| 220 |
$user_pass = $_POST['pwd']; |
|---|
| 221 |
$rememberme = $_POST['rememberme']; |
|---|
| 222 |
} else { |
|---|
| 223 |
$cookie_login = wp_get_cookie_login(); |
|---|
| 224 |
if ( ! empty($cookie_login) ) { |
|---|
| 225 |
$using_cookie = true; |
|---|
| 226 |
$user_login = $cookie_login['login']; |
|---|
| 227 |
$user_pass = $cookie_login['password']; |
|---|
| 228 |
} |
|---|
| 229 |
} |
|---|
| 230 |
|
|---|
| 231 |
do_action_ref_array('wp_authenticate', array(&$user_login, &$user_pass)); |
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
if ( $_POST && empty($_COOKIE[TEST_COOKIE]) ) |
|---|
| 235 |
$errors['test_cookie'] = __('<strong>ERROR</strong>: WordPress requires Cookies but your browser does not support them or they are blocked.'); |
|---|
| 236 |
|
|---|
| 237 |
if ( $user_login && $user_pass && empty( $errors ) ) { |
|---|
| 238 |
$user = new WP_User(0, $user_login); |
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
if ( !$user->has_cap('edit_posts') && ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' ) ) |
|---|
| 242 |
$redirect_to = get_option('siteurl') . '/wp-admin/profile.php'; |
|---|
| 243 |
|
|---|
| 244 |
if ( wp_login($user_login, $user_pass, $using_cookie) ) { |
|---|
| 245 |
if ( !$using_cookie ) |
|---|
| 246 |
wp_setcookie($user_login, $user_pass, false, '', '', $rememberme); |
|---|
| 247 |
do_action('wp_login', $user_login); |
|---|
| 248 |
wp_safe_redirect($redirect_to); |
|---|
| 249 |
exit(); |
|---|
| 250 |
} else { |
|---|
| 251 |
if ( $using_cookie ) |
|---|
| 252 |
$errors['expiredsession'] = __('Your session has expired.'); |
|---|
| 253 |
} |
|---|
| 254 |
} |
|---|
| 255 |
|
|---|
| 256 |
if ( $_POST && empty( $user_login ) ) |
|---|
| 257 |
$errors['user_login'] = __('<strong>ERROR</strong>: The username field is empty.'); |
|---|
| 258 |
if ( $_POST && empty( $user_pass ) ) |
|---|
| 259 |
$errors['user_pass'] = __('<strong>ERROR</strong>: The password field is empty.'); |
|---|
| 260 |
|
|---|
| 261 |
|
|---|
| 262 |
if ( TRUE == $_GET['loggedout'] ) $errors['loggedout'] = __('Successfully logged you out.'); |
|---|
| 263 |
elseif ( 'disabled' == $_GET['registration'] ) $errors['registerdiabled'] = __('User registration is currently not allowed.'); |
|---|
| 264 |
elseif ( 'confirm' == $_GET['checkemail'] ) $errors['confirm'] = __('Check your e-mail for the confirmation link.'); |
|---|
| 265 |
elseif ( 'newpass' == $_GET['checkemail'] ) $errors['newpass'] = __('Check your e-mail for your new password.'); |
|---|
| 266 |
elseif ( 'registered' == $_GET['checkemail'] ) $errors['registered'] = __('Registration complete. Please check your e-mail.'); |
|---|
| 267 |
|
|---|
| 268 |
if ( ! is_user_logged_in() ) |
|---|
| 269 |
wp_clearcookie(); |
|---|
| 270 |
login_header(__('Login')); |
|---|
| 271 |
?> |
|---|
| 272 |
|
|---|
| 273 |
<form name="loginform" id="loginform" action="http://<?php echo $current_blog->domain . $current_blog->path ?>wp-login.php" method="post"> |
|---|
| 274 |
<?php if ( !in_array( $_GET['checkemail'], array('confirm', 'newpass') ) ) : ?> |
|---|
| 275 |
<p> |
|---|
| 276 |
<label><?php _e('Username:') ?><br /> |
|---|
| 277 |
<input type="text" name="log" id="user_login" class="input" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" size="20" tabindex="10" /></label> |
|---|
| 278 |
</p> |
|---|
| 279 |
<p> |
|---|
| 280 |
<label><?php _e('Password:') ?><br /> |
|---|
| 281 |
<input type="password" name="pwd" id="user_pass" class="input" value="" size="20" tabindex="20" /></label> |
|---|
| 282 |
</p> |
|---|
| 283 |
<?php do_action('login_form'); ?> |
|---|
| 284 |
<p><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="90" /> <?php _e('Remember me'); ?></label></p> |
|---|
| 285 |
<p class="submit"> |
|---|
| 286 |
<input type="submit" name="wp-submit" id="wp-submit" value="<?php _e('Login'); ?> »" tabindex="100" /> |
|---|
| 287 |
<input type="hidden" name="redirect_to" value="<?php echo attribute_escape($redirect_to); ?>" /> |
|---|
| 288 |
</p> |
|---|
| 289 |
<?php else : ?> |
|---|
| 290 |
<p> </p> |
|---|
| 291 |
<?php endif; ?> |
|---|
| 292 |
</form> |
|---|
| 293 |
</div> |
|---|
| 294 |
|
|---|
| 295 |
<ul> |
|---|
| 296 |
<?php if ( in_array( $_GET['checkemail'], array('confirm', 'newpass') ) ) : ?> |
|---|
| 297 |
<li><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title', 'display')); ?></a></li> |
|---|
| 298 |
<?php elseif (get_option('users_can_register')) : ?> |
|---|
| 299 |
<li><a href="<?php bloginfo('wpurl'); ?>/wp-signup.php"><?php _e('Register') ?></a></li> |
|---|
| 300 |
<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> |
|---|
| 301 |
<li><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title', 'display')); ?></a></li> |
|---|
| 302 |
<?php else : ?> |
|---|
| 303 |
<li><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('Back to %s'), get_bloginfo('title', 'display')); ?></a></li> |
|---|
| 304 |
<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> |
|---|
| 305 |
<?php endif; ?> |
|---|
| 306 |
</ul> |
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
</body> |
|---|
| 310 |
</html> |
|---|
| 311 |
<?php |
|---|
| 312 |
|
|---|
| 313 |
break; |
|---|
| 314 |
} |
|---|
| 315 |
?> |
|---|
| 316 |
|
|---|