Ejemplo n.º 1
0
 public function testLogin()
 {
     $this->form = \Yii::createObject(LoginForm::className());
     $this->specify('should not allow logging in blocked users', function () {
         $user = $this->getFixture('users')->getModel('blocked');
         $this->form->setAttributes(['login' => $user->email, 'password' => 'qwerty']);
         verify($this->form->validate())->false();
         verify($this->form->getErrors('login'))->contains('Your account has been blocked');
     });
     $this->specify('should not allow logging in unconfirmed users', function () {
         \Yii::$app->getModule('users')->enableConfirmation = true;
         \Yii::$app->getModule('users')->enableUnconfirmedLogin = false;
         $user = $this->getFixture('users')->getModel('users');
         $this->form->setAttributes(['login' => $user->email, 'password' => 'qwerty']);
         verify($this->form->validate())->true();
         $user = $this->getFixture('users')->getModel('unconfirmed');
         $this->form->setAttributes(['login' => $user->email, 'password' => 'unconfirmed']);
         verify($this->form->validate())->false();
     });
     $this->specify('should log the user in with correct credentials', function () {
         $user = $this->getFixture('users')->getModel('users');
         $this->form->setAttributes(['login' => $user->email, 'password' => 'wrong']);
         verify($this->form->validate())->false();
         $this->form->setAttributes(['login' => $user->email, 'password' => 'qwerty']);
         verify($this->form->validate())->true();
     });
 }
Ejemplo n.º 2
0
 /** @inheritdoc */
 public function run()
 {
     $model = \Yii::createObject(LoginForm::className());
     $action = $this->validate ? null : ['/users/security/login'];
     if ($this->validate && $model->load(\Yii::$app->request->post()) && $model->login()) {
         return \Yii::$app->response->redirect(\Yii::$app->user->returnUrl);
     }
     return $this->render('login', ['model' => $model, 'action' => $action]);
 }
Ejemplo n.º 3
0
 /**
  * Displays the login page.
  * @return string|\yii\web\Response
  */
 public function actionLogin()
 {
     $model = \Yii::createObject(LoginForm::className());
     $this->performAjaxValidation($model);
     if ($model->load(\Yii::$app->getRequest()->post()) && $model->login()) {
         if (\Yii::$app->user->identity->getIsAdmin()) {
             return $this->redirect($this->module->adminRedirect);
         } elseif ($this->module->userProfileRedirect) {
             return $this->redirect(['profile/show', 'id' => \Yii::$app->user->identity->id]);
         } else {
             return $this->goBack();
         }
     }
     return $this->render('login', ['model' => $model, 'module' => $this->module]);
 }