/**
  * Вывод главной страницы с 3 формами:
  * авторизация, регистрация и восстановление
  * пароля. Все 3 обработчика форм
  * лаконичнее располагать по одному
  * запросу
  *
  * @return string|\yii\web\Response
  */
 public function actionIndex()
 {
     if (Yii::$app->user->isGuest) {
         //Авторизация
         $model = new LoginForm();
         if ($model->load(Yii::$app->request->post()) && $model->login()) {
             return $this->goBack();
         }
         //Регистрация
         $reg = new RegForm();
         if ($reg->load(Yii::$app->request->post()) && $reg->save()) {
             Yii::$app->getSession()->setFlash('reg-success');
             return $this->goBack();
         }
         //Восстановление пароля
         $forget = new PasswordResetForm();
         if ($forget->load(Yii::$app->request->post()) && $forget->validate()) {
             if ($forget->sendEmail()) {
                 Yii::$app->getSession()->setFlash('forget-send');
             }
             return $this->goBack();
         }
         return $this->render('index', ['model' => $model, 'reg' => $reg, 'forget' => $forget]);
     } else {
         return $this->render('panel');
     }
 }
Exemplo n.º 2
0
 public function actionPasswordReset()
 {
     $model = new PasswordResetForm();
     if (Yii::$app->user->isGuest) {
         if ($model->load(Yii::$app->request->post()) && $model->validate()) {
             $model->sendEmail();
             Alert::addSuccess('Thank you. If the email address you entered matches with one that is registered in our system we will send you a reset link within the next few minutes.');
             return $this->goHome();
         } else {
             return $this->render('password-reset', ['model' => $model]);
         }
     } else {
         $model->email = Yii::$app->user->identity->email;
     }
     if ($model->validate()) {
         $model->sendEmail();
         Alert::addSuccess('Thank you. If the email address you entered matches with one that is registered in our system we will send you a reset link within the next few minutes.');
         return $this->goHome();
     } else {
         return $this->render('password-reset', ['model' => $model]);
     }
 }