Happy New Year!
[platal.git] / modules / auth / auth.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
12262f13 3 * Copyright (C) 2003-2011 Polytechnique.org *
0337d704 4 * http://opensource.polytechnique.org/ *
5 * *
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. *
10 * *
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. *
15 * *
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 *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
670b0ac0 22function gpex_prepare_param($name, $val, &$to_hash, $charset)
23{
24 $val = iconv('UTF-8', $charset, $val);
25 $to_hash .= $val;
15dec88f 26 return '&' . $name . '=' . urlencode($val);
670b0ac0 27}
28
29function gpex_make($chlg, $privkey, $datafields, $charset)
9881e0b2 30{
0337d704 31 $tohash = "1$chlg$privkey";
9881e0b2 32 $params = "";
670b0ac0 33 $fieldarr = explode(',', $datafields);
0337d704 34
94b72319
FB
35 $user =& S::user();
36 if ($user->hasProfile()) {
7a12b2ca 37 /* Transition table for authentification. */
94b72319 38 $personnal_data = $user->profile()->data();
0aa0d3a8
PC
39 $personnal_data['full_promo'] = $personnal_data['promo'];
40 $personnal_data['promo'] = $personnal_data['entry_year'];
94b72319
FB
41 $personnal_data['matricule'] = $personnal_data['xorg_id'];
42 $personnal_data['matricule_ax'] = $personnal_data['ax_id'];
0aa0d3a8 43 $personnal_data['promo_sortie'] = $personnal_data['grad_year'];
94b72319
FB
44 $personnal_data['nationalite'] = $personnal_data['nationality1'];
45 $personnal_data['naissance'] = $personnal_data['birthdate'];
46 $personnal_data['deces'] = $personnal_data['deathdate'];
c8fe767d
PC
47 $personnal_data['nom'] = $personnal_data['lastname'];
48 $personnal_data['prenom'] = $personnal_data['firstname'];
94b72319
FB
49 $personnal_data['flags'] = $user->profile()->isFemale() ? 'femme' : '';
50 } else {
51 $personnal_data = array();
52 }
5d292fd8 53
54 foreach ($fieldarr as $val) {
6e181f3e 55 // Determine the requested value, and add it to the answer.
b3454c7f 56 if ($val == 'perms') {
dd70cd28 57 $params .= gpex_prepare_param($val, S::admin() ? 'admin' : 'user', $tohash, $charset);
6e181f3e
VZ
58 } else if ($val == 'forlife') {
59 $params .= gpex_prepare_param($val, S::v('hruid'), $tohash, $charset);
b3454c7f 60 } else if (S::has($val)) {
670b0ac0 61 $params .= gpex_prepare_param($val, S::v($val), $tohash, $charset);
9f3acd20 62 } else if (isset($personnal_data[$val])) {
670b0ac0 63 $params .= gpex_prepare_param($val, $personnal_data[$val], $tohash, $charset);
0337d704 64 } else if ($val == 'username') {
94b72319
FB
65 $res = XDB::query("SELECT alias
66 FROM aliases
fe13bc1d 67 WHERE uid = {?} AND FIND_IN_SET('bestalias', flags)",
94b72319 68 S::i('uid'));
0337d704 69 $min_username = $res->fetchOneCell();
670b0ac0 70 $params .= gpex_prepare_param($val, $min_username, $tohash, $charset);
b49f3f40 71 } else if ($val == 'grpauth') {
670b0ac0 72 if (isset($_GET['group'])) {
73 $res = XDB::query("SELECT perms
eb41eda9
FB
74 FROM group_members
75 INNER JOIN groups ON(id = asso_id)
670b0ac0 76 WHERE uid = {?} AND diminutif = {?}",
77 S::v('uid'), $_GET['group']);
78 $perms = $res->fetchOneCell();
79 } else {
80 // if no group asked, return main rights
dd70cd28 81 $perms = S::admin() ? 'admin' : 'membre';
670b0ac0 82 }
83 $params .= gpex_prepare_param($val, $perms, $tohash, $charset);
94b72319
FB
84 } else {
85 $params .= gpex_prepare_param($val, '', $tohash, $charset);
5d292fd8 86 }
0337d704 87 }
88 $tohash .= "1";
9881e0b2 89 $auth = md5($tohash);
670b0ac0 90 return array($auth, "&auth=" . $auth . $params);
0337d704 91}
92
93/* cree les parametres de l'URL de retour avec les champs demandes */
670b0ac0 94function gpex_make_params($chlg, $privkey, $datafields, $charset)
95{
96 list ($auth, $param) = gpex_make($chlg, $privkey, $datafields, $charset);
97 return $param;
0337d704 98}
99
a7de4ef7 100// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 101?>