2 /***************************************************************************
3 * Copyright (C) 2003-2009 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) {
56 // Should we check the publicity of the alias?
57 $user = User
::getSilent($x . '@' . $globals->mail
->alias_dom
);
58 return $user ?
$user : null
;
62 function get_user_openid_url($user)
68 return $globals->baseurl
. '/openid/' . $user->hruid
;
71 function get_idp_xrds_url()
74 return $globals->baseurl
. '/openid/idp_xrds';
77 function get_user_xrds_url($user)
83 return $globals->baseurl
. '/openid/user_xrds/' . $user->hruid
;
86 function get_sreg_data($user)
91 return array('fullname' => $user->fullName(),
92 'nickname' => $user->displayName(),
94 'email' => $user->bestEmail(),
95 'gender' => $user->isFemale() ?
'F' : 'M',
102 function is_trusted_site($user, $url)
104 $res = XDB
::query('SELECT COUNT(*)
106 WHERE (user_id = {?} OR user_id IS NULL)
109 return $res->fetchOneCell() > 0;
112 function add_trusted_site($user, $url)
114 XDB
::execute("INSERT IGNORE INTO openid_trusted
115 SET user_id={?}, url={?}",
119 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: