Jarves\PageStack::getUser PHP Method

getUser() public method

Returns the current logged in User if available. Null if not or another token than Jarves' is active.
public getUser ( ) : Symfony\Component\Security\Core\User\UserInterface | null
return Symfony\Component\Security\Core\User\UserInterface | null
    public function getUser()
    {
        $token = $this->tokenStorage->getToken();
        if ($token && !$token instanceof AnonymousToken) {
            return $token->getUser();
        }
        return null;
    }

Usage Example

Esempio n. 1
0
 public function addSessionScripts()
 {
     $response = $this->pageStack->getPageResponse();
     $session = array();
     $session['userId'] = null;
     $session['lang'] = 'en';
     if ($this->pageStack->getSession() && $this->pageStack->getSession()->has('admin_language')) {
         $session['lang'] = $this->pageStack->getSession()->get('admin_language');
     }
     $session['access'] = $this->acl->check(ACLRequest::create('jarves/entryPoint', ['path' => '/admin']));
     if ($this->pageStack->isLoggedIn()) {
         $user = $this->pageStack->getUser();
         $session['userId'] = $user->getId();
         $session['username'] = $user->getUsername();
         $session['lastLogin'] = $user->getLastLogin();
         $session['firstName'] = $user->getFirstName();
         $session['lastName'] = $user->getLastName();
         //            $email = $user->getEmail();
         //            $session['emailMd5'] = $email ? md5(strtolower(trim($email))) : null;
         $session['imagePath'] = $user->getImagePath();
     }
     $session['token'] = get_class($this->pageStack->getToken());
     $css = 'window._session = ' . json_encode($session) . ';';
     $response->addJs($css);
 }
All Usage Examples Of Jarves\PageStack::getUser