/** * Reset password */ public function actionResetPassword() { $code = $this->getParams('code'); $newPassword = $this->getParams('password'); $result = Validation::validateCode($code); if ($result == Validation::LINK_INVALID) { throw new BadRequestHttpException(Yii::t('common', 'link_invalid')); } else { if ($result == Validation::LINK_EXPIRED) { throw new BadRequestHttpException(Yii::t('common', 'link_expired')); } } $userId = $result; $user = HelpDesk::findByPk($userId); if (empty($user)) { throw new BadRequestHttpException(Yii::t('commmon', 'incorrect_userid')); } // update the user password $user->password = HelpDesk::encryptPassword($newPassword, $user->salt); if (!$user->save()) { throw new ServerErrorHttpException("Save user failed!"); } return ['status' => 'ok']; }