Exemplo n.º 1
0
 public function actionLogin()
 {
     $this->onlyOnPc();
     $this->layout = 'common';
     if (!Yii::app()->user->isGuest) {
         $this->message(0, '您已登录,请勿重复操作');
     }
     $canLogin = true;
     $ip = Yii::app()->request->getUserHostAddress();
     $cacheKey = 'loginErrors-' . $ip;
     $errorTimes = zmf::getFCache($cacheKey);
     if ($errorTimes >= 5) {
         $canLogin = false;
     }
     if ($canLogin) {
         $model = new FrontLogin();
         if (isset($_POST['FrontLogin'])) {
             $model->attributes = $_POST['FrontLogin'];
             if ($model->validate() && $model->login()) {
                 $arr = array('latestLoginTime' => zmf::now());
                 $uid = Yii::app()->user->id;
                 //                    User::model()->updateByPk($uid, $arr);
                 zmf::delCookie('checkWithCaptcha');
                 zmf::delFCache($cacheKey);
                 if ($this->referer) {
                     $this->redirect($this->referer);
                 } else {
                     $this->redirect(zmf::config('baseurl'));
                 }
             } else {
                 zmf::updateFCacheCounter($cacheKey, 1, 3600);
                 zmf::setCookie('checkWithCaptcha', 1, 86400);
             }
         }
     }
     $this->pageTitle = '登录';
     $this->render('login', array('model' => $model));
 }