Esempio n. 1
0
 public function testLoginCorrect()
 {
     $model = new LoginForm(['username' => 'bayer.hudson', 'password' => 'password_0']);
     $this->specify('user should be able to login with correct credentials', function () use($model) {
         expect('model should login user', $model->login())->true();
         expect('error message should not be set', $model->errors)->hasntKey('password');
         expect('user should be logged in', Yii::$app->user->isGuest)->false();
     });
 }
Esempio n. 2
0
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->goBack();
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
Esempio n. 3
0
 /**
  * Logs in a user.
  *
  * @return mixed
  */
 public function actionAcceso()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->goBack();
     }
     $this->layout = 'invitados';
     return $this->render('acceso', ['model' => $model]);
 }
Esempio n. 4
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]);
     }
 }
Esempio n. 5
0
 /**
  * Active user should be able to log in if he enter correct credentials.
  */
 public function testLoginActivatedUser()
 {
     $model = new LoginForm(['scenario' => 'LoginWithEmail']);
     $model->email = '*****@*****.**';
     $model->password = '******';
     $this->specify('user should be able to login with correct credentials', function () use($model) {
         expect('model should login user', $model->login())->true();
         expect('error message should not be set', $model->errors)->hasntKey('password');
         expect('user should be logged in', Yii::$app->user->isGuest)->false();
     });
 }
Esempio n. 6
0
 /**
  * Logs in a user.
  *
  * @return mixed
  */
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->redirect(['user-panel/settings']);
     }
     $serviceName = Yii::$app->getRequest()->getQueryParam('service');
     if (isset($serviceName)) {
         /** @var $eauth \nodge\eauth\ServiceBase */
         $eauth = Yii::$app->get('eauth')->getIdentity($serviceName);
         $eauth->setRedirectUrl(Yii::$app->getUser()->getReturnUrl());
         $eauth->setCancelUrl(Yii::$app->getUrlManager()->createAbsoluteUrl('site/login'));
         try {
             if ($eauth->authenticate()) {
                 // var_dump($eauth->getIsAuthenticated(), $eauth->getAttributes()); exit;
                 $identity = User::findByEAuth($eauth);
                 Yii::$app->getUser()->login($identity);
                 // special redirect with closing popup window
                 $eauth->redirect();
             } else {
                 // close popup window and redirect to cancelUrl
                 $eauth->cancel();
             }
         } catch (\nodge\eauth\ErrorException $e) {
             // save error to show it later
             Yii::$app->getSession()->setFlash('error', 'EAuthException: ' . $e->getMessage());
             // close popup window and redirect to cancelUrl
             // $eauth->cancel();
             $this->redirect($eauth->getCancelUrl());
         }
     } else {
         $model = new LoginForm();
         if ($model->load(Yii::$app->request->post()) && $model->login()) {
             return $this->goBack();
         } else {
             return $this->render('login', ['model' => $model]);
         }
     }
 }