Beispiel #1
0
 public function resetByMobileAction()
 {
     $mobile = $this->request->getPost('mobile');
     $captcha = $this->request->getPost('captcha');
     /** @var \Eva\EvaUser\Models\ResetPassword $user */
     $user = Models\User::findFirst("mobile='{$mobile}' AND mobileStatus='active'");
     if (!$user) {
         throw new Exception\ResourceNotFoundException('ERR_USER_NOT_EXIST');
     }
     if ($user->mobileStatus != 'active') {
         throw new Exception\InvalidArgumentException('ERR_MOBILE_INACTIVATED');
     }
     try {
         $user->mobileCaptchaCheck($mobile, $captcha);
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e);
     }
     $resetPassword = new Models\ResetPassword();
     $form = new Forms\MobileResetPasswordForm();
     if ($form->isValid($this->request->getPost()) === false) {
         return $this->showInvalidMessagesAsJson($form);
     }
     $resetPassword->assign(array('username' => $user->username, 'password' => $this->request->getPost('password')));
     try {
         $resetPassword->resetPassword();
         $this->flashSession->success('SUCCESS_USER_PASSWORD_RESET');
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $user->getMessages());
     }
     return $this->showResponseAsJson('SUCCESS_USER_PASSWORD_RESET');
 }
 /**
  * @param $validator
  * @param string $attribute
  * @return bool
  */
 public function validate($validator, $attribute)
 {
     $value = $validator->getValue($attribute);
     $usr = Login::getCurrentUser();
     if (!$usr['id']) {
         $validator->appendMessage(new Validation\Message('ERR_USER_NOT_LOGIN', $attribute));
         return false;
     }
     /**
      * @var $usr User
      */
     $usr = User::findFirst('id = ' . $usr['id']);
     if (!Login::passwordVerify($value, $usr->password)) {
         $message = $this->getOption('message');
         if (!$message) {
             //$message = 'The old password provided is incorrect.';
             $message = 'ERR_USER_OLD_PASSWORD_NOT_MATCH';
         }
         $validator->appendMessage(new Validation\Message($message, $attribute, null, null));
         return false;
     }
     return true;
 }
Beispiel #3
0
 public function loginByCookie($tokenString)
 {
     $this->getDI()->getEventsManager()->fire('user:beforeLoginByCookie', $tokenString);
     $tokenArray = explode('|', $tokenString);
     if (!$tokenArray || count($tokenArray) < 3) {
         $this->appendMessage(new Message('ERR_USER_REMEMBER_TOKEN_FORMAT_INCORRECT'));
         return false;
     }
     $token = new Entities\Tokens();
     $tokenInfo = $token::findFirst(array("conditions" => "sessionId = :sessionId: AND token = :token: AND userHash = :userHash:", "bind" => array('sessionId' => $tokenArray[0], 'token' => $tokenArray[1], 'userHash' => $tokenArray[2])));
     if (!$tokenInfo) {
         $this->appendMessage(new Message('ERR_USER_REMEMBER_TOKEN_NOT_FOUND'));
         return false;
     }
     if ($tokenInfo->expiredAt < time()) {
         $this->appendMessage(new Message('ERR_USER_REMEMBER_TOKEN_EXPIRED'));
         return false;
     }
     $userinfo = User::findFirst($tokenInfo->userId);
     $rememberMeHash = $this->getRememberMeHash($userinfo);
     //User changed status or password
     if ($rememberMeHash != $tokenInfo->userHash) {
         $this->appendMessage(new Message('ERR_USER_REMEMBER_TOKEN_ILLEGAL'));
         return false;
     }
     $login = new Login();
     $login->id = $tokenInfo->userId;
     $userinfo = $login->login();
     return $userinfo;
 }