X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Frecoverpassword.php;h=444dd1f2a90b3bf5ba7e18a7eb3e46dd6ac6eed0;hb=e440b9cea02549032ba4f79c43964219dea23d82;hp=feb2001639ec471aed8598d5e0a313801bacf2b1;hpb=87b494f1ebbe7640d194ef322af12fdf378295df;p=quix0rs-gnu-social.git diff --git a/actions/recoverpassword.php b/actions/recoverpassword.php index feb2001639..444dd1f2a9 100644 --- a/actions/recoverpassword.php +++ b/actions/recoverpassword.php @@ -36,7 +36,7 @@ class RecoverpasswordAction extends Action { } else if ($this->arg('reset')) { $this->reset_password(); } else { - $this->client_error(_('Unexpected form.')); + $this->client_error(_('Unexpected form submission.')); } } else { if ($this->trimmed('code')) { @@ -69,6 +69,7 @@ class RecoverpasswordAction extends Action { } $touched = strtotime($confirm->modified); + $email = $confirm->address; # Burn this code @@ -89,6 +90,20 @@ class RecoverpasswordAction extends Action { return; } + # If we used an outstanding confirmation to send the email, + # it's been confirmed at this point. + + if (!$user->email) { + $orig = clone($user); + $user->email = $email; + $result = $user->updateKeys($orig); + if (!$result) { + common_log_db_error($user, 'UPDATE', __FILE__); + $this->server_error(_('Could not update user with confirmed email address.')); + return; + } + } + # Success! $this->set_temp_user($user); @@ -120,7 +135,7 @@ class RecoverpasswordAction extends Action { } else { common_element('div', 'instructions', _('If you\'ve forgotten or lost your' . - ' password, you can get a new one sent ' . + ' password, you can get a new one sent to' . ' the email address you have stored ' . ' in your account.')); } @@ -176,25 +191,49 @@ class RecoverpasswordAction extends Action { $this->show_form(_('Enter a nickname or email address.')); return; } + $user = User::staticGet('email', common_canonical_email($nore)); + if (!$user) { $user = User::staticGet('nickname', common_canonical_nickname($nore)); } + # See if it's an unconfirmed email address + if (!$user) { - $this->show_form(_('No such user.')); + $confirm_email = Confirm_address::staticGet('address', common_canonical_email($nore)); + if ($confirm_email && $confirm_email->address_type == 'email') { + $user = User::staticGet($confirm_email->user_id); + } + } + + if (!$user) { + $this->show_form(_('No user with that email address or username.')); return; } - if (!$user->email) { + + # 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 = NULL; + } + } + + if (!$user->email && !$confirm_email) { $this->client_error(_('No registered email address for that user.')); return; } + # Success! We have a valid user and a confirmed or unconfirmed email address + $confirm = new Confirm_address(); $confirm->code = common_confirmation_code(128); $confirm->address_type = 'recover'; $confirm->user_id = $user->id; - $confirm->address = $user->email; + $confirm->address = (isset($user->email)) ? $user->email : $confirm_email->address; if (!$confirm->insert()) { common_log_db_error($confirm, 'INSERT', __FILE__); @@ -219,7 +258,7 @@ class RecoverpasswordAction extends Action { $body .= common_config('site', 'name'); $body .= "\n"; - mail_to_user($user, _('Password recovery requested'), $body); + mail_to_user($user, _('Password recovery requested'), $body, $confirm->address); common_show_header(_('Password recovery requested')); common_element('p', NULL,