daacf519a0613c91e2cea0c12a0b13ee0552820b
2 /***************************************************************************
3 * Copyright (C) 2003-2013 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 // {{{ function strongCheckId
24 function strongCheckId($subState)
26 $subState->set('xorgid', Profile
::getXorgId($subState->i('schoolid')));
27 if (!$subState->v('xorgid')) {
28 return 'Le matricule est incorrect.';
31 $uf = new UserFilter(new PFC_And(
32 new UFC_SchoolId('xorg', $subState->i('xorgid')),
33 new PFC_Not(new UFC_Dead()),
34 new PFC_Not(new UFC_Registered(true
))
36 $profile = $uf->getProfile();
37 if (is_null($profile)) {
38 return "Tu es déjà inscrit ou ton matricule est incorrect !";
41 if ($profile->promo() != $subState->s('promo')) {
42 return 'Le matricule est incorrect.';
45 if (!$profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) {
46 return "Erreur dans l'identification. Réessaie, il y a une erreur quelque part !";
49 $subState->set('lastname', $profile->lastName());
50 $subState->set('firstname', $profile->firstName());
51 $subState->set('uid', $profile->owner()->id());
52 $subState->set('watch', $profile->owner()->watch
);
53 $subState->set('comment', $profile->owner()->comment
);
54 $subState->set('birthdateRef', $profile->__get('birthdate_ref'));
59 // {{{ function weakCheckId
61 function weakCheckId($subState)
63 $uf = new UserFilter(new PFC_And(
64 new PFC_Not(new UFC_Dead()),
65 new UFC_Promo('=', $subState->s('edu_type'), $subState->s('yearpromo')),
66 new PFC_Not(new UFC_Registered(true
))
68 if ($it = $uf->iterProfiles()) {
69 while ($profile = $it->next()) {
70 if ($profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) {
71 $subState->set('lastname', $profile->lastName());
72 $subState->set('firstname', $profile->firstName());
73 $subState->set('uid', $profile->owner()->id());
74 $subState->set('watch', $profile->owner()->watch
);
75 $subState->set('comment', $profile->owner()->comment
);
76 $subState->set('birthdateRef', $profile->__get('birthdate_ref'));
77 $subState->set('xorgid', $profile->__get('xorg_id'));
83 $uf = new UserFilter(new PFC_And(
84 new PFC_Not(new UFC_Dead()),
85 new UFC_Promo('=', $subState->s('edu_type'), $subState->s('yearpromo')),
86 new UFC_Registered(true
)
88 if ($it = $uf->iterProfiles()) {
89 while ($profile = $it->next()) {
90 if ($profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) {
91 $subState->set('uid', $profile->owner()->id());
92 $subState->set('watch', $profile->owner()->watch
);
93 $subState->set('comment', $profile->owner()->comment
);
94 $subState->set('birthdateRef', $profile->__get('birthdate_ref'));
95 $subState->set('xorgid', $profile->__get('xorg_id'));
96 return 'Tu es vraisemblablement déjà inscrit !';
100 return 'Erreur : vérifie que tu as bien orthographié ton nom !';
104 // {{{ function checkNewUser
106 function checkNewUser($subState)
108 $firstname = preg_replace("/[ \t]+/", ' ', $subState->t('firstname'));
109 $firstname = preg_replace("/--+/", '-', $firstname);
110 $firstname = preg_replace("/''+/", '\'', $firstname);
111 $subState->set('firstname', PlUser
::fixFirstnameCase($firstname));
113 $lastname = preg_replace("/[ \t]+/", ' ', $subState->t('lastname'));
114 $lastname = preg_replace("/--+/", '-', $lastname);
115 $lastname = preg_replace("/''+/", '\'', $lastname);
116 $subState->set('lastname', mb_strtoupper($lastname));
118 if ($subState->v('edu_type') == Profile
::DEGREE_X
&& $subState->i('yearpromo') >= 1996) {
119 $res = strongCheckId($subState);
121 $res = weakCheckId($subState);
131 // {{{ function createAliases
133 function createAliases($subState)
137 $res = XDB
::query("SELECT hruid, state, type
139 WHERE uid = {?} AND hruid != ''",
140 $subState->i('uid'));
141 if ($res->numRows() == 0) {
142 return "Tu n'as pas d'adresse à vie pré-attribuée.<br />"
143 . "Envoie un mail à <a href=\"mailto:support@{$globals->mail->domain}\">"
144 . "support@{$globals->mail->domain}</a> en expliquant ta situation.";
146 list($forlife, $state, $type) = $res->fetchOneRow();
148 if ($state == 'active') {
149 return "Tu es déjà inscrit, si tu ne te souviens plus de ton mot de passe d'accès au site, "
150 . "tu peux suivre <a href=\"recovery\">la procédure de récupération de mot de passe</a>.";
151 } else if ($state == 'disabled') {
152 return "Ton compte a été désactivé par les administrateurs du site suite à des abus. "
153 . "Pour plus d'information ou pour demander la réactivation du compte, tu peux t'adresser à "
154 . "<a href=\"mailto:support@{$globals->mail->domain}\">support@{$globals->mail->domain}</a>.";
158 $emailXorg = PlUser
::makeUserName($subState->t('firstname'), $subState->t('lastname'));
159 $suffix = (User
::$sub_mail_domains[$type] ?
substr(User
::$sub_mail_domains[$type], 0, 1) : '') . substr($subState->v('yearpromo'), -2);
160 $emailXorg2 = $emailXorg . '.' . $suffix;
161 // Search for homonyms:
162 // * first case: only one homonym already registered.
163 $res = XDB
::query('SELECT uid, expire
164 FROM email_source_account
165 WHERE email = {?} AND type != \'alias_aux\'',
167 // * second case: at least two homonyms registerd.
168 $result = XDB
::query("SELECT hrmid
169 FROM email_source_other
170 WHERE type = 'homonym' AND email = {?}",
172 if ($res->numRows() ||
$result->numRows()) {
173 if ($res->numRows()) {
174 list($h_id, $expire) = $res->fetchOneRow();
175 if (empty($expire)) {
176 XDB
::execute('UPDATE email_source_account
177 SET expire = ADDDATE(NOW(), INTERVAL 1 MONTH)
178 WHERE email = {?} AND type != \'alias_aux\'',
180 $hrmid = User
::makeHomonymHrmid($emailXorg);
181 XDB
::execute('INSERT IGNORE INTO homonyms_list (hrmid, uid)
182 VALUES ({?}, {?}), ({?}, {?})',
183 $hrmid, $h_id, $hrmid, $subState->i('uid'));
184 $als = XDB
::fetchColumn('SELECT email
185 FROM email_source_account
186 WHERE uid = {?} AND type != \'alias_aux\' AND expire IS NULL',
189 $homonym = User
::getSilentWithUID($h_id);
190 $mailer = new PlMailer('register/lostalias.mail.tpl');
191 $mailer->addTo($homonym);
192 $mailer->setSubject("Perte de ton alias $emailXorg dans un mois !");
193 $mailer->assign('emailXorg', $emailXorg);
194 $mailer->assign('als', join(', ', $als));
195 $mailer->SetTxtBody(wordwrap($msg,72));
199 $hrmid = $result->fetchOneCell();
200 XDB
::execute('INSERT IGNORE INTO homonyms_list (hrmid, uid)
202 $hrmid, $subState->i('uid'));
203 // TODO: insert into source_other if new domain
206 $subState->set('forlife', $forlife);
207 $subState->set('bestalias', $emailXorg2);
208 $subState->set('emailXorg2', null
);
210 $subState->set('forlife', $forlife);
211 $subState->set('bestalias', $emailXorg);
212 $subState->set('emailXorg2', $emailXorg2);
214 $subState->set('main_mail_domain', User
::$sub_mail_domains[$type] . Platal
::globals()->mail
->domain
);
220 // {{{ function finishRegistration
222 function finishRegistration($subState)
226 $hash = rand_url_id(12);
227 XDB
::execute('INSERT INTO register_pending (uid, forlife, bestalias, mailorg2, password,
228 email, date, relance, naissance, hash, services)
229 VALUES ({?}, {?}, {?}, {?}, {?}, {?}, NOW(), 0, {?}, {?}, {?})
230 ON DUPLICATE KEY UPDATE password=VALUES(password), email=VALUES(email),
231 date=VALUES(date), naissance=VALUES(naissance),
232 hash=VALUES(hash), services=VALUES(services)',
233 $subState->i('uid'), $subState->s('forlife'), $subState->s('bestalias'),
234 $subState->s('emailXorg2'), $subState->s('password'), $subState->s('email'),
235 $subState->s('birthdate'), $hash, implode(',', $subState->v('services')));
237 $mymail = new PlMailer('register/end.mail.tpl');
238 $mymail->assign('emailXorg', $subState->s('bestalias'));
239 $mymail->assign('to', $subState->s('email'));
240 $mymail->assign('baseurl', $globals->baseurl
);
241 $mymail->assign('hash', $hash);
242 $mymail->assign('subject', ucfirst($globals->mail
->domain
) . ' : ' . $subState->s('bestalias'));
247 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: