Created
June 22, 2011 00:08
-
-
Save fprochazka/1039260 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of the Kdyby (http://www.kdyby.org) | |
* | |
* Copyright (c) 2008, 2011 Filip Procházka (filip.prochazka@kdyby.org) | |
* | |
* @license http://www.kdyby.org/license | |
*/ | |
namespace Kdyby\Security; | |
use DateTime; | |
use Doctrine; | |
use Kdyby; | |
use Nette; | |
use Nette\Utils\Strings; | |
/** | |
* @author Filip Procházka | |
* | |
* @serializationVersion 1.0 | |
* @Entity(repositoryClass="Kdyby\Security\IdentityRepository") @Table(name="users") | |
* @HasLifecycleCallbacks | |
* | |
* @property-read mixed $id | |
*/ | |
class Identity extends Nette\FreezableObject implements Nette\Security\IIdentity, Nette\Security\IRole, \Serializable | |
{ | |
/** @Column(type="integer") @Id @GeneratedValue */ | |
private $id; | |
// ... | |
/** | |
* Returns the ID of user. | |
* | |
* @return mixed | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/*********************** \Serializable ***********************/ | |
/** | |
* @return string | |
*/ | |
public function serialize() | |
{ | |
return serialize($this->id); | |
} | |
/** | |
* @param string $serialized | |
*/ | |
public function unserialize($serialized) | |
{ | |
$this->id = unserialize($serialized); | |
$this->loaded = FALSE; | |
} | |
/** | |
* @return type | |
*/ | |
public function isLoaded() | |
{ | |
return $this->loaded; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This file is part of the Kdyby (http://www.kdyby.org) | |
* | |
* Copyright (c) 2008, 2011 Filip Procházka (filip.prochazka@kdyby.org) | |
* | |
* @license http://www.kdyby.org/license | |
*/ | |
namespace Kdyby\Security; | |
use Kdyby; | |
use Nette; | |
use Nette\Security\IAuthenticator; | |
use Nette\Security\IAuthorizator; | |
use Nette\Security\IIdentity; | |
/** | |
* User authentication and authorization. | |
* | |
* @author David Grudl | |
* @author Filip Procházka | |
* | |
* @property-read Nette\Security\IIdentity $identity | |
* @property Nette\Security\IAuthenticator $authenticator | |
* @property Nette\Security\IAuthorizator $authorizator | |
* @property-read int $logoutReason | |
* @property-read array $roles | |
* @property-read bool $authenticated | |
*/ | |
class User extends Nette\Object implements Nette\Http\IUser | |
{ | |
// ... | |
/** | |
* Returns current user identity, if any. | |
* @return Nette\Security\IIdentity | |
*/ | |
public function getIdentity() | |
{ | |
$session = $this->getSessionSection(FALSE); | |
if ($session && $session->identity && $session->identity instanceof Identity) { | |
if (!$session->identity->isLoaded()) { | |
// TODO: super lazy, EntityManager::merge etc | |
$respository = $this->context->doctrine->getRepository(get_class($session->identity)); | |
$session->identity = $respository->find($session->identity->getId()); | |
} | |
return $session->identity; | |
} | |
return NULL; | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment