| Total Complexity | 13 |
| Total Lines | 70 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | class AuthController |
||
| 21 | { |
||
| 22 | private $auth; |
||
| 23 | |||
| 24 | public function __construct(AuthScope $auth) |
||
| 25 | { |
||
| 26 | $this->auth = $auth; |
||
| 27 | } |
||
| 28 | |||
| 29 | public function do(GuardInterface $guard) |
||
| 30 | { |
||
| 31 | if (!$guard->allows('do')) { |
||
| 32 | throw new ControllerException("Unauthorized permission 'do'", ControllerException::FORBIDDEN); |
||
| 33 | } |
||
| 34 | |||
| 35 | return 'ok'; |
||
| 36 | } |
||
| 37 | |||
| 38 | public function token(AuthContextInterface $authContext) |
||
| 39 | { |
||
| 40 | if ($authContext->getToken() !== null) { |
||
| 41 | return $authContext->getToken()->getID(); |
||
| 42 | } |
||
| 43 | |||
| 44 | return 'none'; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function login(AuthContextInterface $authContext, TokenStorageInterface $tokenStorage) |
||
| 48 | { |
||
| 49 | $authContext->start( |
||
| 50 | $tokenStorage->create(['userID' => 1]) |
||
| 51 | ); |
||
| 52 | |||
| 53 | return 'OK'; |
||
| 54 | } |
||
| 55 | |||
| 56 | public function logout() |
||
| 57 | { |
||
| 58 | $this->auth->close(); |
||
| 59 | |||
| 60 | return 'closed'; |
||
| 61 | } |
||
| 62 | |||
| 63 | public function token2() |
||
| 64 | { |
||
| 65 | if ($this->auth->getToken() !== null) { |
||
| 66 | return $this->auth->getToken()->getID(); |
||
| 67 | } |
||
| 68 | |||
| 69 | return 'none'; |
||
| 70 | } |
||
| 71 | |||
| 72 | public function token3() |
||
| 73 | { |
||
| 74 | return $this->auth->getToken()->getPayload(); |
||
| 75 | } |
||
| 76 | |||
| 77 | public function login2(TokenStorageInterface $tokenStorage) |
||
| 78 | { |
||
| 79 | $this->auth->start( |
||
| 80 | $tokenStorage->create(['userID' => 1]) |
||
| 81 | ); |
||
| 82 | |||
| 83 | return 'OK'; |
||
| 84 | } |
||
| 85 | |||
| 86 | public function actor() |
||
| 87 | { |
||
| 88 | $actor = $this->auth->getActor(); |
||
| 89 | return $actor ? $actor->getName() : 'none'; |
||
| 90 | } |
||
| 92 |