root/branches/1.5/wp-login.php

Revision 2661, 9.6 kB (checked in by ryan, 3 years ago)

Init message before concat.

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