| 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\Store\StoreManager; |
| 30: | use SimpleID\Util\SecurityToken; |
| 31: | use SimpleID\Util\Events\UIBuildEvent; |
| 32: | use SimpleID\Util\UI\Template; |
| 33: | |
| 34: | |
| 35: | class UserModule extends Module { |
| 36: | static function init($f3) { |
| 37: | $f3->route('GET @user: /user/@uid', 'SimpleID\Base\UserModule->user'); |
| 38: | } |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | function user($f3, $params) { |
| 48: | $web = \Web::instance(); |
| 49: | $tpl = Template::instance(); |
| 50: | $store = StoreManager::instance(); |
| 51: | $mgr = ModuleManager::instance(); |
| 52: | |
| 53: | $this->f3->set('title', $this->f3->get('intl.core.user.user_title')); |
| 54: | if (!isset($params['uid'])) { |
| 55: | $this->f3->status(400); |
| 56: | $this->f3->set('message', $this->f3->get('intl.common.missing_uid')); |
| 57: | } else { |
| 58: | $user = $store->loadUser($params['uid']); |
| 59: | |
| 60: | if ($user == NULL) { |
| 61: | $this->f3->status(404); |
| 62: | $this->f3->set('message', $this->f3->get('intl.common.user_not_found', $params['uid'])); |
| 63: | } else { |
| 64: | header('Vary: Accept'); |
| 65: | |
| 66: | $event = new RouteContentNegotiationEvent($this->f3->get('ALIAS'), $this->f3->get('REQUEST'), $this->f3->get('SERVER.HTTP_ACCEPT')); |
| 67: | $dispatcher = \Events::instance(); |
| 68: | $dispatcher->dispatch($event); |
| 69: | if ($event->isPropagationStopped()) return; |
| 70: | |
| 71: | $xrds_location = $this->getCanonicalURL('@openid_user_xrds'); |
| 72: | header('X-XRDS-Location: ' . $xrds_location); |
| 73: | |
| 74: | $this->f3->set('message', $this->f3->get('intl.core.user.user_page', $params['uid'])); |
| 75: | |
| 76: | $this->f3->set('title', $user['uid']); |
| 77: | $this->f3->set('xrds', $xrds_location); |
| 78: | if ($user->hasLocalOpenIDIdentity()) { |
| 79: | $this->f3->set('local_id', $user["identity"]); |
| 80: | } |
| 81: | |
| 82: | $this->f3->set('head', 'openid_head.html'); |
| 83: | } |
| 84: | } |
| 85: | |
| 86: | print $tpl->render('page.html'); |
| 87: | } |
| 88: | |
| 89: | |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: | |
| 95: | |
| 96: | function onProfileBlocks(UIBuildEvent $event) { |
| 97: | $auth = AuthManager:: instance(); |
| 98: | $user = $auth->getUser(); |
| 99: | |
| 100: | $html = '<p>' . $this->f3->get('intl.core.user.profile_label') . '</p>'; |
| 101: | |
| 102: | $html .= "<table><tr><th>" . $this->f3->get('intl.common.name') . "</th><th>" . $this->f3->get('intl.common.value') . "</th></tr>"; |
| 103: | |
| 104: | if (isset($user['userinfo'])) { |
| 105: | foreach ($user['userinfo'] as $member => $value) { |
| 106: | if (is_array($value)) { |
| 107: | foreach ($value as $submember => $subvalue) { |
| 108: | $html .= "<tr><td>" . $this->f3->clean($member) . " (" .$this->f3->clean($submember) . ")</td><td>" . $this->f3->clean($subvalue) . "</td></tr>"; |
| 109: | } |
| 110: | } else { |
| 111: | $html .= "<tr><td>" . $this->f3->clean($member) . "</td><td>" . $this->f3->clean($value) . "</td></tr>"; |
| 112: | } |
| 113: | } |
| 114: | } |
| 115: | |
| 116: | $html .= "</table>"; |
| 117: | |
| 118: | $event->addBlock('userinfo', $html, -1, [ |
| 119: | 'title' => $this->f3->get('intl.core.user.userinfo_title') |
| 120: | ]); |
| 121: | } |
| 122: | } |
| 123: | |
| 124: | ?> |
| 125: | |