Ejemplo n.º 1
0
 /**
  * 设置某个Cookie值
  *
  * @param string $name 要设置的cookie的名称
  * @param mixed $value 要设置的值
  * @param int $expire 过期时间
  * @param string $path path
  * @param string $domain domain
  *
  * @return void
  */
 public static function set($name, $value, $expire = 0, $path = '', $domain = '')
 {
     empty($expire) && ($expire = Config::get('cookie_expire'));
     empty($path) && ($path = Config::get('cookie_path'));
     empty($domain) && ($domain = Config::get('cookie_domain'));
     $expire = empty($expire) ? 0 : Alpha::$nowTime + $expire;
     $value = Encry::encrypt($value);
     setcookie(Config::get('cookie_prefix') . $name, $value, $expire, $path, $domain);
     $_COOKIE[Config::get('cookie_prefix') . $name] = $value;
 }
Ejemplo n.º 2
0
 /**
  *获取当前会话的信息
  *
  * @return array
  */
 public static function getLoginInfo()
 {
     if (is_null(self::$authUser)) {
         //Cookie::get本身有一重解密 这里解第二重
         self::$authUser = Encry::decrypt(Cookie::get(Config::get('userauthid')), self::$encryptKey);
         empty(self::$authUser) || (self::$authUser = json_decode(self::$authUser, true));
         if (empty(self::$authUser) || self::$authUser['expire'] < Alpha::$nowTime || self::$authUser['ssosign'] != Model::getInstance()->cache()->get("SSOSingleSignOn" . self::$authUser['uid'])) {
             self::$authUser = false;
         } else {
             $user = Model::getInstance()->db()->get('users-id-' . self::$authUser['uid'] . '-status-1');
             if (empty($user)) {
                 self::$authUser = false;
             } else {
                 $user = $user[0];
                 $tmp = array('id' => $user['id'], 'username' => $user['username'], 'nickname' => $user['nickname'], 'groupid' => explode('|', $user['groupid']));
                 $groups = Model::getInstance()->db()->table('groups')->columns('name')->whereIn('id', $tmp['groupid'])->_and()->where('status', 1)->select();
                 $tmp['groupname'] = array();
                 foreach ($groups as $group) {
                     $tmp['groupname'][] = $group['name'];
                 }
                 $tmp['groupname'] = implode(',', $tmp['groupname']);
                 //有操作登录超时时间重新设置为1个小时
                 if (self::$authUser['expire'] - Alpha::$nowTime < 1800) {
                     self::setLoginStatus($user['id']);
                 }
                 unset($user, $group);
                 self::$authUser = $tmp;
             }
         }
     }
     return self::$authUser;
 }