| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | namespace SimpleID\Base; |
| 24: | |
| 25: | use Psr\Log\LogLevel; |
| 26: | use SimpleID\Module; |
| 27: | use SimpleID\ModuleManager; |
| 28: | use SimpleID\Auth\AuthManager; |
| 29: | use SimpleID\Crypt\SecurityToken; |
| 30: | use SimpleID\Util\UI\Template; |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | class IndexModule extends Module { |
| 36: | static function init($f3) { |
| 37: | $f3->route('GET|POST @index: /', 'SimpleID\Base\IndexModule->index'); |
| 38: | $f3->route('GET|POST /continue/@token', 'SimpleID\Base\IndexModule->continueRequest'); |
| 39: | } |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | public function index() { |
| 54: | $mgr = ModuleManager::instance(); |
| 55: | |
| 56: | $this->logger->log(LogLevel::DEBUG, 'SimpleID\Base\IndexModule->index'); |
| 57: | header('Vary: Accept'); |
| 58: | |
| 59: | $event = new RouteContentNegotiationEvent($this->f3->get('ALIAS'), $this->f3->get('REQUEST'), $this->f3->get('SERVER.HTTP_ACCEPT')); |
| 60: | $dispatcher = \Events::instance(); |
| 61: | $dispatcher->dispatch($event); |
| 62: | if ($event->isPropagationStopped()) return; |
| 63: | |
| 64: | $auth = AuthManager::instance(); |
| 65: | |
| 66: | if (!$auth->isLoggedIn()) { |
| 67: | |
| 68: | $auth_module = $mgr->getModule('SimpleID\Auth\AuthModule'); |
| 69: | $auth_module->loginForm(); |
| 70: | } elseif ($mgr->isModuleLoaded('SimpleID\Base\MyModule')) { |
| 71: | $this->f3->mock('GET /my/dashboard'); |
| 72: | } else { |
| 73: | $tpl = Template::instance(); |
| 74: | $this->f3->set('user_header', true); |
| 75: | $this->f3->set('title', 'SimpleID'); |
| 76: | print $tpl->render('page.html'); |
| 77: | } |
| 78: | } |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | |
| 90: | |
| 91: | public function continueRequest($f3, $params) { |
| 92: | $token = new SecurityToken(); |
| 93: | $payload = $token->getPayload($params['token']); |
| 94: | |
| 95: | if ($payload === null) { |
| 96: | $this->fatalError($this->f3->get('intl.common.invalid_request'), 400); |
| 97: | return; |
| 98: | } |
| 99: | |
| 100: | $request_state = new RequestState($payload); |
| 101: | $this->f3->mock($request_state->toF3RoutePattern(), $request_state->getParams()); |
| 102: | } |
| 103: | |
| 104: | } |
| 105: | |
| 106: | ?> |