Example #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('/');
         }
     }
 }
Example #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();
     });
 }
Example #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;
     }
 }
Example #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]);
     }
 }
 public function actionLogin()
 {
     $model = new LoginForm();
     if (Yii::$app->request->isAjax) {
         $model->load($_POST);
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->goBack();
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
 public function actionLogin()
 {
     Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-success'], 'body' => Yii::t('frontend', 'Your account has been successfully saved')]);
     $model = new LoginForm();
     if (Yii::$app->request->isAjax) {
         $model->load($_POST);
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->goBack();
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
Example #7
0
 /** @inheritdoc */
 public function run()
 {
     $model = \Yii::createObject(LoginForm::className());
     $action = $this->validate ? null : ['/user/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]);
 }
 public function actionIndex()
 {
     if (Yii::$app->user->isGuest) {
         $this->redirect('/user/sign-in/login', 200);
     }
     $searchModel = new PartnerSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $model = new LoginForm();
     if (Yii::$app->request->isAjax) {
         $model->load($_POST);
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         return $this->goBack();
     } else {
         return $this->render('index', ['model' => $model]);
     }
 }
Example #9
0
 /**
  * 显示登录页面.
  *
  * @return string|Response
  */
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         $this->redirect(Url::to(['/user']));
     }
     $model = \Yii::createObject(LoginForm::className());
     $this->performAjaxValidation($model);
     if ($model->load(Yii::$app->getRequest()->post()) && $model->login()) {
         return $this->goBack();
     }
     return $this->render('login', ['model' => $model, 'module' => $this->module]);
 }