Ejemplo n.º 1
0
 /**
  * Logs in the user if his profile is activated,
  * if not, displays standard error message.
  *
  * @return string|\yii\web\Response
  */
 public function actionLogin()
 {
     if (!Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     // get setting value for 'Login With Email'
     $lwe = Yii::$app->params['LoginWithEmail'];
     // if "login with email" is true we instantiate LoginForm in "lwe" scenario
     $lwe ? $model = new LoginForm(['scenario' => 'LoginWithEmail']) : ($model = new LoginForm());
     // everything went fine, log in the user
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         AccessControl::checkRoleAssignment();
         return $this->goBack();
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
Ejemplo n.º 2
0
 /**
  * Logs in the user if his profile is activated,
  * if not, displays appropriate message.
  *
  * @return string|\yii\web\Response
  */
 public function actionLogin()
 {
     if (!Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     // get setting value for 'Login With Email'
     $lwe = Yii::$app->params['LoginWithEmail'];
     // if 'LoginWithEmail' value is 'true' we instantiate LoginForm in 'LoginWithEmail' scenario
     $model = $lwe ? new LoginForm(['scenario' => 'LoginWithEmail']) : new LoginForm();
     // now we can try to log in the user
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         AccessControl::checkRoleAssignment();
         return $this->goBack();
     } else {
         if ($model->notActivated()) {
             // if his profile is not activated, he will have to activate it first
             AppHelper::showErrorMessage(Yii::t('frontend-profile', 'You have to activate your profile first. Please check your email.'));
             return $this->refresh();
         } else {
             return $this->render('login', ['model' => $model]);
         }
     }
 }