isAuthenticatedFully()) { $allAttributes = $this->getAttributeHolder()->getAll(); $allFlashes=$this->getAttributeHolder()->getAll('symfony/user/sfUser/flash'); $this->addCredential($this->credentialSession); // $this->setSessionUserAttribute(); parent::setAuthenticated(true); $this->getAttributeHolder()->add($allAttributes); $this->getAttributeHolder()->add($allFlashes, 'symfony/user/sfUser/flash'); $this->setAttribute("sessionSync", false); } } public function isAuthenticatedSession() { return $this->hasCredential($this->credentialSession); } abstract public function isAuthenticatedFully(); public function getUser() { if((!$this->user || $this->user->isNew()) && $this->getUserAttribute()) { $this->user=UserQuery::create()->filterByPrimaryKey($this->getUserAttribute())->findOne(); } elseif (!$this->user && $this->getSessionUser()) { $this->user=new User(); $this->user->setEmail($this->getSessionUser()->getEmail()); $this->user->setName($this->getSessionUser()->getNickOrName()); // echo $this->getSessionUser()->getName(); } if($this->user) { return $this->user; } // throw new iturException("Konto użytkownika nie istnieje"); } public function getSessionUser() { if(!$this->sessionUser) { $session_id=$this->getSessionUserAttribute(); if(!$session_id) { $this->restoreSessionFromCookie(); $session_id=$this->getSessionUserAttribute(); } if($session_id) { $this->sessionUser=SessionUserQuery::create()->filterBySessionId($this->getSessionUserAttribute())->findOne(); } } if(!$this->sessionUser) { $this->createNewSession(); $this->sessionUser=new SessionUser(); $this->sessionUser->setSessionId($this->getSessionUserAttribute()); $browser_data = '{ userAgent: ' . $_SERVER ['HTTP_USER_AGENT'] . ', ip:' . (@$_SERVER["HTTP_X_FORWARDED_FOR"] ? $_SERVER["HTTP_X_FORWARDED_FOR"] : @$_SERVER['REMOTE_ADDR']) .'}'; $this->sessionUser->setBrowser($browser_data); // $this->sessionUser->save(); } else { if(method_exists($this->sessionUser, "setLastSeen")) { $this->sessionUser->setLastSeen(time()); } } return $this->sessionUser; } public function setSessionUser(SessionUser $sessionUser) { if($sessionUser) { $this->sessionUser=$sessionUser; } } public function getUserAttribute() { return $this->getAttribute($this->userAttributeName); } public function setUserAttribute($userId) { if($userId) { $this->setAttribute($this->userAttributeName, $userId); } } public function getSessionUserAttribute() { return $this->getAttribute($this->sessionAttributeName); } public function restoreSessionFromCookie() { if($session_id=sfContext::getInstance()->getRequest()->getCookie("suid")) { $this->setAttribute($this->sessionAttributeName, $session_id); $this->extendSessionCookie($session_id); } } public function createNewSession() { $session_id=session_id().time(); $this->extendSessionCookie($session_id); $this->setAttribute($this->sessionAttributeName, $session_id); } protected function extendSessionCookie($session_id) { sfcontext::getInstance()->getResponse()->setCookie("suid", $session_id, strtotime("+1 year"), '/', $this->getSessionCookieHostname()); //tworzone dopiero przy wysyłaniu response sfcontext::getInstance()->getResponse()->setCookie("suidc", md5($this->cookiePrefix.$session_id), strtotime("+1 year"), '/', $this->getSessionCookieHostname()); } public function setSessionCookie($session_id) { sfContext::getInstance()->getResponse()->setCookie("itur_session", $session_id, null, '/', $this->getSessionCookieHostname()); if($this->isAuthenticated()) { $this->setUserCookie(); } } public function removeSessionCookie() { sfContext::getInstance()->getResponse()->setCookie("itur_session", "", time()-3600, '/', $this->getSessionCookieHostname()); $this->removeUserCookie(); } public function getSessionCookieHostname() { $host=explode(".", $_SERVER ['HTTP_HOST']); if(count($host) > 1) { $host="." . $host [count($host) - 2] . '.' . $host [count($host) - 1]; } else $host=null; return $host; } public function checkSuCookie() { if($su=sfContext::getInstance()->getRequest()->getCookie("su")) { if(strpos($su, ".")!==-1) { $su_id=$su; } else { $su_id=explode(".", $su); $su_id=$su_id[count($su_id)-1]; } } else { //set session user and set cookie } } }