Пример #1
0
 public function actionLogin()
 {
     $model = new LoginForm();
     if (\Yii::$app->request->isAjax) {
         $phone = \Yii::$app->request->post('phone');
         $pass = \Yii::$app->request->post('password');
         $phone = str_replace(['(', ')', '-', '+'], "", $phone);
         $phone = substr($phone, 2);
         $model->phone = $phone;
         $model->password = $pass;
         if ($model->login()) {
             return $this->redirect('/');
         } else {
             return json_encode(['error' => true, 'message' => 'Номер телефона или пароль введены неверно']);
         }
     } else {
         if (\Yii::$app->user->isGuest) {
             if ($model->load(\Yii::$app->request->post()) && $model->validate()) {
                 if ($model->login()) {
                     return $this->redirect('/');
                 }
             }
             return $this->render('login', ['model' => $model]);
         } else {
             return $this->redirect('/');
         }
     }
 }
Пример #2
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();
     });
 }
Пример #3
0
 /**
  * Вход на сайт
  *
  * @return LoginForm | string
  * @throws \yii\base\InvalidConfigException
  */
 public function actionLogin()
 {
     $model = new LoginForm();
     if ($model->load(\Yii::$app->request->post(), '') && $model->login()) {
         return Yii::$app->user->identity->getAuthKey();
     } else {
         return $model;
     }
 }
Пример #4
0
 /**
  * Renders the index view for the module
  * @return string
  */
 public function actionIndex()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->redirect(Yii::$app->user->returnUrl);
     } else {
         return $this->render('index', ['model' => $model]);
     }
 }