123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- /**
- * 用户基础信息
- * @author benzhan
- */
- class User extends Singleton {
- private static $userInfo = null;
- public static function checkLogin() {
- $userInfo = self::getInfo();
- return $userInfo;
- }
- public static function getUserId() {
- $userInfo = self::getInfo();
- return $userInfo['account'] ? : 0;
- }
- public static function getUserName() {
- $userInfo = self::getInfo();
- return $userInfo['account'] ? : $userInfo['account'];
- }
- public static function getInfo() {
- if (self::$userInfo) {
- return self::$userInfo;
- }
- $flag = Account::checkToken();
- if ($flag) {
- self::$userInfo = [
- 'account' => $_COOKIE['account'] ?: $_REQUEST['account'],
- 'token' => $_COOKIE['token'] ?: $_REQUEST['token'],
- ];
- return self::$userInfo;
- } else {
- return [];
- }
- }
- }
|