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