]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/confirmaddress.php
change Laconica and Control Yourself to StatusNet in PHP files
[quix0rs-gnu-social.git] / actions / confirmaddress.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Confirm an address
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Confirm
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @copyright 2008-2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://laconi.ca/
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Confirm an address
36  *
37  * When users change their SMS, email, Jabber, or other addresses, we send out
38  * a confirmation code to make sure the owner of that address approves. This class
39  * accepts those codes.
40  *
41  * @category Confirm
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@controlyourself.ca>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://laconi.ca/
46  */
47
48 class ConfirmaddressAction extends Action
49 {
50     /** type of confirmation. */
51
52     var $type = null;
53
54     /**
55      * Accept a confirmation code
56      *
57      * Checks the code and confirms the address in the
58      * user record
59      *
60      * @param args $args $_REQUEST array
61      *
62      * @return void
63      */
64
65     function handle($args)
66     {
67         parent::handle($args);
68         if (!common_logged_in()) {
69             common_set_returnto($this->selfUrl());
70             if (!common_config('site', 'openidonly')) {
71                 common_redirect(common_local_url('login'));
72             } else {
73                 common_redirect(common_local_url('openidlogin'));
74             }
75             return;
76         }
77         $code = $this->trimmed('code');
78         if (!$code) {
79             $this->clientError(_('No confirmation code.'));
80             return;
81         }
82         $confirm = Confirm_address::staticGet('code', $code);
83         if (!$confirm) {
84             $this->clientError(_('Confirmation code not found.'));
85             return;
86         }
87         $cur = common_current_user();
88         if ($cur->id != $confirm->user_id) {
89             $this->clientError(_('That confirmation code is not for you!'));
90             return;
91         }
92         $type = $confirm->address_type;
93         if (!in_array($type, array('email', 'jabber', 'sms'))) {
94             $this->serverError(sprintf(_('Unrecognized address type %s'), $type));
95             return;
96         }
97         if ($cur->$type == $confirm->address) {
98             $this->clientError(_('That address has already been confirmed.'));
99             return;
100         }
101
102         $cur->query('BEGIN');
103
104         $orig_user = clone($cur);
105
106         $cur->$type = $confirm->address;
107
108         if ($type == 'sms') {
109             $cur->carrier  = ($confirm->address_extra)+0;
110             $carrier       = Sms_carrier::staticGet($cur->carrier);
111             $cur->smsemail = $carrier->toEmailAddress($cur->sms);
112         }
113
114         $result = $cur->updateKeys($orig_user);
115
116         if (!$result) {
117             common_log_db_error($cur, 'UPDATE', __FILE__);
118             $this->serverError(_('Couldn\'t update user.'));
119             return;
120         }
121
122         if ($type == 'email') {
123             $cur->emailChanged();
124         }
125
126         $result = $confirm->delete();
127
128         if (!$result) {
129             common_log_db_error($confirm, 'DELETE', __FILE__);
130             $this->serverError(_('Couldn\'t delete email confirmation.'));
131             return;
132         }
133
134         $cur->query('COMMIT');
135
136         $this->type = $type;
137         $this->showPage();
138     }
139
140     /**
141      * Title of the page
142      *
143      * @return string title
144      */
145
146     function title()
147     {
148         return _('Confirm Address');
149     }
150
151     /**
152      * Show a confirmation message.
153      *
154      * @return void
155      */
156
157     function showContent()
158     {
159         $cur  = common_current_user();
160         $type = $this->type;
161
162         $this->element('p', null,
163                        sprintf(_('The address "%s" has been '.
164                                  'confirmed for your account.'),
165                                $cur->$type));
166     }
167 }