Пример #1
0
 public function actionAccount()
 {
     // Find Model
     $user = Yii::$app->user->getIdentity();
     // Update/Render if exist
     if (isset($user)) {
         $model = new ResetPassword();
         if ($model->load(Yii::$app->request->post(), 'ResetPassword') && $model->validate()) {
             // Update User and Site Member
             if (UserService::resetPassword($user, $model, false)) {
                 $data = ['email' => $user->email, 'username' => $user->username];
                 // Trigger Ajax Success
                 return AjaxUtil::generateSuccess(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::MESSAGE_REQUEST), $data);
             }
         } else {
             // Generate Errors
             $errors = AjaxUtil::generateErrorMessage($model);
             // Trigger Ajax Failure
             return AjaxUtil::generateFailure(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_REQUEST), $errors);
         }
     }
     // Model not found
     return AjaxUtil::generateFailure(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_REQUEST), ['session' => true]);
 }
Пример #2
0
 public function actionResetPassword($token, $email)
 {
     // Send user to home if already logged in
     $this->checkHome();
     // Unset Flash Message
     Yii::$app->session->setFlash(CoreGlobal::FLASH_GENERIC, null);
     $model = new ResetPassword();
     $model->email = $email;
     // Load and Validate Form Model
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $user = UserService::findByEmail($model->email);
         // If valid user found
         if (isset($user)) {
             if ($user->isResetTokenValid($token)) {
                 if (UserService::resetPassword($user, $model)) {
                     // Set Success Message
                     Yii::$app->session->setFlash(CoreGlobal::FLASH_GENERIC, Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::MESSAGE_RESET_PASSWORD));
                 }
             } else {
                 // Set Failure Message
                 Yii::$app->session->setFlash(CoreGlobal::FLASH_GENERIC, Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_PASSWORD_RESET));
             }
         } else {
             // Set Failure Message
             Yii::$app->session->setFlash(CoreGlobal::FLASH_GENERIC, Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_USER_NOT_EXIST));
         }
     }
     return $this->render(CoreGlobal::PAGE_PASSWORD_RESET, [CoreGlobal::MODEL_GENERIC => $model]);
 }