Esempio n. 1
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'] < 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;
 }
Esempio 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'] < 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;
 }