Commit | Line | Data |
---|---|---|
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 | ||
e4860774 | 22 | // {{{ function strongCheckId |
0337d704 | 23 | |
e4860774 | 24 | function strongCheckId($subState) |
0337d704 | 25 | { |
94590511 SJ |
26 | $subState->set('xorgid', Profile::getXorgId($subState->i('schoolid'))); |
27 | if (!$subState->v('xorgid')) { | |
28 | return 'Le matricule est incorrect.'; | |
0337d704 | 29 | } |
30 | ||
94590511 | 31 | $uf = new UserFilter(new PFC_And( |
16c709a0 | 32 | new UFC_SchoolId('xorg', $subState->i('xorgid')), |
f09bdd3d FB |
33 | new PFC_Not(new UFC_Dead()), |
34 | new PFC_Not(new UFC_Registered(true)) | |
94590511 | 35 | )); |
4b0cf4e4 | 36 | $profile = $uf->getProfile(); |
f09bdd3d | 37 | if (is_null($profile)) { |
94590511 SJ |
38 | return "Tu es déjà inscrit ou ton matricule est incorrect !"; |
39 | } | |
f09bdd3d | 40 | |
4b0cf4e4 | 41 | if ($profile->promo() != $subState->s('promo')) { |
94590511 SJ |
42 | return 'Le matricule est incorrect.'; |
43 | } | |
0337d704 | 44 | |
4b0cf4e4 | 45 | if (!$profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) { |
94590511 | 46 | return "Erreur dans l'identification. Réessaie, il y a une erreur quelque part !"; |
0337d704 | 47 | } |
48 | ||
4b0cf4e4 SJ |
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); | |
34a82c29 | 53 | $subState->set('comment', $profile->owner()->comment); |
4b0cf4e4 | 54 | $subState->set('birthdateRef', $profile->__get('birthdate_ref')); |
0337d704 | 55 | return true; |
56 | } | |
57 | ||
58 | // }}} | |
e4860774 | 59 | // {{{ function weakCheckId |
0337d704 | 60 | |
e4860774 | 61 | function weakCheckId($subState) |
0337d704 | 62 | { |
94590511 SJ |
63 | $uf = new UserFilter(new PFC_And( |
64 | new PFC_Not(new UFC_Dead()), | |
e4860774 | 65 | new UFC_Promo('=', $subState->s('edu_type'), $subState->s('yearpromo')), |
94590511 SJ |
66 | new PFC_Not(new UFC_Registered(true)) |
67 | )); | |
1ee74a83 SJ |
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); | |
34a82c29 | 75 | $subState->set('comment', $profile->owner()->comment); |
1ee74a83 SJ |
76 | $subState->set('birthdateRef', $profile->__get('birthdate_ref')); |
77 | $subState->set('xorgid', $profile->__get('xorg_id')); | |
78 | return true; | |
79 | } | |
0337d704 | 80 | } |
81 | } | |
82 | ||
94590511 SJ |
83 | $uf = new UserFilter(new PFC_And( |
84 | new PFC_Not(new UFC_Dead()), | |
e4860774 | 85 | new UFC_Promo('=', $subState->s('edu_type'), $subState->s('yearpromo')), |
94590511 SJ |
86 | new UFC_Registered(true) |
87 | )); | |
1ee74a83 SJ |
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); | |
34a82c29 | 93 | $subState->set('comment', $profile->owner()->comment); |
1ee74a83 SJ |
94 | $subState->set('birthdateRef', $profile->__get('birthdate_ref')); |
95 | $subState->set('xorgid', $profile->__get('xorg_id')); | |
96 | return 'Tu es vraisemblablement déjà inscrit !'; | |
97 | } | |
0337d704 | 98 | } |
99 | } | |
94590511 | 100 | return 'Erreur : vérifie que tu as bien orthographié ton nom !'; |
0337d704 | 101 | } |
102 | ||
103 | // }}} | |
94590511 | 104 | // {{{ function checkNewUser |
0337d704 | 105 | |
26ba053e | 106 | function checkNewUser($subState) |
0337d704 | 107 | { |
94590511 SJ |
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)); | |
112 | ||
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)); | |
117 | ||
e4860774 SJ |
118 | if ($subState->v('edu_type') == Profile::DEGREE_X && $subState->i('yearpromo') >= 1996) { |
119 | $res = strongCheckId($subState); | |
0337d704 | 120 | } else { |
e4860774 | 121 | $res = weakCheckId($subState); |
f0a52f1b | 122 | } |
94590511 SJ |
123 | if ($res !== true) { |
124 | return $res; | |
0337d704 | 125 | } |
0337d704 | 126 | |
127 | return true; | |
128 | } | |
129 | ||
130 | // }}} | |
94590511 | 131 | // {{{ function createAliases |
0337d704 | 132 | |
26ba053e | 133 | function createAliases($subState) |
0337d704 | 134 | { |
115c90db | 135 | global $globals; |
0337d704 | 136 | |
f0a52f1b | 137 | $res = XDB::query("SELECT hruid, state, type |
94590511 | 138 | FROM accounts |
4c5a5921 FB |
139 | WHERE uid = {?} AND hruid != ''", |
140 | $subState->i('uid')); | |
56081a9c VZ |
141 | if ($res->numRows() == 0) { |
142 | return "Tu n'as pas d'adresse à vie pré-attribuée.<br />" | |
4c5a5921 | 143 | . "Envoie un mail à <a href=\"mailto:support@{$globals->mail->domain}\">" |
56081a9c VZ |
144 | . "support@{$globals->mail->domain}</a> en expliquant ta situation."; |
145 | } else { | |
f0a52f1b | 146 | list($forlife, $state, $type) = $res->fetchOneRow(); |
4c5a5921 FB |
147 | } |
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>."; | |
0337d704 | 155 | } |
eaf30d86 | 156 | |
e4860774 SJ |
157 | |
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; | |
f0a52f1b SJ |
161 | $res = XDB::query('SELECT uid, expire |
162 | FROM email_source_account | |
163 | WHERE email = {?} AND type != \'alias_aux\'', | |
164 | $emailXorg); | |
165 | if ($res->numRows()) { | |
f036c896 SJ |
166 | list($h_id, $expire) = $res->fetchOneRow(); |
167 | if (empty($expire)) { | |
168 | XDB::execute('UPDATE email_source_account | |
169 | SET expire = ADDDATE(NOW(), INTERVAL 1 MONTH) | |
170 | WHERE email = {?} AND type != \'alias_aux\'', | |
171 | $emailXorg); | |
f88d9154 | 172 | $hrmid = User::makeHomonymHrmid($emailXorg); |
4371e993 | 173 | XDB::execute('INSERT IGNORE INTO homonyms_list (hrmid, uid) |
00ba8a74 | 174 | VALUES ({?}, {?}), ({?}, {?})', |
4371e993 | 175 | $hrmid, $h_id, $hrmid, $subState->i('uid')); |
f036c896 SJ |
176 | $als = XDB::fetchColumn('SELECT email |
177 | FROM email_source_account | |
178 | WHERE uid = {?} AND type != \'alias_aux\' AND expire IS NULL', | |
179 | $h_id); | |
0337d704 | 180 | |
f036c896 | 181 | $homonym = User::getSilentWithUID($h_id); |
94590511 | 182 | $mailer = new PlMailer('register/lostalias.mail.tpl'); |
f036c896 | 183 | $mailer->addTo($homonym); |
94590511 SJ |
184 | $mailer->setSubject("Perte de ton alias $emailXorg dans un mois !"); |
185 | $mailer->assign('emailXorg', $emailXorg); | |
186 | $mailer->assign('als', join(', ', $als)); | |
0337d704 | 187 | $mailer->SetTxtBody(wordwrap($msg,72)); |
188 | $mailer->send(); | |
189 | } | |
190 | ||
94590511 SJ |
191 | $subState->set('forlife', $forlife); |
192 | $subState->set('bestalias', $emailXorg2); | |
193 | $subState->set('emailXorg2', null); | |
0337d704 | 194 | } else { |
94590511 SJ |
195 | $subState->set('forlife', $forlife); |
196 | $subState->set('bestalias', $emailXorg); | |
197 | $subState->set('emailXorg2', $emailXorg2); | |
0337d704 | 198 | } |
f0a52f1b | 199 | $subState->set('main_mail_domain', User::$sub_mail_domains[$type] . Platal::globals()->mail->domain); |
0337d704 | 200 | |
201 | return true; | |
202 | } | |
203 | ||
204 | // }}} | |
94590511 | 205 | // {{{ function finishRegistration |
0337d704 | 206 | |
94590511 | 207 | function finishRegistration($subState) |
0337d704 | 208 | { |
209 | global $globals; | |
0337d704 | 210 | |
97a82cd2 | 211 | $hash = rand_url_id(12); |
b4b8ebbf JPAMAJ |
212 | XDB::execute('INSERT INTO register_pending (uid, forlife, bestalias, mailorg2, password, |
213 | email, date, relance, naissance, hash, services) | |
214 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, NOW(), 0, {?}, {?}, {?}) | |
215 | ON DUPLICATE KEY UPDATE password=VALUES(password), email=VALUES(email), | |
216 | date=VALUES(date), naissance=VALUES(naissance), | |
217 | hash=VALUES(hash), services=VALUES(services)', | |
94590511 SJ |
218 | $subState->i('uid'), $subState->s('forlife'), $subState->s('bestalias'), |
219 | $subState->s('emailXorg2'), $subState->s('password'), $subState->s('email'), | |
220 | $subState->s('birthdate'), $hash, implode(',', $subState->v('services'))); | |
221 | ||
222 | $mymail = new PlMailer('register/end.mail.tpl'); | |
223 | $mymail->assign('emailXorg', $subState->s('bestalias')); | |
4b0cf4e4 | 224 | $mymail->assign('to', $subState->s('email')); |
0337d704 | 225 | $mymail->assign('baseurl', $globals->baseurl); |
94590511 | 226 | $mymail->assign('hash', $hash); |
f036c896 | 227 | $mymail->assign('subject', ucfirst($globals->mail->domain) . ' : ' . $subState->s('bestalias')); |
0337d704 | 228 | $mymail->send(); |
229 | } | |
230 | ||
231 | // }}} | |
a7de4ef7 | 232 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
0337d704 | 233 | ?> |