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 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
),
31 'register/save' => $this->make_hook('save', AUTH_MDP
),
35 function handler_register(&$page, $hash = null
)
38 $sub_state = S
::v('sub_state', Array());
39 if (!isset($sub_state['step'])) {
40 $sub_state['step'] = 0;
42 if (!isset($sub_state['backs'])) {
43 $sub_state['backs'] = array();
45 if (Get
::has('back') && Get
::i('back') < $sub_state['step']) {
46 $sub_state['step'] = max(0,Get
::i('back'));
48 unset($state['backs']);
49 $sub_state['backs'][] = $state;
50 if (count($sub_state['backs']) == 3) {
51 $alert .= "Tentative d'inscription tres hesitante - ";
55 // Compatibility with old sources, keep it atm
56 if (!$hash && Env
::has('hash')) {
57 $hash = Env
::v('hash');
62 "SELECT m.uid, u.promo, u.nom, u.prenom, u.matricule, u.naissance_ini, FIND_IN_SET('watch', u.flags)
63 FROM register_marketing AS m
64 INNER JOIN auth_user_md5 AS u ON u.user_id = m.uid
65 WHERE m.hash={?}", $hash);
66 if (list($uid, $promo, $nom, $prenom, $ourmat, $naiss, $watch) = $res->fetchOneRow()) {
67 $sub_state['uid'] = $uid;
68 $sub_state['hash'] = $hash;
69 $sub_state['promo'] = $promo;
70 $sub_state['nom'] = $nom;
71 $sub_state['prenom'] = $prenom;
72 $sub_state['ourmat'] = $ourmat;
73 $sub_state['watch'] = $watch;
74 $sub_state['naissance_ini'] = $naiss;
77 "REPLACE INTO register_mstats (uid,sender,success)
78 SELECT m.uid, m.sender, 0
79 FROM register_marketing AS m
80 WHERE m.hash", $sub_state['hash']);
84 switch ($sub_state['step']) {
86 require_once('wiki.inc.php');
87 wiki_require_page('Reference.Charte');
88 if (Post
::has('step1')) {
89 $sub_state['step'] = 1;
90 if (isset($sub_state['hash'])) {
91 $sub_state['step'] = 3;
92 require_once(dirname(__FILE__
) . '/register/register.inc.php');
93 create_aliases($sub_state);
99 if (Post
::has('promo')) {
100 $promo = Post
::i('promo');
101 $res = XDB
::query("SELECT COUNT(*)
103 WHERE perms='pending' AND deces = '0000-00-00'
106 if (!$res->fetchOneCell()) {
107 $err = "La promotion saisie est incorrecte ou tous les camardes de cette promo sont inscrits !";
109 $sub_state['step'] = 2;
110 $sub_state['promo'] = $promo;
111 if ($promo >= 1996 && $promo<2000) {
112 $sub_state['mat'] = ($promo %
100)*10 . '???';
113 } elseif($promo >= 2000) {
114 $sub_state['mat'] = 100 +
($promo %
100) . '???';
122 require_once(dirname(__FILE__
) . '/register/register.inc.php');
123 $sub_state['prenom'] = Post
::v('prenom');
124 $sub_state['nom'] = Post
::v('nom');
125 $sub_state['mat'] = Post
::v('mat');
126 $err = check_new_user($sub_state);
128 if ($err !== true
) { break; }
129 $err = create_aliases($sub_state);
132 $sub_state['step'] = 3;
139 require_once(dirname(__FILE__
) . '/register/register.inc.php');
140 if (!isvalid_email(Post
::v('email'))) {
141 $err[] = "Le champ 'E-mail' n'est pas valide.";
142 } elseif (!isvalid_email_redirection(Post
::v('email'))) {
143 $err[] = $sub_state['forlife']." doit renvoyer vers un email existant ".
144 "valide, en particulier, il ne peut pas être renvoyé vers lui-même.";
146 $birth = trim(Env
::v('naissance'));
147 if (!preg_match('@^[0-3]?\d/[01]?\d/(19|20)?\d{2}$@', $birth)) {
148 $err[] = "La 'Date de naissance' n'est pas correcte.";
150 $birth = explode('/', $birth, 3);
151 for ($i = 0; $i < 3; $i++
)
152 $birth[$i] = intval($birth[$i]);
153 if ($birth[2] < 100) $birth[2] +
= 1900;
155 $promo = (int)$sub_state['promo'];
156 if ($year > $promo - 15 ||
$year < $promo - 30) {
157 $err[] = "La 'Date de naissance' n'est pas correcte.";
158 $alert = "Date de naissance incorrecte a l'inscription - ";
159 $sub_state['wrong_naissance'] = $birth;
163 // Check if the given email is known as dangerous
164 $res = XDB
::query("SELECT w.state, w.description
165 FROM emails_watch AS w
166 WHERE w.email = {?} AND w.state != 'safe'",
168 $email_banned = false
;
169 if ($res->numRows()) {
170 list($state, $description) = $res->fetchOneRow();
171 $alert .= "Email surveille propose a l'inscription - ";
172 $sub_state['email_desc'] = $description;
173 if ($state == 'dangerous') {
174 $email_banned = true
;
177 if ($sub_state['watch']) {
178 $alert .= "Inscription d'un utilisateur surveillé - ";
181 if (check_ip('unsafe')) {
186 $err = join('<br />', $err);
188 $sub_state['naissance'] = sprintf("%04d-%02d-%02d",
189 intval($birth[2]), intval($birth[1]), intval($birth[0]));
190 if ($sub_state['naissance_ini'] != '0000-00-00' && $sub_state['naissance'] != $sub_state['naissance_ini']) {
191 $alert .= "Date de naissance incorrecte à l'inscription - ";
193 $sub_state['email'] = Post
::v('email');
194 $ip_banned = check_ip('unsafe');
196 $alert .= "Tentative d'inscription depuis une IP surveillee";
198 if ($email_banned ||
$ip_banned) {
200 $err = "Une erreur s'est produite lors de l'inscription."
201 . " Merci de contacter <a href='mailto:register@{$globals->mail->domain}>"
202 . " register@{$globals->mail->domain}</a>"
203 . " pour nous faire part de cette erreur";
205 $sub_state['step'] = 4;
206 if (count($sub_state['backs']) >= 3) {
207 $alert .= "Fin d'une inscription hésitante";
209 finish_ins($sub_state);
216 $_SESSION['sub_state'] = $sub_state;
217 if (!empty($alert)) {
218 send_warning_mail($alert);
220 $page->changeTpl('register/step'.intval($sub_state['step']).'.tpl');
222 $page->trigError($err);
226 function handler_end_old(&$page)
228 return $this->handler_end($page, Env
::v('hash'));
231 function handler_end(&$page, $hash = null
)
236 $page->changeTpl('register/end.tpl');
237 $_SESSION['sub_state'] = array('step' => 5);
239 if (check_ip('unsafe')) {
240 send_warning_mail('Une IP surveillée a tenté de finaliser son inscription');
241 XDB
::execute('DELETE FROM register_pending
242 WHERE hash = {?} AND hash != \'INSCRIT\'', $hash);
246 require_once('user.func.inc.php');
250 "SELECT r.uid, r.forlife, r.bestalias, r.mailorg2,
251 r.password, r.email, r.naissance, u.nom, u.prenom,
252 u.promo, FIND_IN_SET('femme', u.flags), u.naissance_ini
253 FROM register_pending AS r
254 INNER JOIN auth_user_md5 AS u ON r.uid = u.user_id
255 WHERE hash={?} AND hash!='INSCRIT'", $hash);
258 if (!$hash ||
!list($uid, $forlife, $bestalias, $mailorg2, $password, $email,
259 $naissance, $nom, $prenom, $promo, $femme, $naiss_ini) = $res->fetchOneRow())
261 $page->kill("<p>Cette adresse n'existe pas, ou plus, sur le serveur.</p>
262 <p>Causes probables :</p>
264 <li>Vérifie que tu visites l'adresse du dernier
265 e-mail reçu s'il y en a eu plusieurs.</li>
266 <li>Tu as peut-être mal copié l'adresse reçue par
267 mail, vérifie-la à la main.</li>
268 <li>Tu as peut-être attendu trop longtemps pour
269 confirmer. Les pré-inscriptions sont annulées
270 tous les 30 jours.</li>
271 <li>Tu es en fait déjà inscrit.</li>
277 /***********************************************************/
278 /****************** REALLY CREATE ACCOUNT ******************/
279 /***********************************************************/
281 XDB
::execute('UPDATE auth_user_md5
282 SET password={?}, perms="user",
283 date=NOW(), naissance={?}, date_ins = NOW()
284 WHERE user_id={?}', $password, $naissance, $uid);
285 XDB
::execute('REPLACE INTO auth_user_quick (user_id) VALUES ({?})', $uid);
286 XDB
::execute('INSERT INTO aliases (id,alias,type)
287 VALUES ({?}, {?}, "a_vie")', $uid,
289 XDB
::execute('INSERT INTO aliases (id,alias,type,flags)
290 VALUES ({?}, {?}, "alias", "bestalias")',
293 XDB
::execute('INSERT INTO aliases (id,alias,type)
294 VALUES ({?}, {?}, "alias")', $uid,
298 require_once('emails.inc.php');
299 $redirect = new Redirect($uid);
300 $redirect->add_email($email);
302 // on cree un objet logger et on log l'inscription
303 $logger = new CoreLogger($uid);
304 $logger->log('inscription', $email);
306 XDB
::execute('UPDATE register_pending SET hash="INSCRIT" WHERE uid={?}', $uid);
309 $platal->on_subscribe($forlife, $uid, $promo, $password);
311 $mymail = new PlMailer('register/inscription.reussie.tpl');
312 $mymail->assign('forlife', $forlife);
313 $mymail->assign('prenom', $prenom);
316 require_once('user.func.inc.php');
319 // update number of subscribers (perms has changed)
322 if (!start_connexion($uid, false
)) {
325 $_SESSION['auth'] = AUTH_MDP
;
327 /***********************************************************/
328 /************* envoi d'un mail au démarcheur ***************/
329 /***********************************************************/
331 "SELECT sa.alias, IF(s.nom_usage,s.nom_usage,s.nom) AS nom,
332 s.prenom, FIND_IN_SET('femme', s.flags) AS femme,
333 GROUP_CONCAT(m.email) AS mails, MAX(m.last) AS dateDernier
334 FROM register_marketing AS m
335 INNER JOIN auth_user_md5 AS s ON ( m.sender = s.user_id )
336 INNER JOIN aliases AS sa ON ( sa.id = m.sender
337 AND FIND_IN_SET('bestalias', sa.flags) )
339 GROUP BY m.sender", $uid);
340 XDB
::execute("UPDATE register_mstats SET success=NOW() WHERE uid={?}", $uid);
343 while (list($salias, $snom, $sprenom, $sfemme, $mails, $dateDernier) = $res->next()) {
344 $market[] = " - par $snom $sprenom sur $mails (le plus récemment le $dateDernier)";
345 $mymail = new PlMailer();
346 $mymail->setSubject("$prenom $nom s'est inscrit à Polytechnique.org !");
347 $mymail->setFrom('"Marketing Polytechnique.org" <register@' . $globals->mail
->domain
. '>');
348 $mymail->addTo("\"$sprenom $snom\" <$salias@{$globals->mail->domain}>");
349 $msg = ($sfemme?
'Chère':'Cher')." $sprenom,\n\n"
350 . "Nous t'écrivons pour t'informer que $prenom $nom (X$promo), "
351 . "que tu avais incité".($femme?
'e':'')." à s'inscrire à Polytechnique.org, "
352 . "vient à l'instant de terminer son inscription.\n\n"
353 . "Merci de ta participation active à la reconnaissance de ce site !!!\n\n"
354 . "Bien cordialement,\n"
355 . "L'équipe Polytechnique.org";
356 $mymail->setTxtBody(wordwrap($msg, 72));
360 /**** send a mail to X.org administrators ****/
361 if ($globals->register
->notif
) {
362 $mymail = new PlMailer();
363 $mymail->setSubject("Inscription de $prenom $nom (X$promo)");
364 $mymail->setFrom('"Webmaster Polytechnique.org" <web@' . $globals->mail
->domain
. '>');
365 $mymail->addTo($globals->register
->notif
);
366 $mymail->addHeader('Reply-To', $globals->register
->notif
);
367 $msg = "$prenom $nom (X$promo) a terminé son inscription avec les données suivantes :\n"
369 . " - prenom : $prenom\n"
370 . " - promo : $promo\n"
371 . " - naissance : $naissance (date connue : $naiss_ini)\n"
372 . " - forlife : $forlife\n"
373 . " - email : $email\n"
374 . " - sexe : $femme\n"
375 . " - ip : {$logger->ip} ({$logger->host})\n"
376 . ($logger->proxy_ip ?
" - proxy : {$logger->proxy_ip} ({$logger->proxy_host})\n" : "")
378 if (count($market) > 0) {
379 $msg .= "Les marketings suivants avaient été effectués :\n"
380 . implode("\n", $market);
382 $msg .= "$prenom $nom n'a jamais reçu de mail de marketing.";
384 $mymail->setTxtBody($msg);
388 Marketing
::clear($uid);
390 pl_redirect('register/success');
391 $page->assign('uid', $uid);
394 function handler_success(&$page)
397 $page->changeTpl('register/success.tpl');
399 $_SESSION['sub_state'] = array('step' => 5);
400 if (Env
::has('response2')) {
401 $_SESSION['password'] = $password = Post
::v('response2');
403 XDB
::execute('UPDATE auth_user_md5 SET password={?}
404 WHERE user_id={?}', $password,
407 // If GoogleApps is enabled, and the user did choose to use synchronized passwords,
408 // and if the (stupid) user has decided to user /register/success another time,
409 // updates the Google Apps password as well.
410 if ($globals->mailstorage
->googleapps_domain
) {
411 require_once 'googleapps.inc.php';
412 $account = new GoogleAppsAccount(S
::v('uid'), S
::v('forlife'));
413 if ($account->active() && $account->sync_password
) {
414 $account->set_password($password);
419 $log->log('passwd', '');
421 if (Cookie
::v('ORGaccess')) {
422 require_once('secure_hash.inc.php');
423 setcookie('ORGaccess', hash_encrypt($password), (time()+
25920000), '/', '' ,0);
426 $page->assign('mdpok', true
);
429 $res = XDB
::iterRow("SELECT sub, domain
431 WHERE uid = {?} AND type = 'list'
434 $current_domain = null
;
436 while (list($sub, $domain) = $res->next()) {
437 if ($current_domain != $domain) {
438 $current_domain = $domain;
439 $client = new MMList(S
::v('uid'), S
::v('password'), $domain);
441 list($details, ) = $client->get_members($sub);
442 $lists["$sub@$domain"] = $details;
444 $page->assign_by_ref('lists', $lists);
446 $page->addJsLink('motdepasse.js');
449 function handler_save(&$page)
453 // Finish registration procedure
454 if (Post
::v('register_from_ax_question')) {
455 XDB
::execute('UPDATE auth_user_quick
456 SET profile_from_ax = 1
457 WHERE user_id = {?}',
460 if (Post
::v('add_to_nl')) {
461 require_once 'newsletter.inc.php';
462 NewsLetter
::subscribe();
464 if (Post
::v('add_to_ax')) {
465 require_once dirname(__FILE__
) . '/axletter/axletter.inc.php';
466 AXLetter
::subscribe();
468 if (Post
::v('add_to_promo')) {
469 $r = XDB
::query('SELECT id FROM groupex.asso WHERE diminutif = {?}',
471 $asso_id = $r->fetchOneCell();
472 XDB
::execute('REPLACE INTO groupex.membres (uid,asso_id)
474 S
::v('uid'), $asso_id);
475 $mmlist = new MMList(S
::v('uid'), S
::v('password'));
476 $mmlist->subscribe("promo".S
::v('promo'));
478 if (Post
::v('sub_ml')) {
479 $subs = array_keys(Post
::v('sub_ml'));
480 $current_domain = null
;
481 foreach ($subs as $list) {
482 list($sub, $domain) = explode('@', $list);
483 if ($domain != $current_domain) {
484 $current_domain = $domain;
485 $client = new MMList(S
::v('uid'), S
::v('password'), $domain);
487 $client->subscribe($sub);
490 if (Post
::v('imap')) {
491 require_once 'emails.inc.php';
492 $storage = new EmailStorage(S
::v('uid'), 'imap');
493 $storage->activate();
496 pl_redirect('profile/edit');
500 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: