X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fregister%2Fregister.inc.php;h=1ccb04176fadf37b904a78cb177b3c928a25a6bb;hb=c9566e01c2add8f12a858abe0fbb0bc6b8e3c0d4;hp=1ecc1986a4c31f1583000ed2a2f9b70f01332785;hpb=9e1816c7666767755abbc24f6a0df290efff81b6;p=platal.git
diff --git a/modules/register/register.inc.php b/modules/register/register.inc.php
index 1ecc198..1ccb041 100644
--- a/modules/register/register.inc.php
+++ b/modules/register/register.inc.php
@@ -1,6 +1,6 @@
set('xorgid', Profile::getXorgId($subState->i('schoolid')));
+ if (!$subState->v('xorgid')) {
+ return 'Le matricule est incorrect.';
}
- return $is_ok && ($maxlen > 2 || $maxlen == strlen($_nom));
-}
-
-// }}}
-// {{{ function check_mat
-
-function check_mat($promo, $mat, &$nom, &$prenom, &$ourmat, &$ourid, &$watch, &$naiss)
-{
- if (!preg_match('/^[0-9][0-9][0-9][0-9][0-9][0-9]$/', $mat)) {
- return "Le matricule doit comporter 6 chiffres.";
+ $uf = new UserFilter(new PFC_And(
+ new UFC_SchoolId('xorg', $subState->i('xorgid')),
+ new PFC_Not(new UFC_Dead()),
+ new PFC_Not(new UFC_Registered(true))
+ ));
+ $profile = $uf->getProfile();
+ if (is_null($profile)) {
+ return "Tu es déjà inscrit ou ton matricule est incorrect !";
}
- $year = intval(substr($mat, 0, 3));
- $rang = intval(substr($mat, 3, 3));
- if ($year > 200) { $year /= 10; };
- if ($year < 96) {
- return "ton matricule est incorrect";
- } else {
- $ourmat = sprintf('%04u%04u', 1900+$year, $rang);
+ if ($profile->promo() != $subState->s('promo')) {
+ return 'Le matricule est incorrect.';
}
- $res = XDB::query(
- 'SELECT user_id, promo, perms IN ("admin","user"), nom, prenom, FIND_IN_SET(\'watch\', flags), naissance_ini
- FROM auth_user_md5
- WHERE matricule={?} and deces = 0', $ourmat);
- list ($uid, $_promo, $_already, $_nom, $_prenom, $watch, $naiss) = $res->fetchOneRow();
- if ($_already) { return "tu es déjà inscrit ou ton matricule est incorrect !"; }
- if ($_promo != $promo) { return "erreur de matricule"; }
-
- if (!user_cmp($prenom, $nom, $_prenom, $_nom)) {
- return "erreur dans l'identification. Réessaie, il y a une erreur quelque part !";
+ if (!$profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) {
+ return "Erreur dans l'identification. Réessaie, il y a une erreur quelque part !";
}
- $nom = $_nom;
- $prenom = $_prenom;
- $ourid = $uid;
+ $subState->set('lastname', $profile->lastName());
+ $subState->set('firstname', $profile->firstName());
+ $subState->set('uid', $profile->owner()->id());
+ $subState->set('watch', $profile->owner()->watch);
+ $subState->set('comment', $profile->owner()->comment);
+ $subState->set('birthdateRef', $profile->__get('birthdate_ref'));
return true;
}
// }}}
-// {{{ function check_old_mat
+// {{{ function weakCheckId
-function check_old_mat($promo, $mat, &$nom, &$prenom, &$ourmat, &$ourid, &$watch, &$naiss)
+function weakCheckId($subState)
{
- $res = XDB::iterRow(
- 'SELECT user_id, nom, prenom, matricule, FIND_IN_SET(\'watch\', flags), naissance_ini
- FROM auth_user_md5
- WHERE promo={?} AND deces=0 AND perms="pending"', $promo);
- while (list($_uid, $_nom, $_prenom, $_mat, $watch, $naiss) = $res->next()) {
- if (user_cmp($prenom, $nom, $_prenom, $_nom)) {
- $nom = $_nom;
- $prenom = $_prenom;
- $ourid = $_uid;
- $ourmat = $_mat;
- return true;
+ $uf = new UserFilter(new PFC_And(
+ new PFC_Not(new UFC_Dead()),
+ new UFC_Promo('=', $subState->s('edu_type'), $subState->s('yearpromo')),
+ new PFC_Not(new UFC_Registered(true))
+ ));
+ if ($it = $uf->iterProfiles()) {
+ while ($profile = $it->next()) {
+ if ($profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) {
+ $subState->set('lastname', $profile->lastName());
+ $subState->set('firstname', $profile->firstName());
+ $subState->set('uid', $profile->owner()->id());
+ $subState->set('watch', $profile->owner()->watch);
+ $subState->set('comment', $profile->owner()->comment);
+ $subState->set('birthdateRef', $profile->__get('birthdate_ref'));
+ $subState->set('xorgid', $profile->__get('xorg_id'));
+ return true;
+ }
}
}
- $res = XDB::iterRow(
- 'SELECT user_id, nom, prenom, matricule, alias, FIND_IN_SET(\'watch\', u.flags), naissance_ini
- FROM auth_user_md5 AS u
- INNER JOIN aliases AS a ON (u.user_id = a.id and FIND_IN_SET("bestalias", a.flags))
- WHERE promo={?} AND deces=0 AND perms IN ("user","admin")', $promo);
- while (list($_uid, $_nom, $_prenom, $_mat, $alias, $watch, $naiss) = $res->next()) {
- if (user_cmp($prenom, $nom, $_prenom, $_nom)) {
- $ourid = $_uid;
- $ourmat = $_mat;
- return "Tu es vraisemblablement déjà inscrit !";
+ $uf = new UserFilter(new PFC_And(
+ new PFC_Not(new UFC_Dead()),
+ new UFC_Promo('=', $subState->s('edu_type'), $subState->s('yearpromo')),
+ new UFC_Registered(true)
+ ));
+ if ($it = $uf->iterProfiles()) {
+ while ($profile = $it->next()) {
+ if ($profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) {
+ $subState->set('uid', $profile->owner()->id());
+ $subState->set('watch', $profile->owner()->watch);
+ $subState->set('comment', $profile->owner()->comment);
+ $subState->set('birthdateRef', $profile->__get('birthdate_ref'));
+ $subState->set('xorgid', $profile->__get('xorg_id'));
+ return 'Tu es vraisemblablement déjà inscrit !';
+ }
}
}
- return "erreur: vérifie que tu as bien orthographié ton nom !";
+ return 'Erreur : vérifie que tu as bien orthographié ton nom !';
}
// }}}
-// {{{ function check_new_user
+// {{{ function checkNewUser
-function check_new_user(&$sub)
+function checkNewUser($subState)
{
- extract($sub);
-
- $prenom = preg_replace("/[ \t]+/", ' ', trim($prenom));
- $prenom = preg_replace("/--+/", '-', $prenom);
- $prenom = preg_replace("/''+/", '\'', $prenom);
- $prenom = make_firstname_case($prenom);
-
- $nom = preg_replace("/[ \t]+/", ' ', trim($nom));
- $nom = preg_replace("/--+/", '-', $nom);
- $nom = preg_replace("/''+/", '\'', $nom);
- $nom = mb_strtoupper($nom);
-
- if ($promo >= 1996) {
- $res = check_mat($promo, $mat, $nom, $prenom, $ourmat, $ourid, $watch, $naiss);
+ $firstname = preg_replace("/[ \t]+/", ' ', $subState->t('firstname'));
+ $firstname = preg_replace("/--+/", '-', $firstname);
+ $firstname = preg_replace("/''+/", '\'', $firstname);
+ $subState->set('firstname', PlUser::fixFirstnameCase($firstname));
+
+ $lastname = preg_replace("/[ \t]+/", ' ', $subState->t('lastname'));
+ $lastname = preg_replace("/--+/", '-', $lastname);
+ $lastname = preg_replace("/''+/", '\'', $lastname);
+ $subState->set('lastname', mb_strtoupper($lastname));
+
+ if ($subState->v('edu_type') == Profile::DEGREE_X && $subState->i('yearpromo') >= 1996) {
+ $res = strongCheckId($subState);
} else {
- $res = check_old_mat($promo, $mat, $nom, $prenom, $ourmat, $ourid, $watch, $naiss);
+ $res = weakCheckId($subState);
+ }
+ if ($res !== true) {
+ return $res;
}
- if ($res !== true) { return $res; }
-
- $sub['nom'] = $nom;
- $sub['prenom'] = $prenom;
- $sub['ourmat'] = $ourmat;
- $sub['uid'] = $ourid;
- $sub['watch'] = $watch;
- $sub['naissance_ini'] = $naiss;
return true;
}
// }}}
-// {{{ function create_aliases
+// {{{ function createAliases
-function create_aliases (&$sub)
+function createAliases($subState)
{
global $globals;
- extract ($sub);
-
- $mailorg = make_username($prenom, $nom);
- $mailorg2 = $mailorg.sprintf(".%02u", ($promo%100));
- $res = XDB::query("SELECT hruid FROM auth_user_md5 WHERE user_id = {?} AND hruid != ''", $uid);
+ $res = XDB::query("SELECT hruid, state, type
+ FROM accounts
+ WHERE uid = {?} AND hruid != ''",
+ $subState->i('uid'));
if ($res->numRows() == 0) {
return "Tu n'as pas d'adresse à vie pré-attribuée.
"
- . "Envoie un mail à mail->domain}\">"
+ . "Envoie un mail à mail->domain}\">"
. "support@{$globals->mail->domain} en expliquant ta situation.";
} else {
- // TODO: at the moment forlife == hruid, however we'll have to change
- // that behaviour when masters will be on plat/al.
- $forlife = $res->fetchOneCell();
+ list($forlife, $state, $type) = $res->fetchOneRow();
}
+ if ($state == 'active') {
+ return "Tu es déjà inscrit, si tu ne te souviens plus de ton mot de passe d'accès au site, "
+ . "tu peux suivre la procédure de récupération de mot de passe.";
+ } else if ($state == 'disabled') {
+ return "Ton compte a été désactivé par les administrateurs du site suite à des abus. "
+ . "Pour plus d'information ou pour demander la réactivation du compte, tu peux t'adresser à "
+ . "mail->domain}\">support@{$globals->mail->domain}.";
+ }
+
- $res = XDB::query('SELECT id, type, expire FROM aliases WHERE alias={?}', $mailorg);
+ $emailXorg = PlUser::makeUserName($subState->t('firstname'), $subState->t('lastname'));
+ $suffix = (User::$sub_mail_domains[$type] ? substr(User::$sub_mail_domains[$type], 0, 1) : '') . substr($subState->v('yearpromo'), -2);
+ $emailXorg2 = $emailXorg . '.' . $suffix;
+ $res = XDB::query('SELECT uid, expire
+ FROM email_source_account
+ WHERE email = {?} AND type != \'alias_aux\'',
+ $emailXorg);
if ($res->numRows()) {
- list($h_id, $h_type, $expire) = $res->fetchOneRow();
- if ($h_type != 'homonyme' and empty($expire)) {
- XDB::execute('UPDATE aliases SET expire=ADDDATE(NOW(),INTERVAL 1 MONTH) WHERE alias={?}', $mailorg);
- XDB::execute('REPLACE INTO homonymes (homonyme_id,user_id) VALUES ({?},{?})', $h_id, $h_id);
- XDB::execute('REPLACE INTO homonymes (homonyme_id,user_id) VALUES ({?},{?})', $h_id, $uid);
- $res = XDB::query("SELECT alias FROM aliases WHERE id={?} AND expire IS NULL", $h_id);
- $als = $res->fetchColumn();
-
- $mailer = new PlMailer();
- $mailer->setFrom('"Support Polytechnique.org" mail->domain . '>');
- $mailer->addTo("$mailorg@" . $globals->mail->domain);
- $mailer->setSubject("perte de ton alias $mailorg dans un mois !");
- $mailer->addCc('"Support Polytechnique.org" mail->domain . '>');
- $msg =
- "Bonjour,\n\n".
-
- "Un homonyme vient de s'inscrire. La politique de Polytechnique.org est de fournir des\n".
- "adresses email devinables, nous ne pouvons donc pas conserver ton alias '$mailorg' qui\n".
- "correspond maintenant à deux personnes.\n\n".
-
- "Tu gardes tout de même l'usage de cet alias pour un mois encore à compter de ce jour.\n\n".
-
- "Lorsque cet alias sera désactivé, l'adresse $mailorg@polytechnique.org renverra vers un \n".
- "robot qui indiquera qu'il y a plusieurs personnes portant le même nom ;\n".
- "cela évite que l'un des homonymes reçoive des courriels destinés à l'autre.\n\n".
-
- "Pour te connecter au site, tu pourras utiliser comme identifiant n'importe lequel de tes\n".
- "autres alias :\n".
- " ".join(', ', $als)."\n";
- "Commence dès aujourd'hui à communiquer à tes correspondants la nouvelle adresse que tu comptes utiliser !\n\n".
-
- "En nous excusant pour le désagrément occasionné,\n".
- "Cordialement,\n\n".
-
- "-- \n".
- "L'équipe de Polytechnique.org\n".
- "\"Le portail des élèves & anciens élèves de l'X\"";
+ list($h_id, $expire) = $res->fetchOneRow();
+ if (empty($expire)) {
+ XDB::execute('UPDATE email_source_account
+ SET expire = ADDDATE(NOW(), INTERVAL 1 MONTH)
+ WHERE email = {?} AND type != \'alias_aux\'',
+ $emailXorg);
+ $hrmid = User::makeHomonymHrmid($emailXorg);
+ XDB::execute('INSERT IGNORE INTO homonyms_list (hrmid, uid)
+ VALUES ({?}, {?}), ({?}, {?})',
+ $hrmid, $h_id, $hrmid, $subState->i('uid'));
+ $als = XDB::fetchColumn('SELECT email
+ FROM email_source_account
+ WHERE uid = {?} AND type != \'alias_aux\' AND expire IS NULL',
+ $h_id);
+
+ $homonym = User::getSilentWithUID($h_id);
+ $mailer = new PlMailer('register/lostalias.mail.tpl');
+ $mailer->addTo($homonym);
+ $mailer->setSubject("Perte de ton alias $emailXorg dans un mois !");
+ $mailer->assign('emailXorg', $emailXorg);
+ $mailer->assign('als', join(', ', $als));
$mailer->SetTxtBody(wordwrap($msg,72));
$mailer->send();
}
- $sub['forlife'] = $forlife;
- $sub['bestalias'] = $mailorg2;
- $sub['mailorg2'] = null;
+ $subState->set('forlife', $forlife);
+ $subState->set('bestalias', $emailXorg2);
+ $subState->set('emailXorg2', null);
} else {
- $sub['forlife'] = $forlife;
- $sub['bestalias'] = $mailorg;
- $sub['mailorg2'] = $mailorg2;
+ $subState->set('forlife', $forlife);
+ $subState->set('bestalias', $emailXorg);
+ $subState->set('emailXorg2', $emailXorg2);
}
+ $subState->set('main_mail_domain', User::$sub_mail_domains[$type] . Platal::globals()->mail->domain);
return true;
}
// }}}
-// {{{ function finish_ins
+// {{{ function finishRegistration
-function finish_ins($sub_state)
+function finishRegistration($subState)
{
global $globals;
- extract($sub_state);
- require_once('secure_hash.inc.php');
$hash = rand_url_id(12);
- XDB::execute(
- "UPDATE auth_user_md5
- SET last_known_email = {?}
- WHERE matricule = {?}", $email, $mat);
- XDB::execute(
- "REPLACE INTO register_pending (uid, forlife, bestalias, mailorg2, password, email, date, relance, naissance, hash, services)
- VALUES ({?}, {?}, {?}, {?}, {?}, {?}, NOW(), 0, {?}, {?}, {?})",
- $uid, $forlife, $bestalias, $mailorg2, $password, $email, $naissance, $hash, implode(',', $services));
-
- $mymail = new PlMailer('register/inscrire.mail.tpl');
- $mymail->assign('mailorg', $bestalias);
- $mymail->assign('lemail', $email);
+ XDB::execute('INSERT INTO register_pending (uid, forlife, bestalias, mailorg2, password,
+ email, date, relance, naissance, hash, services)
+ VALUES ({?}, {?}, {?}, {?}, {?}, {?}, NOW(), 0, {?}, {?}, {?})
+ ON DUPLICATE KEY UPDATE password=VALUES(password), email=VALUES(email),
+ date=VALUES(date), naissance=VALUES(naissance),
+ hash=VALUES(hash), services=VALUES(services)',
+ $subState->i('uid'), $subState->s('forlife'), $subState->s('bestalias'),
+ $subState->s('emailXorg2'), $subState->s('password'), $subState->s('email'),
+ $subState->s('birthdate'), $hash, implode(',', $subState->v('services')));
+
+ $mymail = new PlMailer('register/end.mail.tpl');
+ $mymail->assign('emailXorg', $subState->s('bestalias'));
+ $mymail->assign('to', $subState->s('email'));
$mymail->assign('baseurl', $globals->baseurl);
- $mymail->assign('hash', $hash);
- $mymail->assign('subj', $bestalias."@" . $globals->mail->domain);
+ $mymail->assign('hash', $hash);
+ $mymail->assign('subject', ucfirst($globals->mail->domain) . ' : ' . $subState->s('bestalias'));
$mymail->send();
}