示例#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 : Cml::$nowTime + $expire;
     $value = Encry::encrypt($value);
     setcookie(Config::get('cookie_prefix') . $name, $value, $expire, $path, $domain);
     $_COOKIE[Config::get('cookie_prefix') . $name] = $value;
 }
示例#2
0
文件: Acl.php 项目: linhecheng/cmlphp
 /**
  * 获取当前登录用户的信息
  *
  * @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'] < Cml::$nowTime || self::$authUser['ssosign'] != Model::getInstance()->cache()->get("SSOSingleSignOn" . self::$authUser['uid'])) {
             self::$authUser = false;
             self::$ssoSign = '';
         } else {
             self::$ssoSign = self::$authUser['ssosign'];
             $user = Model::getInstance()->db()->get('users-id-' . self::$authUser['uid'] . '-status-1');
             if (empty($user)) {
                 self::$authUser = false;
             } else {
                 $user = $user[0];
                 $tmp = ['id' => $user['id'], 'username' => $user['username'], 'nickname' => $user['nickname'], 'groupid' => explode('|', trim($user['groupid'], '|'))];
                 $groups = Model::getInstance()->db()->table('groups')->columns('name')->whereIn('id', $tmp['groupid'])->_and()->where('status', 1)->select();
                 $tmp['groupname'] = [];
                 foreach ($groups as $group) {
                     $tmp['groupname'][] = $group['name'];
                 }
                 $tmp['groupname'] = implode(',', $tmp['groupname']);
                 //有操作登录超时时间重新设置为1个小时
                 if (self::$authUser['expire'] - Cml::$nowTime < 1800) {
                     self::setLoginStatus($user['id'], false);
                 }
                 unset($user, $group);
                 self::$authUser = $tmp;
             }
         }
     }
     return self::$authUser;
 }
示例#3
0
文件: Acl.php 项目: im286er/cmlphp
 /**
  *获取当前会话的信息
  *
  * @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'] < Cml::$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' => $user['groupid']);
                 $group = Model::getInstance()->db()->get('groups-id-' . $user['groupid'] . '-status-1');
                 if (!empty($group)) {
                     $tmp['groupname'] = $group[0]['name'];
                 }
                 //有操作登录超时时间重新设置为1个小时
                 if (self::$authUser['expire'] - Cml::$nowTime < 1800) {
                     self::setLoginStatus($user['id']);
                 }
                 unset($user, $group);
                 self::$authUser = $tmp;
             }
         }
     }
     return self::$authUser;
 }