| 1 | <?php |
||
| 25 | class Auth |
||
| 26 | { |
||
| 27 | use Options; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var EntityInterface Instance of EntityInterface |
||
| 31 | */ |
||
| 32 | protected $identity; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Setup identity |
||
| 36 | * |
||
| 37 | * @param EntityInterface $identity |
||
| 38 | * @return void |
||
| 39 | */ |
||
| 40 | 3 | public function setIdentity(EntityInterface $identity) |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Return identity if user agent is correct |
||
| 52 | * |
||
| 53 | * @return EntityInterface|null |
||
| 54 | */ |
||
| 55 | 6 | public function getIdentity() |
|
| 56 | { |
||
| 57 | 6 | if (!$this->identity) { |
|
| 58 | // check user agent |
||
| 59 | 3 | if (Session::get('auth:agent') == Request::getServer('HTTP_USER_AGENT')) { |
|
| 60 | $this->identity = Session::get('auth:identity'); |
||
| 61 | } else { |
||
| 62 | 3 | $this->clearIdentity(); |
|
| 63 | } |
||
| 64 | } |
||
| 65 | 6 | return $this->identity; |
|
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Clear identity and user agent information |
||
| 70 | * |
||
| 71 | * @return void |
||
| 72 | */ |
||
| 73 | 635 | public function clearIdentity() |
|
| 79 | } |
||
| 80 |