/**
  * 用户登录对应的Action
  */
 public function actionLogin()
 {
     $userForm = new UserForm('login');
     if (Yii::app()->request->getIsPostRequest()) {
         $post = Yii::app()->request->getPost('UserForm');
         $userForm->setAttributes($post, false);
         if ($userForm->validate() && $userForm->login()) {
             $this->redirect(array('/'));
         } else {
             $userForm->addError('username', '用户名或密码错误');
         }
     }
     $this->setTitle('登录到' . Yii::app()->name);
     $this->renderPartial('login', array('userForm' => $userForm));
 }
Пример #2
0
 public function actionLogin()
 {
     $model = new UserForm('login');
     if (!empty($_POST['UserForm'])) {
         $model->attributes = $_POST['UserForm'];
         if ($model->validate() && $model->login()) {
             $this->redirect(['cabinet/']);
         }
     }
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('login', ['model' => $model]);
     } else {
         $this->render('login', ['model' => $model]);
     }
 }
Пример #3
0
 public function actionLogin()
 {
     $LoginForm = Request::getVar("LoginForm");
     if (Request::getVar("LoginForm") and $LoginForm['username'] == "" || $LoginForm['password'] == "") {
         YiiMessage::raseWarning("Type your username and password");
         $this->redirect(Router::buildLink("users", array("view" => "user", 'layout' => 'login')));
         return;
     }
     $model = new UserForm();
     // collect user input data
     if (isset($_POST['LoginForm'])) {
         $model->attributes = $_POST['LoginForm'];
         $session_id = session_id();
         // validate user input and redirect to the previous page if valid
         if ($model->validate() && $model->login()) {
             $this->afterLogin($session_id, session_id());
             $this->redirect(Router::buildLink("cpanel"));
             //                    $this->redirect("/backend/");
         } else {
             YiiMessage::raseWarning("Invalid your usename or password");
         }
     }
     $this->layout = "//login";
     $this->pageTitle = "Page login";
     $this->render('login');
 }