X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fregister%2Fregister.inc.php;h=993ead3446eca8923e21e00384c730c8a582ee26;hb=73317355964c4cd538157f8b281a1384b7e38e4d;hp=47e59d2589494ed39958cc85f2982adf55337d1a;hpb=45ea6160465aeba0aa780e49c12272819dedffd1;p=platal.git diff --git a/modules/register/register.inc.php b/modules/register/register.inc.php index 47e59d2..993ead3 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')) { @@ -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,14 +115,10 @@ function checkNewUser($subState) $lastname = preg_replace("/''+/", '\'', $lastname); $subState->set('lastname', mb_strtoupper($lastname)); - if ($subState->i('yearpromo') >= 1996 && $subState->v('edu_type') == 'X') { - $res = checkId($subState); + if ($subState->v('edu_type') == Profile::DEGREE_X && $subState->i('yearpromo') >= 1996) { + $res = strongCheckId($subState); } else { - $res = checkOldId($subState); - } - if ($subState->v('edu_type') != 'X' && - $subState->v('xorgid') != $subState->v('schoolid')) { - return 'Le matricule est incorrect.'; + $res = weakCheckId($subState); } if ($res !== true) { return $res; @@ -133,9 +134,6 @@ 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, type FROM accounts WHERE uid = {?} AND hruid != ''", @@ -156,34 +154,53 @@ function createAliases($subState) . "mail->domain}\">support@{$globals->mail->domain}."; } + + $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; + // Search for homonyms: + // * first case: only one homonym already registered. $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\'', + // * second case: at least two homonyms registerd. + $result = XDB::query("SELECT hrmid + FROM email_source_other + WHERE type = 'homonym' AND email = {?}", $emailXorg); - $hrmid = User::makeHomonymHrmid($emailXorg); + if ($res->numRows() || $result->numRows()) { + 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 = 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(); + } + } else { + $hrmid = $result->fetchOneCell(); 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(); + VALUES ({?}, {?})', + $hrmid, $subState->i('uid')); + // TODO: insert into source_other if new domain } $subState->set('forlife', $forlife); @@ -227,5 +244,5 @@ function finishRegistration($subState) } // }}} -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>