示例#1
0
 public function getCachedSessionData($reload)
 {
     $key = sprintf("session-user-%d", $this->session->getLoggedInUserId());
     $userData = function () {
         $user_id = $this->session->getLoggedInUserId();
         /** @var User $user_info */
         if ($user_info = User::find($user_id)) {
             $user_data = array_diff_key($user_info->getAttributes(), ['password' => 1, 'verified' => 1, 'ident' => 1]);
             $user_data['groups'] = $this->userInfo->getUserGroups($user_id, true) ?: [];
         } else {
             $user_data = null;
         }
         if (!empty($user_data) && empty($user_data['full_name'])) {
             $user_data['full_name'] = trim(sprintf('%s %s', $user_data['first_name'], $user_data['last_name'])) ?: 'Anonymous';
         }
         foreach ($this->providers->getEnabled() as $provider) {
             unset($provider['key'], $provider['secret']);
             $providers[] = $provider;
         }
         return ['site' => $this->config->getPublicVars(), 'user' => $user_data, 'providers' => $providers ?? []];
     };
     $data = $reload ? $userData() : $this->cache->get($key, $userData, 300);
     return $data;
 }
示例#2
0
 public function destroySession()
 {
     $this->userInfo->clearCache($this->getLoggedInUserId());
     $this->data = new stdClass();
     $this->response->setCookie(self::COOKIE_NAME, null);
 }