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