Index: branches/5.2.x/core/units/users/users_tag_processor.php =================================================================== diff -u -N -r14941 -r14973 --- branches/5.2.x/core/units/users/users_tag_processor.php (.../users_tag_processor.php) (revision 14941) +++ branches/5.2.x/core/units/users/users_tag_processor.php (.../users_tag_processor.php) (revision 14973) @@ -1,6 +1,6 @@ Application->recallObject('UserHelper'); + /* @var $user_helper UserHelper */ + + $hash = $this->Application->GetVar('hash'); + $error_code = $user_helper->restoreEmail($hash); + + if ( $error_code ) { + // used for error reporting only -> rewrite code + theme (by Alex) + $object =& $this->getObject(Array ('skip_autoload' => true)); // TODO: change theme too + /* @var $object UsersItem */ + + $object->SetError('PwResetConfirm', 'restore', $params[$error_code]); + + return false; + } + + return true; + } + + /** * Returns error message set by given code type * * @param string $error_code @@ -133,6 +161,11 @@ 'code_is_not_valid' => 'lu_error_ActivationCodeNotValid', 'code_expired' => 'lu_error_ActivationCodeExpired', ), + + 'verify_email' => Array ( + 'code_is_not_valid' => 'lu_error_VerificationCodeNotValid', + 'code_expired' => 'lu_error_VerificationCodeExpired', + ), ); if ($code_type == 'custom') { @@ -264,33 +297,84 @@ } /** + * Returns link to revert e-mail change in user record + * + * @param Array $params + * @return string + * @access protected + */ + protected function UndoEmailChangeLink($params) + { + $params['hash'] = $this->Application->Parser->GetParam('hash'); + + if ( !$this->SelectParam($params, 'template,t') ) { + $params['template'] = $this->Application->GetVar('undo_email_template'); + } + + return $this->Application->ProcessParsedTag('m', 'Link', $params); + } + + /** * Activates user using given code * * @param Array $params + * @return string + * @access protected */ - function ActivateUser($params) + protected function ActivateUser($params) { - $passed_key = trim($this->Application->GetVar('user_key')); + $this->_updateAndLogin(Array ('Status' => STATUS_ACTIVE, 'EmailVerified' => 1)); + return ''; + } + + /** + * Marks user e-mail as verified using given code + * + * @param Array $params + * @return string + * @access protected + */ + protected function MarkUserEmailAsVerified($params) + { + $this->_updateAndLogin(Array ('EmailVerified' => 1)); + + return ''; + } + + /** + * Activates user using given code + * + * @param Array $fields_hash + * @return void + * @access protected + */ + protected function _updateAndLogin($fields_hash) + { $user_helper =& $this->Application->recallObject('UserHelper'); - /* @var $user_helper UserHelper */ + /* @var $user_helper UserHelper */ - $user =& $user_helper->getUserObject(); - $user->Load($passed_key, 'PwResetConfirm'); + $user =& $this->Application->recallObject($this->Prefix . '.activate', null, Array ('skip_autoload' => true)); + /* @var $user UsersItem */ + + $user->Load(trim($this->Application->GetVar('user_key')), 'PwResetConfirm'); + if ( !$user->isLoaded() ) { return ; } - $user->SetDBField('Status', STATUS_ACTIVE); + $user->SetFieldsFromHash($fields_hash); $user->SetDBField('PwResetConfirm', ''); $user->SetDBField('PwRequestTime_date', NULL); $user->SetDBField('PwRequestTime_time', NULL); $user->Update(); - if ( $user_helper->checkLoginPermission() ) { - $user_helper->loginUserById( $user->GetID() ); + $login_user =& $user_helper->getUserObject(); + $login_user->Load( $user->GetID() ); + + if ( ($login_user->GetDBField('Status') == STATUS_ACTIVE) && $user_helper->checkLoginPermission() ) { + $user_helper->loginUserById( $login_user->GetID() ); } } - } \ No newline at end of file