Changeset 791

Show
Ignore:
Timestamp:
10/05/06 17:57:03 (2 years ago)
Author:
donncha
Message:

WP Merge

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-login.php

    r744 r791  
    33 
    44$action = $_REQUEST['action']; 
    5 $error = ''
     5$errors = array()
    66 
    77if ( isset($_GET['key']) ) 
     
    2121} 
    2222 
    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 ?> 
     23 
     24// Rather than duplicating this HTML all over the place, we'll stick it in function 
     25function login_header($title = 'Login', $message = '') { 
     26        global $errors, $error; 
     27 
     28        ?> 
    4329<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    4430<html xmlns="http://www.w3.org/1999/xhtml"> 
    4531<head> 
    46         <title>WordPress &raquo; <?php _e('Lost Password') ?></title> 
     32        <title><?php bloginfo('name'); ?> &rsaquo; <?php echo $title; ?></title> 
    4733        <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> 
    48         <link rel="stylesheet" href="<?php echo get_option('siteurl'); ?>/wp-admin/wp-admin.css" type="text/css" /> 
     34        <link rel="stylesheet" href="<?php bloginfo('wpurl'); ?>/wp-admin/wp-admin.css?version=<?php bloginfo('version'); ?>" type="text/css" /> 
     35        <!--[if IE]><style type="text/css">#login h1 a { margin-top: 35px; } #login ul { padding-bottom: 65px; }</style><![endif]--><!-- Curse you, IE! --> 
    4936        <script type="text/javascript"> 
    50         function focusit() { 
    51                 // focus on first input field 
    52                 document.getElementById('user_login').focus(); 
    53         } 
    54         window.onload = focusit; 
     37                function focusit() { 
     38                        document.getElementById('user_login').focus(); 
     39                } 
     40                window.onload = focusit; 
    5541        </script> 
    56         <style type="text/css"> 
    57         #user_login, #email, #submit { 
    58                 font-size: 1.7em; 
    59         } 
    60         </style> 
     42<?php do_action('login_head'); ?> 
    6143</head> 
    6244<body> 
     45 
    6346<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>"; 
     47<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> 
     48<?php 
     49        if ( !empty( $message ) ) echo apply_filters('login_message', $message) . "\n"; 
     50 
     51        // Incase a plugin uses $error rather than the $errors array 
     52        if ( !empty( $error ) ) { 
     53                $errors['error'] = $error; 
     54                unset($error); 
     55        } 
     56 
     57        if ( !empty( $errors ) ) { 
     58                if ( is_array( $errors ) ) { 
     59                        $newerrors = "\n"; 
     60                        foreach ( $errors as $error ) $newerrors .= '   ' . $error . "<br />\n"; 
     61                        $errors = $newerrors; 
     62                } 
     63 
     64                echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n"; 
     65                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>"; 
     66        } 
     67} // End of login_header() 
     68 
     69 
     70switch ($action) { 
     71 
     72case 'logout' : 
     73 
     74        wp_clearcookie(); 
     75        do_action('wp_logout'); 
     76 
     77        $redirect_to = 'wp-login.php?loggedout=true'; 
     78        if ( isset( $_REQUEST['redirect_to'] ) ) 
     79                $redirect_to = $_REQUEST['redirect_to']; 
     80 
     81        wp_redirect($redirect_to); 
     82        exit(); 
     83 
     84break; 
     85 
     86case 'lostpassword' : 
     87case 'retrievepassword' : 
     88        $user_login = ''; 
     89        $user_pass = ''; 
     90 
     91        if ( $_POST ) { 
     92                if ( empty( $_POST['user_login'] ) ) 
     93                        $errors['user_login'] = __('<strong>ERROR</strong>: The username field is empty.'); 
     94                if ( empty( $_POST['user_email'] ) ) 
     95                        $errors['user_email'] = __('<strong>ERROR</strong>: The e-mail field is empty.'); 
     96 
     97                do_action('lostpassword_post'); 
     98                 
     99                if ( empty( $errors ) ) { 
     100                        $user_data = get_userdatabylogin(trim($_POST['user_login'])); 
     101                        // redefining user_login ensures we return the right case in the email 
     102                        $user_login = $user_data->user_login; 
     103                        $user_email = $user_data->user_email; 
     104 
     105                        if (!$user_email || $user_email != $_POST['user_email']) { 
     106                                $errors['invalidcombo'] = __('<strong>ERROR</strong>: Invalid username / e-mail combination.'); 
     107                        } else { 
     108                                do_action('retreive_password', $user_login);  // Misspelled and deprecated 
     109                                do_action('retrieve_password', $user_login); 
     110 
     111                                // Generate something random for a password... md5'ing current time with a rand salt 
     112                                $key = substr( md5( uniqid( microtime() ) ), 0, 8); 
     113                                // Now insert the new pass md5'd into the db 
     114                                $wpdb->query("UPDATE $wpdb->users SET user_activation_key = '$key' WHERE user_login = '$user_login'"); 
     115                                $message = __('Someone has asked to reset the password for the following site and username.') . "\r\n\r\n"; 
     116                                $message .= get_option('siteurl') . "\r\n\r\n"; 
     117                                $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n"; 
     118                                $message .= __('To reset your password visit the following address, otherwise just ignore this email and nothing will happen.') . "\r\n\r\n"; 
     119                                $message .= get_option('siteurl') . "/wp-login.php?action=rp&key=$key\r\n"; 
     120 
     121                                if (FALSE == wp_mail($user_email, sprintf(__('[%s] Password Reset'), get_option('blogname')), $message)) { 
     122                                        die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>'); 
     123                                } else { 
     124                                        wp_redirect('wp-login.php?checkemail=confirm'); 
     125                                        exit(); 
     126                                } 
     127                        } 
     128                } 
     129        } 
     130 
     131        if ( 'invalidkey' == $_GET['error'] ) $errors['invalidkey'] = __('Sorry, that key does not appear to be valid.'); 
     132 
     133        do_action('lost_password'); 
     134        login_header(__('Lost Password'), '<p class="message">' . __('Please enter your username and e-mail address. You will recieve a new password via e-mail.') . '</p>'); 
    69135?> 
    70136 
    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 &raquo;'); ?>" tabindex="3" /></p> 
     137<form name="lostpasswordform" id="lostpasswordform" action="wp-login.php?action=lostpassword" method="post"> 
     138        <p> 
     139                <label><?php _e('Username:') ?><br /> 
     140                <input type="text" name="user_login" id="user_login" class="input" value="<?php echo wp_specialchars(stripslashes($_POST['user_login']), 1); ?>" size="20" tabindex="10" /></label> 
     141        </p> 
     142        <p> 
     143                <label><?php _e('E-mail:') ?><br /> 
     144                <input type="text" name="user_email" id="user_email" class="input" value="<?php echo wp_specialchars(stripslashes($_POST['user_email']), 1); ?>" size="25" tabindex="20" /></label> 
     145        </p> 
     146<?php do_action('lostpassword_form'); ?> 
     147        <p class="submit"><input type="submit" name="submit" id="submit" value="<?php _e('Get New Password &raquo;'); ?>" tabindex="100" /></p> 
    80148</form> 
    81149<ul> 
     150<?php if (get_option('users_can_register')) : ?> 
     151        <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php"><?php _e('Login') ?></a></li> 
     152        <li><a href="<?php bloginfo('wpurl'); ?>/signup/"><?php _e('Register') ?></a></li> 
     153        <li><a href="<?php bloginfo('home'); ?>/" title="<?php _e('Are you lost?') ?>" class="fullwidth">&laquo; <?php _e('Back to blog') ?></a></li> 
     154<?php else : ?> 
    82155        <li><a href="<?php bloginfo('home'); ?>/" title="<?php _e('Are you lost?') ?>">&laquo; <?php _e('Back to blog') ?></a></li> 
    83 <?php if (get_option('users_can_register')) : ?> 
    84         <li><a href="<?php bloginfo('wpurl'); ?>/wp-signup.php"><?php _e('Register') ?></a></li> 
     156        <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php"><?php _e('Login') ?></a></li> 
    85157<?php endif; ?> 
    86         <li><a href="<?php bloginfo('wpurl'); ?>/wp-login.php"><?php _e('Login') ?></a></li> 
    87158</ul> 
    88159</div> 
     
    92163break; 
    93164 
    94 case 'retrievepassword': 
    95         $user_data = get_userdatabylogin(trim($_POST['user_login'])); 
    96         // redefining user_login ensures we return the right case in the email 
    97         $user_login = $user_data->user_login; 
    98         $user_email = $user_data->user_email; 
    99  
    100         if (!$user_email || $user_email != $_POST['email']) 
    101                 wp_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);  // Misspelled and deprecated. 
    104 do_action('retrieve_password', $user_login); 
    105  
    106         // Generate something random for a password... md5'ing current time with a rand salt 
    107         $key = substr( md5( uniqid( microtime() ) ), 0, 8); 
    108         // now insert the new pass md5'd into the db 
    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_option('siteurl') . "/wp-login.php?action=rp&key=$key\r\n"; 
    115  
    116         $m = wp_mail($user_email, sprintf(__('[%s] Password Reset'), get_option('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  
    130165case 'resetpass' : 
    131166case 'rp' : 
     167        $key = preg_replace('/a-z0-9/i', '', $_GET['key']); 
     168        if ( empty( $key ) ) { 
     169                wp_redirect('wp-login.php?action=lostpassword&error=invalidkey'); 
     170                exit(); 
     171        } 
     172 
     173        $user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_activation_key = '$key'"); 
     174        if ( empty( $user ) ) { 
     175                wp_redirect('wp-login.php?action=lostpassword&error=invalidkey'); 
     176                exit(); 
     177        } 
     178 
     179        do_action('password_reset'); 
     180 
    132181        // Generate something random for a password... md5'ing current time with a rand salt 
    133         $key = preg_replace('/a-z0-9/i', '', $_GET['key']); 
    134         if ( empty($key) ) 
    135                 wp_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                 wp_die( __('Sorry, that key does not appear to be valid.') ); 
    139  
    140         do_action('password_reset'); 
    141  
    142182        $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'"); 
     183      $wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$new_pass'), user_activation_key = '' WHERE user_login = '$user->user_login'"); 
    144184        wp_cache_delete($user->ID, 'users'); 
    145185        wp_cache_delete($user->user_login, 'userlogins'); 
     
    148188        $message .= get_option('siteurl') . "/wp-login.php\r\n"; 
    149189 
    150         $m = wp_mail($user->user_email, sprintf(__('[%s] Your new password'), get_option('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(); 
     190        if (FALSE == wp_mail($user->user_email, sprintf(__('[%s] Your new password'), get_option('blogname')), $message)) { 
     191                die('<p>' . __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') . '</p>'); 
    156192        } 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                 // send a copy of password change notification to the admin 
    160                 $message = sprintf(__('Password Lost and Changed for user: %s'), $user->user_login) . "\r\n"; 
    161                 wp_mail(get_option('admin_email'), sprintf(__('[%s] Password Lost/Changed'), get_option('blogname')), $message); 
    162                 die(); 
    163         } 
    164 break; 
     193                wp_redirect('wp-login.php?checkemail=newpass'); 
     194                exit(); 
     195        } 
     196break; 
     197 
     198case 'auth' : 
     199        $_COOKIE = array(); // Prevent redirect loops caused by corrupted cookies 
    165200 
    166201case 'login' :  
    167202default: 
    168  
    169203        $user_login = ''; 
    170204        $user_pass = ''; 
    171         $using_cookie = false; 
     205        $using_cookie = FALSE; 
     206 
    172207        if ( !isset( $_REQUEST['redirect_to'] ) ) 
    173208                $redirect_to = 'wp-admin/'; 
     
    175210                $redirect_to = $_REQUEST['redirect_to']; 
    176211 
    177         if( $_POST ) { 
    178                 $user_login = $_POST['log']; 
     212        if ( $_POST ) { 
     213                $user_login = $_POST['user_login']; 
    179214                $user_login = sanitize_user( $user_login ); 
    180                 $user_pass  = $_POST['pwd']; 
     215                $user_pass  = $_POST['user_pass']; 
    181216                $rememberme = $_POST['rememberme']; 
    182217        } else { 
     
    191226        do_action_ref_array('wp_authenticate', array(&$user_login, &$user_pass)); 
    192227 
    193         if ( $user_login && $user_pass ) { 
     228        if ( $user_login && $user_pass && empty( $errors ) ) { 
    194229                $user = new WP_User(0, $user_login); 
    195230 
     
    203238                        do_action('wp_login', $user_login); 
    204239                        wp_redirect($redirect_to); 
    205                         exit
     240                        exit()
    206241                } else { 
    207242                        if ( $using_cookie ) 
    208                                 $error = __('Your session has expired.'); 
    209                 } 
    210         } else if ( $user_login || $user_pass ) { 
    211                 $error = __('<strong>Error</strong>: The password field is empty.'); 
    212         } 
     243                                $errors['expiredsession'] = __('Your session has expired.'); 
     244                } 
     245        } 
     246         
     247        if ( $_POST && empty( $user_login ) ) 
     248                $errors['user_login'] = __('<strong>ERROR</strong>: The username field is empty.'); 
     249        if ( $_POST && empty( $user_pass ) ) 
     250                $errors['user_pass'] = __('<strong>ERROR</strong>: The password field is empty.'); 
     251 
     252        // Some parts of this script use the main login form to display a message 
     253        if              ( TRUE == $_GET['loggedout'] )                  $errors['loggedout']            = __('Successfully logged you out.'); 
     254        elseif  ( 'disabled' == $_GET['registration'] ) $errors['registerdiabled']      = __('User registration is currently not allowed.'); 
     255        elseif  ( 'confirm' == $_GET['checkemail'] )    $errors['confirm']                      = __('Check your e-mail for the confirmation link.'); 
     256        elseif  ( 'newpass' == $_GET['checkemail'] )    $errors['newpass']                      = __('Check your e-mail for your new password.'); 
     257        elseif  ( 'registered' == $_GET['checkemail'] ) $errors['registered']           = __('Registration complete. Please check your e-mail.'); 
    213258 
    214259        if ( ! is_user_logged_in() ) 
    215260                wp_clearcookie(); // Start with a clean slate 
     261        login_header(__('Login')); 
    216262?> 
    217 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    218 <html xmlns="http://www.w3.org/1999/xhtml"> 
    219 <head> 
    220         <title>WordPress &rsaquo; <?php _e('Login') ?></title> 
    221         <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> 
    222         <link rel="stylesheet" href="<?php bloginfo('wpurl'); ?>/wp-admin/wp-admin.css" type="text/css" /> 
    223         <script type="text/javascript"> 
    224         function focusit() { 
    225                 document.getElementById('log').focus(); 
    226         } 
    227         window.onload = focusit; 
    228         </script> 
    229 </head> 
    230 <body> 
    231  
    232 <div id="login"> 
    233 <h1><a href="http://<?php echo $current_site->domain . $current_site->path ?>"><?php echo $current_site->site_name ?></a></h1> 
    234 <?php 
    235 if ( $error ) { 
    236         echo "<div id='login_error'>$error</div>"; 
    237         echo '<p align="center">'.__('<strong>Note:</strong> You must <a href="http://www.google.com/cookies.html">enable cookies</a> to use WordPress.').'</p>'; 
    238 } 
    239 ?> 
    240263 
    241264<form name="loginform" id="loginform" action="wp-login.php" method="post"> 
    242 <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> 
    243 <p><label><?php _e('Password:') ?><br /> <input type="password" name="pwd" id="pwd" value="" size="20" tabindex="2" /></label></p> 
    244 <p> 
    245   <label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="3" />  
    246   <?php _e('Remember me'); ?></label></p> 
    247 <p class="submit"> 
    248         <input type="submit" name="submit" id="submit" value="<?php _e('Login'); ?> &raquo;" tabindex="4" /> 
    249         <input type="hidden" name="redirect_to" value="<?php echo wp_specialchars($redirect_to); ?>" /> 
    250 </p> 
     265        <p> 
     266                <label><?php _e('Username:') ?><br /> 
     267                <input type="text" name="user_login" id="user_login" class="input" value="<?php echo wp_specialchars(stripslashes($user_login), 1); ?>" size="20" tabindex="10" /></label> 
     268        </p> 
     269        <p> 
     270                <label><?php _e('Password:') ?><br /> 
     271                <input type="password" name="user_pass" id="user_pass" class="input" value="" size="20" tabindex="20" /></label> 
     272        </p> 
     273<?php do_action('login_form'); ?> 
     274        <p><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="90" /> <?php _e('Remember me'); ?></label></p> 
     275        <p class="submit"> 
     276                <input type="submit" name="submit" id="submit" value="<?php _e('Login'); ?> &raquo;" tabindex="100" /> 
     277                <input type="hidden" name="redirect_to" value="<?php echo wp_specialchars($redirect_to); ?>" /> 
     278        </p> 
    251279</form> 
    252280<ul> 
     281<?php if (get_option('users_can_register')) : ?> 
     282        <li><a href="<?php bloginfo('wpurl'); ?>/signup/"><?php _e('Register') ?></a></li> 
     283        <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> 
     284        <li><a href="<?php bloginfo('home'); ?>/" title="<?php _e('Are you lost?') ?>" class="fullwidth">&laquo; <?php _e('Back to blog') ?></a></li> 
     285<?php else : ?> 
    253286        <li><a href="<?php bloginfo('home'); ?>/" title="<?php _e('Are you lost?') ?>">&laquo; <?php _e('Back to blog') ?></a></li> 
    254 <?php if (get_option('users_can_register')) : ?> 
    255         <li><a href="<?php bloginfo('wpurl'); ?>/wp-signup.php"><?php _e('Register') ?></a></li> 
     287        <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> 
    256288<?php endif; ?> 
    257         <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> 
    258289</ul> 
    259290</div>