Pimcore\Tool\Authentication::authenticateSession PHP Method

authenticateSession() public static method

public static authenticateSession ( ) : User
return Pimcore\Model\User
    public static function authenticateSession()
    {
        if (!isset($_COOKIE["pimcore_admin_sid"]) && !isset($_REQUEST["pimcore_admin_sid"])) {
            // if no session cookie / ID no authentication possible, we don't need to start a session
            return null;
        }
        $session = Session::getReadOnly();
        $user = $session->user;
        if ($user instanceof User) {
            // renew user
            $user = User::getById($user->getId());
            if (self::isValidUser($user)) {
                return $user;
            }
        }
        return null;
    }

Usage Example

Beispiel #1
1
 public function preDispatch()
 {
     parent::preDispatch();
     // do something before the action is called //-> see Zend Framework
     \Pimcore\Tool\Authentication::authenticateSession();
     $adminSession = new \Zend_Session_Namespace("pimcore_admin");
     if (!$adminSession->user instanceof \User) {
         $auth = \Zend_Auth::getInstance();
         if ($auth->hasIdentity()) {
             // We have a login session (user is logged in)
             $cached_person = $auth->getIdentity();
             $id = $cached_person->getId();
             $this->view->person = $this->person = \Object\Person::getById($id);
         } else {
             $this->forward("form-login", "login");
         }
     } else {
         $this->view->person = $this->person = \Object\Person::getById(590);
     }
     if ($this->person) {
         $this->view->user = $this->user = $this->person;
         $this->view->societe = $this->societe = $this->person->getSociete();
         $this->view->locations = $this->locations = $this->societe->getLocations();
         $this->storeLocation();
     }
 }
All Usage Examples Of Pimcore\Tool\Authentication::authenticateSession