2 /***************************************************************************
3 * Copyright (C) 2003-2007 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 RegisterModule
extends PLModule
27 'register' => $this->make_hook('register', AUTH_PUBLIC
),
28 'register/end' => $this->make_hook('end', AUTH_PUBLIC
),
29 'register/end.php' => $this->make_hook('end_old', AUTH_PUBLIC
),
30 'register/success' => $this->make_hook('success', AUTH_MDP
),
34 function handler_register(&$page, $hash = null
)
37 $sub_state = S
::v('sub_state', Array());
38 if (!isset($sub_state['step'])) {
39 $sub_state['step'] = 0;
41 if (!isset($sub_state['backs'])) {
42 $sub_state['backs'] = array();
44 if (Get
::has('back') && Get
::i('back') < $sub_state['step']) {
45 $sub_state['step'] = max(0,Get
::i('back'));
47 unset($state['backs']);
48 $sub_state['backs'][] = $state;
49 if (count($sub_state['backs']) == 3) {
50 $alert .= "Tentative d'inscription tres hesitante - ";
54 // Compatibility with old sources, keep it atm
55 if (!$hash && Env
::has('hash')) {
56 $hash = Env
::v('hash');
61 "SELECT m.uid, u.promo, u.nom, u.prenom, u.matricule, u.naissance_ini, FIND_IN_SET('watch', u.flags)
62 FROM register_marketing AS m
63 INNER JOIN auth_user_md5 AS u ON u.user_id = m.uid
64 WHERE m.hash={?}", $hash);
65 if (list($uid, $promo, $nom, $prenom, $ourmat, $naiss, $watch) = $res->fetchOneRow()) {
66 $sub_state['uid'] = $uid;
67 $sub_state['hash'] = $hash;
68 $sub_state['promo'] = $promo;
69 $sub_state['nom'] = $nom;
70 $sub_state['prenom'] = $prenom;
71 $sub_state['ourmat'] = $ourmat;
72 $sub_state['watch'] = $watch;
73 $sub_state['naissance_ini'] = $naiss;
76 "REPLACE INTO register_mstats (uid,sender,success)
77 SELECT m.uid, m.sender, 0
78 FROM register_marketing AS m
79 WHERE m.hash", $sub_state['hash']);
83 switch ($sub_state['step']) {
85 require_once('wiki.inc.php');
86 wiki_require_page('Reference.Charte');
87 if (Post
::has('step1')) {
88 $sub_state['step'] = 1;
89 if (isset($sub_state['hash'])) {
90 $sub_state['step'] = 3;
91 require_once(dirname(__FILE__
) . '/register/register.inc.php');
92 create_aliases($sub_state);
98 if (Post
::has('promo')) {
99 $promo = Post
::i('promo');
100 $res = XDB
::query("SELECT COUNT(*)
102 WHERE perms='pending' AND deces = '0000-00-00'
105 if (!$res->fetchOneCell()) {
106 $err = "La promotion saisie est incorrecte ou tous les camardes de cette promo sont inscrits !";
108 $sub_state['step'] = 2;
109 $sub_state['promo'] = $promo;
110 if ($promo >= 1996 && $promo<2000) {
111 $sub_state['mat'] = ($promo %
100)*10 . '???';
112 } elseif($promo >= 2000) {
113 $sub_state['mat'] = 100 +
($promo %
100) . '???';
121 require_once(dirname(__FILE__
) . '/register/register.inc.php');
122 $sub_state['prenom'] = Post
::v('prenom');
123 $sub_state['nom'] = Post
::v('nom');
124 $sub_state['mat'] = Post
::v('mat');
125 $err = check_new_user($sub_state);
127 if ($err !== true
) { break; }
128 $err = create_aliases($sub_state);
131 $sub_state['step'] = 3;
138 require_once(dirname(__FILE__
) . '/register/register.inc.php');
139 if (!isvalid_email(Post
::v('email'))) {
140 $err[] = "Le champ 'E-mail' n'est pas valide.";
141 } elseif (!isvalid_email_redirection(Post
::v('email'))) {
142 $err[] = $sub_state['forlife']." doit renvoyer vers un email existant ".
143 "valide, en particulier, il ne peut pas être renvoyé vers lui-même.";
145 $birth = trim(Env
::v('naissance'));
146 if (!preg_match('/^[0-3][0-9][01][0-9][12][90][0-9][0-9]$/', $birth)) {
147 $err[] = "La 'Date de naissance' n'est pas correcte.";
149 $year = (int)substr($birth, 4, 4);
150 $promo = (int)$sub_state['promo'];
151 if ($year > $promo - 15 ||
$year < $promo - 30) {
152 $err[] = "La 'Date de naissance' n'est pas correcte.";
153 $alert = "Date de naissance incorrecte a l'inscription - ";
154 $sub_state['wrong_naissance'] = $birth;
158 // Check if the given email is known as dangerous
159 $res = Xdb
::iterRow("SELECT w.state, w.description, a.alias
161 INNER JOIN emails_watch AS w ON (e.email = w.email AND w.state != 'safe')
162 INNER JOIN aliases AS a ON (e.uid = a.id AND a.type = 'a_vie')
164 ORDER BY a.alias", Post
::v('email'));
166 while(list($gstate, $gdescription, $alias) = $res->next()) {
168 $description = $gdescription;
171 if (count($aliases) != 0) {
172 $alert .= "Email surveille propose a l'inscription - ";
174 if ($sub_state['watch']) {
175 $alter .= "Inscription d'un utilisateur surveillé - ";
178 if (check_ip('unsafe')) {
183 $err = join('<br />', $err);
185 $sub_state['naissance'] = sprintf("%s-%s-%s",
189 if ($sub_state['naissance_ini'] != '0000-00-00' && $sub_state['naissance'] != $sub_state['naissance_ini']) {
190 $alert .= "Date de naissance incorrecte à l'inscription - ";
192 $sub_state['email'] = Post
::v('email');
193 if (check_ip('unsafe')) {
194 $err = "Une erreur s'est produite lors de l'inscription."
195 . " Merci de contacter <a href='mailto:register@polytechnique.org'>register@polytechnique.org</a>"
196 . " pour nous faire part de cette erreur";
197 $alert .= "Tentative d'inscription depuis une IP surveillee";
199 $sub_state['step'] = 4;
200 if (count($sub_state['backs']) >= 3) {
201 $alert .= "Fin d'une inscription hésitante";
203 finish_ins($sub_state);
210 $_SESSION['sub_state'] = $sub_state;
212 send_warning_mail($alert);
214 $page->changeTpl('register/step'.intval($sub_state['step']).'.tpl');
220 function handler_end_old(&$page)
222 return $this->handler_end($page, Env
::v('hash'));
225 function handler_end(&$page, $hash = null
)
230 $page->changeTpl('register/end.tpl');
231 $_SESSION['sub_state'] = array('step' => 5);
233 if (check_ip('unsafe')) {
234 send_warning_mail('Une IP surveillée a tenté de finaliser son inscription');
235 XDB
::execute('DELETE FROM register_pending
236 WHERE hash = {?} AND hash != \'INSCRIT\'', $hash);
240 require_once('user.func.inc.php');
244 "SELECT r.uid, r.forlife, r.bestalias, r.mailorg2,
245 r.password, r.email, r.naissance, u.nom, u.prenom,
246 u.promo, FIND_IN_SET('femme', u.flags), u.naissance_ini
247 FROM register_pending AS r
248 INNER JOIN auth_user_md5 AS u ON r.uid = u.user_id
249 WHERE hash={?} AND hash!='INSCRIT'", $hash);
252 if (!$hash ||
!list($uid, $forlife, $bestalias, $mailorg2, $password, $email,
253 $naissance, $nom, $prenom, $promo, $femme, $naiss_ini) = $res->fetchOneRow())
255 $page->kill("<p>Cette adresse n'existe pas, ou plus, sur le serveur.</p>
256 <p>Causes probables :</p>
258 <li>Vérifie que tu visites l'adresse du dernier
259 e-mail reçu s'il y en a eu plusieurs.</li>
260 <li>Tu as peut-être mal copié l'adresse reçue par
261 mail, vérifie-la à la main.</li>
262 <li>Tu as peut-être attendu trop longtemps pour
263 confirmer. Les pré-inscriptions sont annulées
264 tous les 30 jours.</li>
265 <li>Tu es en fait déjà inscrit.</li>
271 /***********************************************************/
272 /****************** REALLY CREATE ACCOUNT ******************/
273 /***********************************************************/
275 XDB
::execute('UPDATE auth_user_md5
276 SET password={?}, perms="user",
277 date=NOW(), naissance={?}, date_ins = NOW()
278 WHERE user_id={?}', $password, $naissance, $uid);
279 XDB
::execute('REPLACE INTO auth_user_quick (user_id) VALUES ({?})', $uid);
280 XDB
::execute('INSERT INTO aliases (id,alias,type)
281 VALUES ({?}, {?}, "a_vie")', $uid,
283 XDB
::execute('INSERT INTO aliases (id,alias,type,flags)
284 VALUES ({?}, {?}, "alias", "bestalias")',
287 XDB
::execute('INSERT INTO aliases (id,alias,type)
288 VALUES ({?}, {?}, "alias")', $uid,
292 require_once('emails.inc.php');
293 $redirect = new Redirect($uid);
294 $redirect->add_email($email);
296 // on cree un objet logger et on log l'inscription
297 $logger = new CoreLogger($uid);
298 $logger->log('inscription', $email);
300 XDB
::execute('UPDATE register_pending SET hash="INSCRIT" WHERE uid={?}', $uid);
303 $platal->on_subscribe($forlife, $uid, $promo, $password);
305 $mymail = new PlMailer('register/inscription.reussie.tpl');
306 $mymail->assign('forlife', $forlife);
307 $mymail->assign('prenom', $prenom);
310 if (!start_connexion($uid, false
)) {
313 $_SESSION['auth'] = AUTH_MDP
;
315 /***********************************************************/
316 /************* envoi d'un mail au démarcheur ***************/
317 /***********************************************************/
319 "SELECT DISTINCT sa.alias, IF(s.nom_usage,s.nom_usage,s.nom) AS nom,
320 s.prenom, FIND_IN_SET('femme', s.flags) AS femme
321 FROM register_marketing AS m
322 INNER JOIN auth_user_md5 AS s ON ( m.sender = s.user_id )
323 INNER JOIN aliases AS sa ON ( sa.id = m.sender
324 AND FIND_IN_SET('bestalias', sa.flags) )
325 WHERE m.uid = {?}", $uid);
326 XDB
::execute("UPDATE register_mstats SET success=NOW() WHERE uid={?}", $uid);
328 while (list($salias, $snom, $sprenom, $sfemme) = $res->next()) {
329 $mymail = new PlMailer();
330 $mymail->setSubject("$prenom $nom s'est inscrit à Polytechnique.org !");
331 $mymail->setFrom('"Marketing Polytechnique.org" <register@polytechnique.org>');
332 $mymail->addTo("\"$sprenom $snom\" <$salias@{$globals->mail->domain}>");
333 $msg = ($sfemme?
'Chère':'Cher')." $sprenom,\n\n"
334 . "Nous t'écrivons pour t'informer que $prenom $nom (X$promo), "
335 . "que tu avais incité".($femme?
'e':'')." à s'inscrire à Polytechnique.org, "
336 . "vient à l'instant de terminer son inscription.\n\n"
337 . "Merci de ta participation active à la reconnaissance de ce site !!!\n\n"
338 . "Bien cordialement,\n"
339 . "L'équipe Polytechnique.org";
340 $mymail->setTxtBody(wordwrap($msg, 72));
344 /**** send a mail to X.org administrators ****/
345 if ($globals->register
->notif
) {
346 $mymail = new PlMailer();
347 $mymail->setSubject("Inscription de $prenom $nom (X$promo)");
348 $mymail->setFrom('"Webmaster Polytechnique.org" <web@polytechnique.org>');
349 $mymail->addTo($globals->register
->notif
);
350 $msg = "$prenom $nom (X$promo) a terminé son inscription avec les données suivantes :\n"
352 . " - prenom : $prenom\n"
353 . " - promo : $promo\n"
354 . " - naissance : $naissance (date connue : $naiss_ini)\n"
355 . " - forlife : $forlife\n"
356 . " - email : $email\n"
357 . " - sexe : $femme\n"
358 . " - ip : {$logger->ip} ({$logger->host})\n"
359 . ($logger->proxy_ip ?
" - proxy : {$logger->proxy_ip} ({$logger->proxy_host})\n" : "");
360 $mymail->setTxtBody($msg);
364 Marketing
::clear($uid);
366 pl_redirect('register/success');
367 $page->assign('uid', $uid);
370 function handler_success(&$page)
372 $page->changeTpl('register/success.tpl');
374 $_SESSION['sub_state'] = array('step' => 5);
375 if (Env
::has('response2')) {
376 $_SESSION['password'] = $password = Post
::v('response2');
378 XDB
::execute('UPDATE auth_user_md5 SET password={?}
379 WHERE user_id={?}', $password,
383 $log->log('passwd', '');
385 if (Cookie
::v('ORGaccess')) {
386 require_once('secure_hash.inc.php');
387 setcookie('ORGaccess', hash_encrypt($password), (time()+
25920000), '/', '' ,0);
390 $page->assign('mdpok', true
);
393 $res = XDB
::iterRow("SELECT sub, domain
395 WHERE uid = {?} AND type = 'list'
398 $current_domain = null
;
400 while (list($sub, $domain) = $res->next()) {
401 if ($current_domain != $domain) {
402 $current_domain = $domain;
403 $client = new MMList(S
::v('uid'), S
::v('password'), $domain);
405 list($details, ) = $client->get_members($sub);
406 $lists["$sub@$domain"] = $details;
408 $page->assign_by_ref('lists', $lists);
410 $page->addJsLink('motdepasse.js');
414 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: