+ $page->changeTpl('platal/recovery.tpl');
+
+ if (!Env::has('login') || !Env::has('birth')) {
+ return;
+ }
+
+ if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::v('birth'))) {
+ $page->trig('Date de naissance incorrecte ou incohérente');
+ return;
+ }
+
+ $birth = sprintf('%s-%s-%s',
+ substr(Env::v('birth'), 4, 4),
+ substr(Env::v('birth'), 2, 2),
+ substr(Env::v('birth'), 0, 2));
+
+ $mailorg = strtok(Env::v('login'), '@');
+
+ // paragraphe rajouté : si la date de naissance dans la base n'existe pas, on l'update
+ // avec celle fournie ici en espérant que c'est la bonne
+
+ $res = XDB::query(
+ "SELECT user_id, naissance
+ FROM auth_user_md5 AS u
+ INNER JOIN aliases AS a ON (u.user_id=a.id AND type != 'homonyme')
+ WHERE a.alias={?} AND u.perms IN ('admin','user') AND u.deces=0", $mailorg);
+ list($uid, $naissance) = $res->fetchOneRow();
+
+ if ($naissance == $birth) {
+ $res = XDB::query("SELECT COUNT(*)
+ FROM emails
+ WHERE uid = {?} AND flags != 'panne' AND flags != 'filter'", $uid);
+ $count = intval($res->fetchOneCell());
+ if ($count == 0) {
+ $page->assign('no_addr', true);
+ return;
+ }
+
+ $page->assign('ok', true);
+
+ $url = rand_url_id();
+ XDB::execute('INSERT INTO perte_pass (certificat,uid,created)
+ VALUES ({?},{?},NOW())', $url, $uid);
+ $res = XDB::query('SELECT email
+ FROM emails
+ WHERE uid = {?} AND email = {?}',
+ $uid, Post::v('email'));
+ if ($res->numRows()) {
+ $mails = $res->fetchOneCell();
+ } else {
+ $res = XDB::query('SELECT email
+ FROM emails
+ WHERE uid = {?} AND NOT FIND_IN_SET("filter", flags)', $uid);
+ $mails = implode(', ', $res->fetchColumn());
+ }
+ $mymail = new PlMailer();
+ $mymail->setFrom('"Gestion des mots de passe" <support+password@' . $globals->mail->domain . '>');
+ $mymail->addTo($mails);
+ $mymail->setSubject('Ton certificat d\'authentification');
+ $mymail->setTxtBody("Visite la page suivante qui expire dans six heures :
+{$globals->baseurl}/tmpPWD/$url
+
+Si en cliquant dessus tu n'y arrives pas, copie intégralement l'adresse dans la barre de ton navigateur. Si tu n'as pas utilisé ce lien dans six heures, tu peux tout simplement recommencer cette procédure.
+
+--
+Polytechnique.org
+\"Le portail des élèves & anciens élèves de l'Ecole polytechnique\"
+
+Mail envoyé à ".Env::v('login') . (Post::has('email') ? "
+Adresse de secours : " . Post::v('email') : ""));
+ $mymail->send();
+
+ // on cree un objet logger et on log l'evenement
+ $logger = $_SESSION['log'] = new CoreLogger($uid);
+ $logger->log('recovery', $mails);
+ } else {
+ $page->trig('Les informations que tu as rentrées ne permettent pas de récupérer ton mot de passe.<br />'.
+ 'Si tu as un homonyme, utilise prenom.nom.promo comme login');