Commit | Line | Data |
---|---|---|
bc6e8005 SJ |
1 | <?php |
2 | /*************************************************************************** | |
3 | * Copyright (C) 2003-2011 Polytechnique.org * | |
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 | ||
23 | class AccountReq extends Validate | |
24 | { | |
25 | // {{{ properties | |
26 | ||
27 | public $uid; | |
28 | public $hruid; | |
29 | public $email; | |
30 | public $group; | |
3d57237e | 31 | public $groups; |
bc6e8005 SJ |
32 | |
33 | public $rules = "Accepter si l'adresse email parait correcte, et pas absurde | |
34 | (ou si le demandeur est de confiance). Si le demandeur marque sa propre | |
35 | adresse email, refuser dans tous les cas. Sauf abus flagrant, il n'y a | |
36 | pas de raison de refuser des marketing perso répétés."; | |
37 | // }}} | |
38 | // {{{ constructor | |
39 | ||
40 | public function __construct(User $user, $hruid, $email, $group) | |
41 | { | |
42 | parent::__construct($user, false, 'account'); | |
43 | $this->hruid = $hruid; | |
44 | $this->email = $email; | |
45 | $this->group = $group; | |
46 | $this->uid = XDB::fetchOneCell('SELECT uid | |
47 | FROM accounts | |
48 | WHERE hruid = {?}', | |
49 | $hruid); | |
3d57237e SJ |
50 | $this->groups = implode(',', XDB::fetchColumn('SELECT g.nom |
51 | FROM groups AS g | |
52 | INNER JOIN group_members AS m ON (g.id = m.asso_id) | |
53 | WHERE m.uid = {?} | |
54 | ORDER BY g.nom', | |
55 | $this->uid)); | |
bc6e8005 SJ |
56 | } |
57 | ||
58 | // }}} | |
59 | // {{{ function formu() | |
60 | ||
61 | public function formu() | |
62 | { | |
63 | return 'include/form.valid.account.tpl'; | |
64 | } | |
65 | ||
66 | // }}} | |
67 | // {{{ function _mail_subj | |
68 | ||
69 | protected function _mail_subj() | |
70 | { | |
71 | return "[Polytechnique.org] Création d'un compte Polytechnique.net"; | |
72 | } | |
73 | ||
74 | // }}} | |
75 | // {{{ function _mail_body | |
76 | ||
77 | protected function _mail_body($isok) | |
78 | { | |
79 | if ($isok) { | |
80 | return " Un email vient d'être envoyé à {$this->email} pour qu'il puisse activer son compte sur Polytechnique.net."; | |
81 | } else { | |
82 | return " Nous n'avons pas jugé bon d'envoyer d'email à {$this->email} pour qu'il puisse activer son compte sur Polytechnique.net."; | |
83 | } | |
84 | } | |
85 | ||
86 | // }}} | |
87 | // {{{ function commit() | |
88 | ||
89 | public function commit() | |
90 | { | |
91 | $hash = rand_url_id(12); | |
4df10c3b SJ |
92 | XDB::execute('UPDATE accounts |
93 | SET state = \'pending\' | |
94 | WHERE uid = {?}', | |
95 | $this->uid); | |
bc6e8005 SJ |
96 | XDB::execute('INSERT INTO register_pending_xnet (uid, hruid, email, date, hash) |
97 | VALUES ({?}, {?}, {?}, NOW(), {?})', | |
98 | $this->uid, $this->hruid, $this->email, $hash); | |
99 | ||
100 | $mailer = new PlMailer('xnet/account.mail.tpl'); | |
101 | $mailer->addTo($this->email); | |
102 | $mailer->assign('hash', $hash); | |
103 | $mailer->assign('hruid', $this->hruid); | |
104 | $mailer->assign('group', $this->group); | |
105 | $mailer->assign('user', $this->user); | |
106 | $mailer->send(); | |
107 | ||
108 | return true; | |
109 | } | |
110 | ||
111 | // }}} | |
112 | // {{{ function isPending() | |
113 | ||
114 | static public function isPending($uid) | |
115 | { | |
116 | $res = XDB::iterRow('SELECT data | |
117 | FROM requests | |
118 | WHERE type = \'account\' | |
119 | ORDER BY stamp'); | |
120 | ||
121 | $is_pending = false; | |
122 | while (list($data) = $res->next()) { | |
123 | $request = Validate::unserialize($data); | |
124 | $is_pending = ($is_pending || ($request->uid == $uid)); | |
125 | } | |
126 | return $is_pending; | |
127 | } | |
128 | ||
129 | // }}} | |
130 | } | |
131 | ||
132 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
133 | ?> |