X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fregister%2Fregister.inc.php;h=1ccb04176fadf37b904a78cb177b3c928a25a6bb;hb=71ebd57d64102a39896d47873514a42a26c7201e;hp=7a8b21ff14f1759eb259c114091b95cf35bf78e2;hpb=f036c8966e64d9f2bb3923bbeb278353bc7e1083;p=platal.git diff --git a/modules/register/register.inc.php b/modules/register/register.inc.php index 7a8b21f..1ccb041 100644 --- a/modules/register/register.inc.php +++ b/modules/register/register.inc.php @@ -19,9 +19,9 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ -// {{{ function checkId +// {{{ function strongCheckId -function checkId($subState) +function strongCheckId($subState) { $subState->set('xorgid', Profile::getXorgId($subState->i('schoolid'))); if (!$subState->v('xorgid')) { @@ -50,46 +50,51 @@ function checkId($subState) $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 checkOldId +// {{{ function weakCheckId -function checkOldId($subState) +function weakCheckId($subState) { $uf = new UserFilter(new PFC_And( new PFC_Not(new UFC_Dead()), - new UFC_Promo('=', UserFilter::DISPLAY, $subState->s('promo')), + new UFC_Promo('=', $subState->s('edu_type'), $subState->s('yearpromo')), new PFC_Not(new UFC_Registered(true)) )); - $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('birthdateRef', $profile->__get('birthdate_ref')); - $subState->set('xorgid', $profile->__get('xorg_id')); - return 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; + } } } $uf = new UserFilter(new PFC_And( new PFC_Not(new UFC_Dead()), - new UFC_Promo('=', UserFilter::DISPLAY, $subState->s('promo')), + new UFC_Promo('=', $subState->s('edu_type'), $subState->s('yearpromo')), new UFC_Registered(true) )); - $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('birthdateRef', $profile->__get('birthdate_ref')); - $subState->set('xorgid', $profile->__get('xorg_id')); - return 'Tu es vraisemblablement déjà inscrit !'; + 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 !'; @@ -110,10 +115,10 @@ function checkNewUser($subState) $lastname = preg_replace("/''+/", '\'', $lastname); $subState->set('lastname', mb_strtoupper($lastname)); - if ($subState->i('yearpromo') >= 1996) { - $res = checkId($subState); + if ($subState->v('edu_type') == Profile::DEGREE_X && $subState->i('yearpromo') >= 1996) { + $res = strongCheckId($subState); } else { - $res = checkOldId($subState); + $res = weakCheckId($subState); } if ($res !== true) { return $res; @@ -129,10 +134,7 @@ 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, state + $res = XDB::query("SELECT hruid, state, type FROM accounts WHERE uid = {?} AND hruid != ''", $subState->i('uid')); @@ -141,7 +143,7 @@ function createAliases($subState) . "Envoie un mail à mail->domain}\">" . "support@{$globals->mail->domain} en expliquant ta situation."; } else { - list($forlife, $state) = $res->fetchOneRow(); + 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, " @@ -152,18 +154,22 @@ function createAliases($subState) . "mail->domain}\">support@{$globals->mail->domain}."; } - $count = XDB::numRows('SELECT uid, expire - FROM email_source_account - WHERE email = {?} AND type != \'alias_aux\'', - $emailXorg); - if ($count) { + + $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, $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 = 'h.' . $emailXorg . '.' . $globals->mail->domain; + $hrmid = User::makeHomonymHrmid($emailXorg); XDB::execute('INSERT IGNORE INTO homonyms_list (hrmid, uid) VALUES ({?}, {?}), ({?}, {?})', $hrmid, $h_id, $hrmid, $subState->i('uid')); @@ -190,6 +196,7 @@ function createAliases($subState) $subState->set('bestalias', $emailXorg); $subState->set('emailXorg2', $emailXorg2); } + $subState->set('main_mail_domain', User::$sub_mail_domains[$type] . Platal::globals()->mail->domain); return true; }