Inheritance: extends yii\base\Model
 public function testNotLoginInactiveUser()
 {
     $model = new LoginForm(['accountName' => 'doe-inactive', 'password' => 'password_0']);
     expect('model should not login user', $model->login())->false();
     expect('error message should be set', $model->errors)->hasKey('password');
     expect('user should not be logged in', Yii::$app->user->isGuest)->true();
 }
 public function testLoginCorrect()
 {
     $model = new LoginForm(['username' => 'demo1', 'password' => 'demo1']);
     $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
 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]);
     }
 }
Example #4
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->redirect(Yii::$app->urlManager->createUrl("user"));
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
Example #5
0
 public function actionLogin()
 {
     $this->layout = false;
     if (!\Yii::$app->user->isGuest) {
         return $this->redirect(['admin/index']);
     }
     $model = new LoginForm();
     if ($model->load($_POST) && $model->login()) {
         return $this->redirect(['admin/index']);
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
Example #6
0
 public function actionLogin()
 {
     $this->layout = false;
     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, 'title' => '欢迎使用瞄再买管理平台']);
     }
 }
Example #7
0
 public function actionLogin()
 {
     $this->layout = 'base';
     if (!Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         $_SESSION['domain_id'] = Yii::$app->user->identity->domain_id;
         return $this->goBack();
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
Example #8
0
 /**
  * 登录
  * @return string|\yii\web\Response
  */
 public function actionLogin()
 {
     $this->layout = false;
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         if (!Yii::$app->user->identity->changed_password) {
             return $this->redirect(['/site/password']);
         }
         return $this->goHome();
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
Example #9
0
 public function actionPost()
 {
     if (!\Yii::$app->request->getIsPost()) {
         throw new yii\base\InvalidCallException("无效请求");
     }
     $model = new LoginForm();
     $model->username = $_POST['username'];
     $model->password = $_POST['password'];
     $model->rememberMe = isset($_POST['rememberMe']) && $_POST['rememberMe'] == 'on' ? true : false;
     $model->verifyCode = $_POST['verifyCode'];
     if ($model->login()) {
         exit(UtilD::handleResult(true, '登陆成功'));
     } else {
         exit(UtilD::handleResult(false, '登陆失败,账号或密码错误'));
     }
 }
 /**
  *
  */
 public function actionLogin()
 {
     // if (!Yii::$app->user->isGuest) {
     // return $this->goHome();
     // }
     $res = new Response();
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         $res->success = true;
         $res->message = '登录成功';
     } else {
         $res->success = false;
         $res->message = '登录失败';
     }
     $res->to_json();
 }
Example #11
0
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->gohome();
     }
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         Yii::$app->systemlog->add('管理员', '登录');
         return $this->gohome();
     } else {
         if ($model && $model->username) {
             Yii::$app->systemlog->add('管理员:' . $model->username, '登录', '失败', json_encode($model->getErrors()));
         }
         $this->layout = 'login';
         return $this->render('login', ['model' => $model]);
     }
 }
Example #12
0
 public function actionLogin()
 {
     $this->layout = 'main-login';
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         $auth = new Authorization(['userID' => \Yii::$app->user->identity->getId()]);
         if (!$auth->save()) {
             \Yii::trace($auth->getErrors());
             \Yii::trace($auth);
         }
         return $this->goBack();
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }
Example #13
0
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         $user = Admin::find()->where(['username' => $_POST['LoginForm']['username']])->one();
         //设置session
         $session = Yii::$app->session;
         $session['userid'] = $user->id;
         $session['username'] = $user->username;
         $session['head_image'] = $user->head_image;
         return $this->redirect(['/admin/index']);
     } else {
         return $this->renderPartial('login', ['model' => $model, 'assets_url' => \Yii::$app->params['backend_assets']]);
     }
 }
Example #14
0
 public function actionLogin()
 {
     $this->layout = 'login';
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new LoginForm();
     $message = [];
     if ($model->load(LsYii::getRequest()->post())) {
         if ($model->login()) {
             $this->redirect(\source\helpers\Url::to(['index']));
         } else {
             foreach ($model->getErrors() as $errors) {
                 foreach ($errors as $error) {
                     $message[] = $error;
                 }
             }
         }
     }
     return $this->render('login', ['model' => $model, 'message' => !empty($message) ? $message[0] : '']);
 }
 public function actionLogin()
 {
     $model = \Yii::createObject(LoginForm::className());
     //
     //        $this->performAjaxValidation($model);
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     //        $model = new LoginForm();
     if ($model->load(\Yii::$app->getRequest()->post()) && $model->login()) {
         if (\Yii::$app->user->can('admin')) {
             return $this->goBack();
         } else {
             //return $this->goBack();
             Yii::$app->session->setFlash('error-login', 'Your account can\'t access this page.');
             \Yii::$app->user->logout();
             return $this->refresh();
         }
     } else {
         return $this->render('login', ['model' => $model]);
     }
 }