public function actionForgotPassword() { // Send user to home if already logged in $this->checkHome(); // Create Form Model $model = new ForgotPassword(); // Load and Validate Form Model if ($model->load(Yii::$app->request->post()) && $model->validate()) { $user = UserService::findByEmail($model->email); // Trigger Reset Password if (isset($user) && UserService::forgotPassword($user)) { $user = UserService::findByEmail($model->email); // Load User Permissions $user->loadPermissions(); // Send Forgot Password Mail Yii::$app->cmgCoreMailer->sendPasswordResetMail($user); // Set Flash Message Yii::$app->session->setFlash(CoreGlobal::FLASH_GENERIC, Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::MESSAGE_FORGOT_PASSWORD)); // Refresh the Page return $this->refresh(); } else { $model->addError(CoreGlobal::MODEL_EMAIL, Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_USER_NOT_EXIST)); } } return $this->render(CoreGlobal::PAGE_PASSWORD_FORGOT, [CoreGlobal::MODEL_GENERIC => $model]); }
public function actionForgotPassword() { // Create Form Model $model = new ForgotPassword(); // Load and Validate Form Model if ($model->load(Yii::$app->request->post(), 'ForgotPassword') && $model->validate()) { $user = UserService::findByEmail($model->email); // Trigger Reset Password if (isset($user) && UserService::forgotPassword($user)) { $user = UserService::findByEmail($model->email); // Load User Permissions $user->loadPermissions(); // Send Forgot Password Mail Yii::$app->cmgCoreMailer->sendPasswordResetMail($user); return AjaxUtil::generateSuccess(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::MESSAGE_FORGOT_PASSWORD)); } else { // Generate Errors $model->addError('email', Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_USER_NOT_EXIST)); $errors = AjaxUtil::generateErrorMessage($model); // Trigger Ajax Failure return AjaxUtil::generateFailure(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_REQUEST), $errors); } } // Generate Errors $errors = AjaxUtil::generateErrorMessage($model); // Trigger Ajax Failure return AjaxUtil::generateFailure(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_REQUEST), $errors); }