0337d704 |
1 | <?php |
2 | /*************************************************************************** |
50a40a33 |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
0337d704 |
4 | * http://opensource.polytechnique.org/ * |
5 | * * |
6 | * This program is free software; you can redistribute it and/or modify * |
7 | * it under the terms of the GNU General Public License as published by * |
8 | * the Free Software Foundation; either version 2 of the License, or * |
9 | * (at your option) any later version. * |
10 | * * |
11 | * This program is distributed in the hope that it will be useful, * |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
14 | * GNU General Public License for more details. * |
15 | * * |
16 | * You should have received a copy of the GNU General Public License * |
17 | * along with this program; if not, write to the Free Software * |
18 | * Foundation, Inc., * |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
20 | ***************************************************************************/ |
21 | |
22 | require_once('xorg.inc.php'); |
23 | new_skinned_page('recovery.tpl', AUTH_PUBLIC); |
24 | |
25 | if (Env::has('login') and Env::has('birth')) { |
26 | if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::get('birth'))) { |
27 | $page->trig_run('Date de naissance incorrecte ou incohérente'); |
28 | } |
29 | $birth = sprintf('%s-%s-%s', substr(Env::get('birth'),4,4), substr(Env::get('birth'),2,2), substr(Env::get('birth'),0,2)); |
30 | |
31 | $mailorg = strtok(Env::get('login'), '@'); |
32 | |
33 | // paragraphe rajouté : si la date de naissance dans la base n'existe pas, on l'update |
34 | // avec celle fournie ici en espérant que c'est la bonne |
35 | |
36 | $res = $globals->xdb->query( |
37 | "SELECT user_id, naissance |
38 | FROM auth_user_md5 AS u |
39 | INNER JOIN aliases AS a ON (u.user_id=a.id AND type!='homonyme') |
40 | WHERE a.alias={?} AND u.perms IN ('admin','user') AND u.deces=0", $mailorg); |
41 | list($uid, $naissance) = $res->fetchOneRow(); |
42 | |
43 | if ($naissance == $birth) { |
44 | $page->assign('ok', true); |
45 | |
46 | $url = rand_url_id(); |
47 | $globals->xdb->execute('INSERT INTO perte_pass (certificat,uid,created) VALUES ({?},{?},NOW())', $url, $uid); |
48 | $res = $globals->xdb->query('SELECT email FROM emails WHERE uid = {?} AND NOT FIND_IN_SET("filter", flags)', $uid); |
49 | $mails = implode(', ', $res->fetchColumn()); |
50 | |
51 | require_once("diogenes/diogenes.hermes.inc.php"); |
52 | $mymail = new HermesMailer(); |
53 | $mymail->setFrom('"Gestion des mots de passe" <support+password@polytechnique.org>'); |
54 | $mymail->addTo($mails); |
55 | $mymail->setSubject('Ton certificat d\'authentification'); |
56 | $mymail->setTxtBody("Visite la page suivante qui expire dans six heures : |
57 | {$globals->baseurl}/tmpPWD.php?certificat=$url |
58 | |
59 | Si en cliquant dessus tu n'y arrives pas, copie intégralement l'adresse dans la barre de ton navigateur. |
60 | |
61 | -- |
62 | Polytechnique.org |
63 | \"Le portail des élèves & anciens élèves de l'Ecole polytechnique\"".(Post::get('email') ? " |
64 | |
65 | Adresse de secours : \n ".Post::get('email') : "")." |
66 | |
67 | Mail envoyé à ".Env::get('login')); |
68 | $mymail->send(); |
69 | |
70 | // on cree un objet logger et on log l'evenement |
71 | $logger = $_SESSION['log'] = new DiogenesCoreLogger($uid); |
72 | $logger->log('recovery', $emails); |
73 | } else { |
74 | $page->trig('Pas de résultat correspondant aux champs entrés dans notre base de données.'); |
75 | } |
76 | } |
77 | |
78 | $page->run(); |
79 | ?> |