Exemplo n.º 1
0
 public function actionLogin()
 {
     $iUser_login = new UserLoginForm();
     if (isset($_POST['UserLoginForm'])) {
         $iUser_login->attributes = $_POST['UserLoginForm'];
         if ($iUser_login->validate() && $iUser_login->login()) {
             $id = $this->_session['login_id'];
             $user = Member::model()->findByPk($id);
             $cur = $user->diligent_point;
             if (gmdate('M j, Y') != $user->date_login) {
                 if (time() - $user->last_login <= 60 * 60 * 24) {
                     Member::model()->updateByPk($id, array("diligent_point" => $cur + 1));
                 } else {
                     if ($cur == 0) {
                         $cur = 2;
                     }
                     $day = round((time() - $user->last_login) / (3600 * 24));
                     Member::model()->updateByPk($id, array("diligent_point" => $cur - 2 * $day < 0 ? 0 : $cur - 2 * $day));
                 }
                 Member::model()->updateByPk($id, array("last_login" => time(), "date_login" => gmdate('M j, Y')));
                 $this->redirect($_SERVER['HTTP_REFERER']);
             }
         } else {
             Yii::app()->user->setFlash('error', 'Sai username hoặc password.');
         }
     }
     $this->redirect(Yii::app()->getBaseUrl(true));
 }
Exemplo n.º 2
0
 /**
  * Display login page and authenticate user.
  */
 public function actionLogin()
 {
     if (!Yii::app()->user->isGuest) {
         Yii::app()->request->redirect('/');
     }
     Yii::import('application.modules.users.forms.UserLoginForm');
     $model = new UserLoginForm();
     if (Yii::app()->request->getIsPostRequest()) {
         $model->attributes = $_POST['UserLoginForm'];
         if ($model->validate()) {
             // Authenticate user and redirect to the dashboard
             if ($model->rememberMe) {
                 $duration = Yii::app()->user->rememberTime;
             } else {
                 $duration = 0;
             }
             // TODO: Use backtop param
             //if(Yii::app()->user->returnUrl && Yii::app()->user->returnUrl!=='/index.php')
             //	$url=Yii::app()->user->returnUrl;
             //else
             $url = '/';
             Yii::app()->user->login($model->getIdentity(), $duration);
             Yii::app()->request->redirect($url);
         }
     }
     $this->render('login', array('model' => $model));
 }
Exemplo n.º 3
0
 public function run()
 {
     $this->skin = Yii::app()->user->isGuest ? 'user_auth' : 'user_info';
     if (Yii::app()->user->isGuest) {
         Yii::import('mod.users.forms.UserLoginForm');
         $model = new UserLoginForm();
         if (isset($_POST['UserLoginForm'])) {
             $model->attributes = $_POST['UserLoginForm'];
             if ($model->validate()) {
                 CIntegrationForums::instance()->check_user($model->login, $model->password);
                 $duration = $model->rememberMe ? Yii::app()->settings->get('core', 'cookie_time') : 0;
                 $model->authenticate();
                 if (Yii::app()->user->login($model->getIdentity(), $duration)) {
                     Yii::app()->controller->refresh();
                 } else {
                     Yii::app()->user->setFlash('login-error', 'Login error');
                 }
             } else {
                 Yii::app()->user->setFlash('login-error', 'No validate');
             }
         }
     } else {
         $model = false;
     }
     $this->render($this->skin, array('model' => $model, 'online' => Session::online()));
 }
Exemplo n.º 4
0
 public function actionLogin()
 {
     $this->pageName = Yii::t('app', 'AUTH');
     $this->pageTitle = $this->pageName;
     $service = Yii::app()->request->getQuery('service');
     if (isset($service)) {
         $authIdentity = Yii::app()->eauth->getIdentity($service);
         $authIdentity->redirectUrl = '/users/login';
         $authIdentity->cancelUrl = $this->createAbsoluteUrl('login');
         if ($authIdentity->authenticate()) {
             $identity = new ServiceUserIdentity($authIdentity);
             // $identity = new EAuthUserIdentity($authIdentity);
             // Успешный вход
             if ($identity->authenticate()) {
                 Yii::app()->user->login($identity, Yii::app()->user->rememberTime);
                 // die(print_r($identity->authenticate()));
                 // Специальный редирект с закрытием popup окна
                 $authIdentity->redirect();
             } else {
                 die('error: cancel();');
                 // Закрываем popup окно и перенаправляем на cancelUrl
                 $authIdentity->cancel();
             }
         }
         die('err');
         // Что-то пошло не так, перенаправляем на страницу входа
         $this->redirect(array('login'));
     }
     if (!Yii::app()->user->isGuest) {
         Yii::app()->request->redirect('/');
     }
     Yii::import('mod.users.forms.UserLoginForm');
     $model = new UserLoginForm();
     $view = Yii::app()->request->isAjaxRequest ? '_form' : 'login';
     if (Yii::app()->request->getIsPostRequest()) {
         $model->attributes = $_POST['UserLoginForm'];
         // integration forum
         //  CIntegrationForums::instance()->check_user($model->login, $model->password);
         if ($model->validate()) {
             $duration = $model->rememberMe ? (int) Yii::app()->settings->get('core', 'cookie_time') : 0;
             if (Yii::app()->user->login($model->getIdentity(), $duration)) {
                 if (Yii::app()->request->isAjaxRequest) {
                     $view = 'ajax_success_login';
                 } else {
                     $this->refresh();
                 }
             } else {
                 // if (count(User::model()->findByAttributes(array('password' => User::encodePassword($model->password)))) < 1)
                 //     $model->addError('login', Yii::t('default', 'INCORRECT_LOGIN_OR_PASS'));
                 if (count(User::model()->findByAttributes(array('login' => $model->login))) < 1 || count(User::model()->findByAttributes(array('password' => User::encodePassword($model->password)))) < 1) {
                     $model->addError('login', Yii::t('app', 'INCORRECT_LOGIN_OR_PASS'));
                 }
             }
         }
     }
     if (Yii::app()->request->isAjaxRequest) {
         Yii::app()->clientScript->scriptMap['jquery.js'] = false;
     }
     $this->render($view, array('model' => $model), false, true);
 }