Beispiel #1
0
 public function actionLogin()
 {
     if (empty($_POST) == false) {
         $user = \App\Models\Users::login($_POST);
         if (empty($user) == false) {
             $sess = md5(microtime());
             $user->setSess($sess);
             $_SESSION['sess'] = $sess;
             header('Location: http://test/index.php');
         } else {
             $this->view->msg = 'Неверный логин или пароль';
             $this->view->display('login');
         }
     } else {
         $this->view->display('login');
     }
 }
 public function actionIndex()
 {
     if (Yii::$app->User->isGuest) {
         $role = Users::findOne(Yii::$app->request->get('Users'))->role;
         $newmodel = new Users();
         $newmodel->scenario = 'login';
         //if model can load get request and User->login is true
         if ($newmodel->load(Yii::$app->request->get()) && $newmodel->login()) {
             if ($role == 1) {
                 if (Yii::$app->request->get('type') == 'auto') {
                     $this->redirect(['auto/index']);
                 } elseif (Yii::$app->request->get('type') == 'guest') {
                     $this->redirect(['pass/index']);
                 } else {
                     return $this->render('withoutlogin');
                 }
             } elseif ($role == 2) {
                 if (Yii::$app->request->get('type') == 'auto') {
                     $this->redirect(['auto/admin']);
                 } elseif (Yii::$app->request->get('type') == 'guest') {
                     $this->redirect(['pass/admin']);
                 } else {
                     return $this->render('withoutlogin');
                 }
             } elseif ($role == 3) {
                 if (Yii::$app->request->get('type') == 'auto') {
                     $this->redirect(['auto/disp']);
                 } elseif (Yii::$app->request->get('type') == 'guest') {
                     $this->redirect(['pass/disp']);
                 } else {
                     return $this->render('withoutlogin');
                 }
             } elseif ($role == 4) {
                 $this->redirect(['admin/index']);
             } else {
                 return $this->goHome();
             }
         } else {
             $model = Users::find()->all();
             return $this->render('index', ['model' => $model, 'newmodel' => $newmodel]);
         }
     } else {
         $role = Users::find()->where(['username' => Yii::$app->user->identity->username])->one()->role;
         if ($role == 1) {
             if (Yii::$app->request->get('type') == 'auto') {
                 $this->redirect(['auto/index']);
             } elseif (Yii::$app->request->get('type') == 'guest') {
                 $this->redirect(['pass/index']);
             } else {
                 return $this->render('withoutlogin');
             }
         } elseif ($role == 2) {
             if (Yii::$app->request->get('type') == 'auto') {
                 $this->redirect(['auto/admin']);
             } elseif (Yii::$app->request->get('type') == 'guest') {
                 $this->redirect(['pass/admin']);
             } else {
                 return $this->render('withoutlogin');
             }
         } elseif ($role == 3) {
             if (Yii::$app->request->get('type') == 'auto') {
                 $this->redirect(['auto/disp']);
             } elseif (Yii::$app->request->get('type') == 'guest') {
                 $this->redirect(['pass/disp']);
             } else {
                 return $this->render('withoutlogin');
             }
         } elseif ($role == 4) {
             $this->redirect(['admin/index']);
         } else {
             return $this->goHome();
         }
     }
 }