488743d50552e93e8f651714a0583709d2c76aa3
2 /***************************************************************************
3 * Copyright (C) 2003-2006 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 class PlatalModule
extends PLModule
27 'preferences' => $this->make_hook('prefs', AUTH_COOKIE
),
28 'password' => $this->make_hook('password', AUTH_MDP
),
29 'tmpPWD' => $this->make_hook('tmpPWD', AUTH_PUBLIC
),
30 'skin' => $this->make_hook('skin', AUTH_COOKIE
),
34 function handler_prefs(&$page)
38 $page->changeTpl('preferences.tpl');
39 $page->assign('xorg_title','Polytechnique.org - Mes préférences');
41 if (Env
::has('mail_fmt')) {
42 $fmt = Env
::get('mail_fmt');
43 if ($fmt != 'texte') $fmt = 'html';
44 $globals->xdb
->execute("UPDATE auth_user_quick
45 SET core_mail_fmt = '$fmt'
47 Session
::getInt('uid'));
48 $_SESSION['mail_fmt'] = $fmt;
49 redirect('preferences');
52 if (Env
::has('rss')) {
53 if (Env
::getBool('rss')) {
54 $_SESSION['core_rss_hash'] = rand_url_id(16);
55 $globals->xdb
->execute('UPDATE auth_user_quick
56 SET core_rss_hash={?} WHERE user_id={?}',
57 Session
::get('core_rss_hash'),
58 Session
::getInt('uid'));
60 $globals->xdb
->execute('UPDATE auth_user_quick
61 SET core_rss_hash="" WHERE user_id={?}',
62 Session
::getInt('uid'));
63 Session
::kill('core_rss_hash');
65 redirect('preferences');
68 $page->assign('prefs', $globals->hook
->prefs());
73 function handler_password(&$page)
77 if (Post
::has('response2')) {
78 require_once 'secure_hash.inc.php';
80 $_SESSION['password'] = $password = Post
::get('response2');
82 $globals->xdb
->execute('UPDATE auth_user_md5
84 WHERE user_id={?}', $password,
85 Session
::getInt('uid'));
87 $log =& Session
::getMixed('log');
88 $log->log('passwd', '');
90 if (Cookie
::get('ORGaccess')) {
91 setcookie('ORGaccess', hash_encrypt($password), (time()+
25920000), '/', '' ,0);
94 $page->changeTpl('motdepasse.success.tpl');
98 $page->changeTpl('motdepasse.tpl');
99 $page->addJsLink('javascript/motdepasse.js');
100 $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
105 function handler_tmpPWD(&$page, $certif = null
)
109 $globals->xdb
->execute('DELETE FROM perte_pass
110 WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created');
112 $res = $globals->xdb
->query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif);
113 $ligne = $res->fetchOneAssoc();
115 $page->changeTpl('index.tpl');
116 $page->kill("Cette adresse n'existe pas ou n'existe plus sur le serveur.");
119 $uid = $ligne["uid"];
120 if (Post
::has('response2')) {
121 $password = Post
::get('response2');
122 $logger = new DiogenesCoreLogger($uid);
123 $globals->xdb
->query('UPDATE auth_user_md5 SET password={?}
124 WHERE user_id={?} AND perms IN("admin","user")',
126 $globals->xdb
->query('DELETE FROM perte_pass WHERE certificat={?}', $certif);
127 $logger->log("passwd","");
128 $page->changeTpl('tmpPWD.success.tpl');
130 $page->changeTpl('motdepasse.tpl');
131 $page->addJsLink('javascript/motdepasse.js');
137 function handler_skin(&$page)
141 if (!$globals->skin
->enable
) {
145 $page->changeTpl('skins.tpl');
146 $page->assign('xorg_title','Polytechnique.org - Skins');
148 if (Env
::has('newskin')) { // formulaire soumis, traitons les données envoyées
149 $globals->xdb
->execute('UPDATE auth_user_quick
150 SET skin={?} WHERE user_id={?}',
151 Env
::getInt('newskin'),
152 Session
::getInt('uid'));
156 $sql = "SELECT s.*,auteur,count(*) AS nb
158 LEFT JOIN auth_user_quick AS a ON s.id=a.skin
159 WHERE skin_tpl != '' AND ext != ''
160 GROUP BY id ORDER BY s.date DESC";
161 $page->assign_by_ref('skins', $globals->xdb
->iterator($sql));