'openid/trust' => $this->make_hook('trust', AUTH_COOKIE),
'openid/idp_xrds' => $this->make_hook('idp_xrds', AUTH_PUBLIC),
'openid/user_xrds' => $this->make_hook('user_xrds', AUTH_PUBLIC),
+// 'openid/melix' => $this->make_hook('melix', AUTH_PUBLIC),
);
}
$page->assign('uri', get_openid_url());
}
+ function handler_melix(&$page, $x = null)
+ {
+ $this->load('openid.inc.php');
+ $user = get_user_by_alias($x);
+
+ // This will redirect to the canonic URL, which was not used
+ // if this hook was triggered
+ return render_discovery_page(&$page, $user);
+ }
+
//--------------------------------------------------------------------//
function render_discovery_page(&$page, $user)
pl_redirect('Xorg/OpenId');
}
+ // Redirect to the canonic URL if we are using an alias
+ // There might be a risk of redirection loop here
+ // if $_SERVER was not exactly what we expect
+ $current_url = 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . '://'
+ . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
+ $canonic_url = get_user_openid_url($user);
+ if ($current_url != $canonic_url) {
+ http_redirect($canonic_url);
+ }
+
// Include X-XRDS-Location response-header for Yadis discovery
header('X-XRDS-Location: ' . get_user_xrds_url($user));
}
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
+?>
\ No newline at end of file
}
+function get_user_by_alias($x) {
+ if (is_null($x)) {
+ return null;
+ }
+ // TODO such a function should probably be provided in the User class
+ // or at least not here
+ $res = XDB::query('SELECT u.user_id
+ FROM auth_user_md5 AS u
+ INNER JOIN aliases AS a ON (a.id = u.user_id AND type != \'homonyme\')
+ WHERE a.alias = {?} AND u.perms IN(\'admin\', \'user\')',
+ $x);
+ if (list($uid) = $res->fetchOneRow()) {
+ $user = User::getSilent($uid);
+ }
+ return $user ? $user : null;
+
+}
+
function get_user_openid_url($user)
{
if (is_null($user)) {