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