Example #1
0
 protected function beforeAction($action)
 {
     $this->_controller = $action->getController()->getId();
     $this->_action = $action->getId();
     $this->returnurl = Fn::url_login_current();
     $token = FCookie::get("auth");
     $now = time();
     list($uid, $email, $timeout) = explode("\t", FHelper::auth_code($token, 'DECODE', FF_SALT));
     if ($uid) {
         $userInfo = $this->getUserinfo($uid);
         if ($userInfo['user']['id']) {
             if ($token == $userInfo['user']['token']) {
                 if ($now < $timeout) {
                     $this->userInfo = $userInfo['info'];
                     $this->user = $userInfo['user'];
                     if ($timeout - $now < 60 * 2) {
                         $timeout = time() + 60 * 15;
                         $token = FHelper::auth_code("{$uid}\t{$email}\t{$timeout}", 'ENCODE', FF_SALT);
                         FCookie::set('auth', $token, 60 * 15);
                         $attr = array('token' => $token);
                         $user_model = new User();
                         $user_model->updateByPk($uid, $attr);
                     }
                     //                        $timeout =  time()+60 *15;
                     //                        $token = FHelper::auth_code("$uid\t$email\t$timeout", 'ENCODE', FF_SALT);
                     //                        FCookie::set('auth', $token);
                 }
             }
         }
     }
     return true;
 }