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