Make WordPress Core

Ticket #5919: 5919.diff

File 5919.diff, 6.3 KB (added by scribu, 15 years ago)
  • wp-login.php

     
    115115                        echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
    116116        }
    117117} // End of login_header()
     118
     119/**
     120 * Outputs the footer for the login page.
     121 *
     122 * @param string $input_id Which input to auto-focus
     123 */
     124function login_footer($input_id = '') {
     125        echo "</div>\n";
     126
     127        if ( !empty($input_id) ) {
     128?>
     129<script type="text/javascript">
     130try{document.getElementById('<?php echo $input_id; ?>').focus();}catch(e){}
     131if(typeof wpOnload=='function')wpOnload();
     132</script>
     133<?php
     134        }
     135?>
     136<p id="backtoblog"><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('&larr; Back to %s'), get_bloginfo('title', 'display' )); ?></a></p>
     137
     138</body>
     139</html>
     140<?php
     141}
     142
    118143function wp_shake_js() {
    119144        global $is_iphone;
    120145        if ( $is_iphone )
     
    211236}
    212237
    213238/**
    214  * Handles resetting the user's password.
     239 * Retrieves a user row based on password reset key and login
    215240 *
    216241 * @uses $wpdb WordPress Database object
    217242 *
    218243 * @param string $key Hash to validate sending user's password
    219  * @return bool|WP_Error
     244 * @param string $login The user login
     245 *
     246 * @return object|WP_Error
    220247 */
    221 function reset_password($key, $login) {
     248function check_password_reset_key($key, $login) {
    222249        global $wpdb;
    223250
    224251        $key = preg_replace('/[^a-z0-9]/i', '', $key);
     
    230257                return new WP_Error('invalid_key', __('Invalid key'));
    231258
    232259        $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $key, $login));
     260
    233261        if ( empty( $user ) )
    234262                return new WP_Error('invalid_key', __('Invalid key'));
     263               
     264        return $user;
     265}
    235266
    236         // Generate something random for a password...
    237         $new_pass = wp_generate_password();
    238 
     267/**
     268 * Handles resetting the user's password.
     269 *
     270 * @uses $wpdb WordPress Database object
     271 *
     272 * @param string $key Hash to validate sending user's password
     273 */
     274function reset_password($user, $new_pass) {
    239275        do_action('password_reset', $user, $new_pass);
    240276
    241277        wp_set_password($new_pass, $user->ID);
    242         update_user_option($user->ID, 'default_password_nag', true, true); //Set up the Password change nag.
     278
    243279        $message  = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
    244280        $message .= sprintf(__('Password: %s'), $new_pass) . "\r\n";
    245281        $message .= site_url('wp-login.php', 'login') . "\r\n";
     
    256292        $title = apply_filters('password_reset_title', $title);
    257293        $message = apply_filters('password_reset_message', $message, $new_pass);
    258294
    259         if ( $message && !wp_mail($user->user_email, $title, $message) )
    260                 wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') );
     295        if ( $message )
     296                wp_mail($user->user_email, $title, $message);
    261297
    262298        wp_password_change_notification($user);
    263 
    264         return true;
    265299}
    266300
    267301/**
     
    398432</form>
    399433
    400434<p id="nav">
     435<a href="<?php echo site_url('wp-login.php', 'login') ?>"><?php _e('Log in') ?></a>
    401436<?php if (get_option('users_can_register')) : ?>
    402 <a href="<?php echo site_url('wp-login.php', 'login') ?>"><?php _e('Log in') ?></a> |
    403 <a href="<?php echo site_url('wp-login.php?action=register', 'login') ?>"><?php _e('Register') ?></a>
    404 <?php else : ?>
    405 <a href="<?php echo site_url('wp-login.php', 'login') ?>"><?php _e('Log in') ?></a>
     437 | <a href="<?php echo site_url('wp-login.php?action=register', 'login') ?>"><?php _e('Register') ?></a>
    406438<?php endif; ?>
    407439</p>
    408440
    409 </div>
    410 
    411 <p id="backtoblog"><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('&larr; Back to %s'), get_bloginfo('title', 'display' )); ?></a></p>
    412 
    413 <script type="text/javascript">
    414 try{document.getElementById('user_login').focus();}catch(e){}
    415 if(typeof wpOnload=='function')wpOnload();
    416 </script>
    417 </body>
    418 </html>
    419441<?php
     442login_footer('user_login');
    420443break;
    421444
    422445case 'resetpass' :
    423446case 'rp' :
    424         $errors = reset_password($_GET['key'], $_GET['login']);
     447        $user = check_password_reset_key($_GET['key'], $_GET['login']);
    425448
    426         if ( ! is_wp_error($errors) ) {
    427                 wp_redirect('wp-login.php?checkemail=newpass');
    428                 exit();
     449        if ( is_wp_error($user) ) {
     450                wp_redirect('wp-login.php?action=lostpassword&error=invalidkey');
     451                exit;
    429452        }
    430453
    431         wp_redirect('wp-login.php?action=lostpassword&error=invalidkey');
    432         exit();
     454        if ( isset($_POST['pass']) && !empty($_POST['pass']) ) {
     455                reset_password($user, $_POST['pass']);
     456                login_header(__('Password Reset'), '<p class="message reset-pass">' . __('Your password has been reset.') . ' <a href="' . site_url('wp-login.php', 'login') . '">' . __('Log in') . '</a></p>');
     457                login_footer();
     458                exit;
     459        }
    433460
     461        login_header(__('Reset Password'), '<p class="message reset-pass">' . __('Reset your password') . '</p>');
     462?>
     463<form name="resetpassform" id="resetpassform" action="<?php echo site_url('wp-login.php?action=resetpass&key=' . urlencode($_GET['key']) . '&login=' . urlencode($_GET['login']), 'login_post') ?>" method="post">
     464        <p>
     465                <label><?php _e('New Password') ?><br />
     466                <input type="password" name="pass" id="user_pass" size="16" value="" autocomplete="off" /></label>
     467        </p>
     468        <br class="clear" />
     469        <p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button-primary" value="<?php esc_attr_e('Reset Password'); ?>" tabindex="100" /></p>
     470</form>
     471
     472<p id="nav">
     473<a href="<?php echo site_url('wp-login.php', 'login') ?>"><?php _e('Log in') ?></a>
     474<?php if (get_option('users_can_register')) : ?>
     475 | <a href="<?php echo site_url('wp-login.php?action=register', 'login') ?>"><?php _e('Register') ?></a>
     476<?php endif; ?>
     477</p>
     478
     479<?php
     480login_footer('user_pass');
    434481break;
    435482
    436483case 'register' :
     
    485532<a href="<?php echo site_url('wp-login.php?action=lostpassword', 'login') ?>" title="<?php _e('Password Lost and Found') ?>"><?php _e('Lost your password?') ?></a>
    486533</p>
    487534
    488 </div>
    489 
    490 <p id="backtoblog"><a href="<?php bloginfo('url'); ?>/" title="<?php _e('Are you lost?') ?>"><?php printf(__('&larr; Back to %s'), get_bloginfo('title', 'display' )); ?></a></p>
    491 
    492 <script type="text/javascript">
    493 try{document.getElementById('user_login').focus();}catch(e){}
    494 if(typeof wpOnload=='function')wpOnload();
    495 </script>
    496 </body>
    497 </html>
    498535<?php
     536login_footer('user_login');
    499537break;
    500538
    501539case 'login' :