]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/recoverpassword.php
Merge branch 'master' into 0.9.x
[quix0rs-gnu-social.git] / actions / recoverpassword.php
index 9776c1fb4482cb335c5fd9fe3b50b80d3385b117..33b0440e40193505be2516d938c104b0555d4fab 100644 (file)
@@ -21,7 +21,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
 
 # You have 24 hours to claim your password
 
-define(MAX_RECOVERY_TIME, 24 * 60 * 60);
+define('MAX_RECOVERY_TIME', 24 * 60 * 60);
 
 class RecoverpasswordAction extends Action
 {
@@ -149,13 +149,13 @@ class RecoverpasswordAction extends Action
             $this->elementStart('div', 'instructions');
             if ($this->mode == 'recover') {
                 $this->element('p', null,
-                               _('If you\'ve forgotten or lost your' .
+                               _('If you have forgotten or lost your' .
                                  ' password, you can get a new one sent to' .
                                  ' the email address you have stored' .
                                  ' in your account.'));
             } else if ($this->mode == 'reset') {
                 $this->element('p', null,
-                               _('You\'ve been identified. Enter a' .
+                               _('You have been identified. Enter a' .
                                  ' new password below. '));
             }
             $this->elementEnd('div');
@@ -185,10 +185,10 @@ class RecoverpasswordAction extends Action
                                            'class' => 'form_settings',
                                            'action' => common_local_url('recoverpassword')));
         $this->elementStart('fieldset');
-        $this->element('legend', null, _('Password recover'));
+        $this->element('legend', null, _('Password recovery'));
         $this->elementStart('ul', 'form_data');
         $this->elementStart('li');
-        $this->input('nicknameoremail', _('Nickname or email'),
+        $this->input('nicknameoremail', _('Nickname or email address'),
                      $this->trimmed('nicknameoremail'),
                      _('Your nickname on this server, ' .
                         'or your registered email address.'));
@@ -262,10 +262,20 @@ class RecoverpasswordAction extends Action
         # See if it's an unconfirmed email address
 
         if (!$user) {
-            $confirm_email = Confirm_address::staticGet('address', common_canonical_email($nore));
-            if ($confirm_email && $confirm_email->address_type == 'email') {
+            // Warning: it may actually be legit to have multiple folks
+            // who have claimed, but not yet confirmed, the same address.
+            // We'll only send to the first one that comes up.
+            $confirm_email = new Confirm_address();
+            $confirm_email->address = common_canonical_email($nore);
+            $confirm_email->address_type = 'email';
+            $confirm_email->find();
+            if ($confirm_email->fetch()) {
                 $user = User::staticGet($confirm_email->user_id);
+            } else {
+                $confirm_email = null;
             }
+        } else {
+            $confirm_email = null;
         }
 
         if (!$user) {
@@ -276,9 +286,11 @@ class RecoverpasswordAction extends Action
         # Try to get an unconfirmed email address if they used a user name
 
         if (!$user->email && !$confirm_email) {
-            $confirm_email = Confirm_address::staticGet('user_id', $user->id);
-            if ($confirm_email && $confirm_email->address_type != 'email') {
-                # Skip non-email confirmations
+            $confirm_email = new Confirm_address();
+            $confirm_email->user_id = $user->id;
+            $confirm_email->address_type = 'email';
+            $confirm_email->find();
+            if (!$confirm_email->fetch()) {
                 $confirm_email = null;
             }
         }
@@ -294,7 +306,7 @@ class RecoverpasswordAction extends Action
         $confirm->code = common_confirmation_code(128);
         $confirm->address_type = 'recover';
         $confirm->user_id = $user->id;
-        $confirm->address = (isset($user->email)) ? $user->email : $confirm_email->address;
+        $confirm->address = (!empty($user->email)) ? $user->email : $confirm_email->address;
 
         if (!$confirm->insert()) {
             common_log_db_error($confirm, 'INSERT', __FILE__);
@@ -319,7 +331,8 @@ class RecoverpasswordAction extends Action
         $body .= common_config('site', 'name');
         $body .= "\n";
 
-        mail_to_user($user, _('Password recovery requested'), $body, $confirm->address);
+        $headers = _mail_prepare_headers('recoverpassword', $user->nickname, $user->nickname);
+        mail_to_user($user, _('Password recovery requested'), $body, $headers, $confirm->address);
 
         $this->mode = 'sent';
         $this->msg = _('Instructions for recovering your password ' .
@@ -349,7 +362,7 @@ class RecoverpasswordAction extends Action
         $confirm = $this->trimmed('confirm');
 
         if (!$newpassword || strlen($newpassword) < 6) {
-            $this->showPasswordForm(_('Password must be 6 chars or more.'));
+            $this->showPasswordForm(_('Password must be 6 characters or more.'));
             return;
         }
         if ($newpassword != $confirm) {