root/tags/release-1.0/wp-login.php

Revision 797, 12.3 kB (checked in by donncha, 2 years ago)

WP Merge - needs testing.

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