/** * Sets basic info of the user in session with JWT when authenticated. * * @param array|User $user * @param bool $forever * @param integer $appId * * @return bool */ public static function setUserInfoWithJWT($user, $forever = false, $appId = null) { $userInfo = null; if ($user instanceof User) { $userInfo = $user->toArray(); ArrayUtils::set($userInfo, 'is_sys_admin', $user->is_sys_admin); } if (!empty($userInfo)) { $id = ArrayUtils::get($userInfo, 'id'); $email = ArrayUtils::get($userInfo, 'email'); $token = JWTUtilities::makeJWTByUser($id, $email, $forever); static::setSessionToken($token); if (!empty($appId) && !$user->is_sys_admin) { static::setSessionData($appId, $id); return true; } else { return static::setUserInfo($userInfo); } } return false; }