X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fregister%2Fregister.inc.php;h=bd6f8601306245d0855a4d779617e982ad407651;hb=4371e993d51f10d655c4b453563c730b613b490e;hp=4506edd2ea9169d448bcebe36291049bb4f5bb91;hpb=684195f33b11e3067200dd3a9e14304bd7d04463;p=platal.git diff --git a/modules/register/register.inc.php b/modules/register/register.inc.php index 4506edd..bd6f860 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')) { @@ -29,34 +29,35 @@ function checkId(&$subState) } $uf = new UserFilter(new PFC_And( - new UFC_UID($subState->i('xorg_id')), - new PFC_Not(new UFC_Dead()) + new UFC_SchoolId('xorg', $subState->i('xorgid')), + new PFC_Not(new UFC_Dead()), + new PFC_Not(new UFC_Registered(true)) )); - $user = $uf->getProfiles(); - - if ($user->__get('state') == 'active') { + $profile = $uf->getProfile(); + if (is_null($profile)) { return "Tu es déjà inscrit ou ton matricule est incorrect !"; } - if ($user->promo() != $subState->s('promo')) { + + if ($profile->promo() != $subState->s('promo')) { return 'Le matricule est incorrect.'; } - if (!$user->compareNames($subState->s('firstname'), $subState->s('lastname'))) { + if (!$profile->compareNames($subState->s('firstname'), $subState->s('lastname'))) { return "Erreur dans l'identification. Réessaie, il y a une erreur quelque part !"; } - $subState->set('lastname', $user->lastName()); - $subState->set('firstname', $user->firstName()); - $subState->set('uid', $user->id()); - $subState->set('watch', $user->watch()); - $subState->set('birthdateRef', $user->profile->__get('birthdate_ref')); + $subState->set('lastname', $profile->lastName()); + $subState->set('firstname', $profile->firstName()); + $subState->set('uid', $profile->owner()->id()); + $subState->set('watch', $profile->owner()->watch); + $subState->set('birthdateRef', $profile->__get('birthdate_ref')); return true; } // }}} // {{{ function checkOldId -function checkOldId(&$subState) +function checkOldId($subState) { $uf = new UserFilter(new PFC_And( new PFC_Not(new UFC_Dead()), @@ -69,7 +70,7 @@ function checkOldId(&$subState) $subState->set('lastname', $profile->lastName()); $subState->set('firstname', $profile->firstName()); $subState->set('uid', $profile->owner()->id()); - $subState->set('watch', $profile->owner()->watch()); + $subState->set('watch', $profile->owner()->watch); $subState->set('birthdateRef', $profile->__get('birthdate_ref')); $subState->set('xorgid', $profile->__get('xorg_id')); return true; @@ -85,7 +86,7 @@ function checkOldId(&$subState) 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('watch', $profile->owner()->watch); $subState->set('birthdateRef', $profile->__get('birthdate_ref')); $subState->set('xorgid', $profile->__get('xorg_id')); return 'Tu es vraisemblablement déjà inscrit !'; @@ -97,7 +98,7 @@ function checkOldId(&$subState) // }}} // {{{ function checkNewUser -function checkNewUser(&$subState) +function checkNewUser($subState) { $firstname = preg_replace("/[ \t]+/", ' ', $subState->t('firstname')); $firstname = preg_replace("/--+/", '-', $firstname); @@ -124,41 +125,55 @@ function checkNewUser(&$subState) // }}} // {{{ function createAliases -function createAliases(&$subState) +function createAliases($subState) { global $globals; $emailXorg = PlUser::makeUserName($subState->t('firstname'), $subState->t('lastname')); $emailXorg2 = $emailXorg . sprintf(".%02u", ($subState->i('yearpromo') % 100)); - $res = XDB::query("SELECT hruid + $res = XDB::query("SELECT hruid, state FROM accounts - WHERE uid = {?} AND hruid != ''", $subState->i('uid')); + 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 { - $forlife = $res->fetchOneCell(); + list($forlife, $state) = $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 uid, type, expire - FROM aliases - WHERE alias = {?}', $emailXorg); - if ($res->numRows()) { + $count = XDB::numRows('SELECT * + FROM email_source_account AS s + INNER JOIN email_virtual_domains AS d ON (s.domain = d.id) + WHERE s.email = {?} AND d.name = {?}', + $emailXorg, $globals->mail->domain); + if ($count) { 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 = {?}', $emailXorg); - XDB::execute('REPLACE INTO homonyms (homonyme_id, uid) - VALUES ({?}, {?})', $h_id, $h_id); - XDB::execute('REPLACE INTO homonyms (homonyme_id, uid) - VALUES ({?}, {?})', $h_id, $uid); - $res = XDB::query('SELECT alias - FROM aliases - WHERE uid = {?} AND expire IS NULL', $h_id); - $als = $res->fetchColumn(); + XDB::execute('UPDATE email_source_account AS e + INNER JOIN email_virtual_domains AS d ON (e.domain = d.id) + SET e.expire = ADDDATE(NOW(), INTERVAL 1 MONTH) + WHERE e.email = {?} AND d.name = {?}', + $emailXorg, $globals->mail->domain); + $hrmid = 'h.' . $emailXorg . '.' . $globals->mail->domain; + XDB::execute('INSERT IGNORE INTO homonyms_list (hrmid, uid) + VALUES ({?}, {?}), ({?}, {?})', + $hrmid, $h_id, $hrmid, $subState->i('uid')); + $als = XDB::fetchColumn('SELECT * + FROM email_source_account AS s + INNER JOIN email_virtual_domains AS d ON (s.domain = d.id) + WHERE s.uid = {?} AND d.name = {?} AND s.expire IS NULL', + $h_id, $globals->mail->domain); $mailer = new PlMailer('register/lostalias.mail.tpl'); $mailer->addTo($emailXorg . '@' . $globals->mail->domain); @@ -189,19 +204,22 @@ function finishRegistration($subState) global $globals; $hash = rand_url_id(12); - XDB::execute('REPLACE INTO register_pending (uid, forlife, bestalias, mailorg2, password, - email, date, relance, naissance, hash, services) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, NOW(), 0, {?}, {?}, {?})', + 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('lemail', $subState->s('email')); + $mymail->assign('to', $subState->s('email')); $mymail->assign('baseurl', $globals->baseurl); $mymail->assign('hash', $hash); - $mymail->assign('subj', $subState->s('bestalias') . '@' . $globals->mail->domain); + $mymail->assign('subject', $subState->s('bestalias') . '@' . $globals->mail->domain); $mymail->send(); }