2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 require_once "Auth/OpenID/Discover.php";
24 function init_openid_server()
26 // Initialize a filesystem-based store
27 $store_location = dirname(__FILE__
) . '/../../spool/openid/store';
28 require_once "Auth/OpenID/FileStore.php";
29 $store = new Auth_OpenID_FileStore($store_location);
31 // Create an OpenId server
32 require_once 'Auth/OpenID/Server.php';
33 return new Auth_OpenID_Server($store, get_openid_url());
36 function get_openid_url()
39 return $globals->baseurl
. '/openid';
42 function get_user($x) {
46 $user = User
::getSilent($x);
47 return $user ?
$user : null
;
51 function get_user_by_alias($x) {
55 // TODO such a function should probably be provided in the User class
56 // or at least not here
57 $res = XDB
::query('SELECT u.user_id
58 FROM auth_user_md5 AS u
59 INNER JOIN auth_user_quick AS q USING(user_id)
60 INNER JOIN aliases AS a ON (a.id = u.user_id AND type != \'homonyme\')
61 WHERE u.perms IN(\'admin\', \'user\')
62 AND q.emails_alias_pub = \'public\'
65 if (list($uid) = $res->fetchOneRow()) {
66 $user = User
::getSilent($uid);
68 return $user ?
$user : null
;
72 function get_user_openid_url($user)
78 return $globals->baseurl
. '/openid/' . $user->hruid
;
81 function get_idp_xrds_url()
84 return $globals->baseurl
. '/openid/idp_xrds';
87 function get_user_xrds_url($user)
93 return $globals->baseurl
. '/openid/user_xrds/' . $user->hruid
;
96 function get_sreg_data($user)
101 return array('fullname' => $user->fullName(),
102 'nickname' => $user->displayName(),
104 'email' => $user->bestEmail(),
105 'gender' => $user->isFemale() ?
'F' : 'M',
112 function is_trusted_site($user, $url)
114 $res = XDB
::query('SELECT COUNT(*)
116 WHERE (user_id = {?} OR user_id IS NULL)
119 return $res->fetchOneCell() > 0;
122 function add_trusted_site($user, $url)
124 XDB
::execute("INSERT IGNORE INTO openid_trusted
125 SET user_id={?}, url={?}",
129 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: