Index: branches/5.2.x/core/units/helpers/user_helper.php =================================================================== diff -u -N -r14968 -r14973 --- branches/5.2.x/core/units/helpers/user_helper.php (.../user_helper.php) (revision 14968) +++ branches/5.2.x/core/units/helpers/user_helper.php (.../user_helper.php) (revision 14973) @@ -1,6 +1,6 @@ 'config:Users_AllowReset', 'activation' => 'config:UserEmailActivationTimeout', + 'verify_email' => 'config:Users_AllowReset', 'custom' => '', ); @@ -550,4 +551,47 @@ return $user_info['PortalUserId']; } + + /** + * Restores user's email, returns error label, if error occurred + * + * @param string $hash + * @return string + * @access public + */ + public function restoreEmail($hash) + { + if ( !preg_match('/^[a-f0-9]{32}$/', $hash) ) { + return 'invalid_hash'; + } + + $sql = 'SELECT PortalUserId, PrevEmails + FROM ' . TABLE_PREFIX . 'PortalUser + WHERE PrevEmails LIKE ' . $this->Conn->qstr('%' . $hash . '%'); + $user_info = $this->Conn->GetRow($sql); + + if ( $user_info === false ) { + return 'invalid_hash'; + } + + $prev_emails = $user_info['PrevEmails']; + $prev_emails = $prev_emails ? unserialize($prev_emails) : Array (); + + if ( !isset($prev_emails[$hash]) ) { + return 'invalid_hash'; + } + + $email_to_restore = $prev_emails[$hash]; + unset($prev_emails[$hash]); + + $object =& $this->Application->recallObject('u.email-restore', null, Array ('skip_autoload' => true)); + /* @var $object UsersItem */ + + $object->Load($user_info['PortalUserId']); + $object->SetDBField('PrevEmails', serialize($prev_emails)); + $object->SetDBField('Email', $email_to_restore); + $object->SetDBField('EmailVerified', 1); + + return $object->Update() ? '' : 'restore_impossible'; + } }