]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/confirmaddress.php
move opening brace of class declaration to next line
[quix0rs-gnu-social.git] / actions / confirmaddress.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 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 Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 class ConfirmaddressAction extends Action
23 {
24
25     function handle($args)
26     {
27         parent::handle($args);
28         if (!common_logged_in()) {
29             common_set_returnto($this->self_url());
30             common_redirect(common_local_url('login'));
31             return;
32         }
33         $code = $this->trimmed('code');
34         if (!$code) {
35             $this->client_error(_('No confirmation code.'));
36             return;
37         }
38         $confirm = Confirm_address::staticGet('code', $code);
39         if (!$confirm) {
40             $this->client_error(_('Confirmation code not found.'));
41             return;
42         }
43         $cur = common_current_user();
44         if ($cur->id != $confirm->user_id) {
45             $this->client_error(_('That confirmation code is not for you!'));
46             return;
47         }
48         $type = $confirm->address_type;
49         if (!in_array($type, array('email', 'jabber', 'sms'))) {
50             $this->server_error(sprintf(_('Unrecognized address type %s'), $type));
51             return;
52         }
53         if ($cur->$type == $confirm->address) {
54             $this->client_error(_('That address has already been confirmed.'));
55             return;
56         }
57
58         $cur->query('BEGIN');
59
60         $orig_user = clone($cur);
61
62         $cur->$type = $confirm->address;
63
64         if ($type == 'sms') {
65             $cur->carrier = ($confirm->address_extra)+0;
66             $carrier = Sms_carrier::staticGet($cur->carrier);
67             $cur->smsemail = $carrier->toEmailAddress($cur->sms);
68         }
69
70         $result = $cur->updateKeys($orig_user);
71
72         if (!$result) {
73             common_log_db_error($cur, 'UPDATE', __FILE__);
74             $this->server_error(_('Couldn\'t update user.'));
75             return;
76         }
77
78         if ($type == 'email') {
79             $cur->emailChanged();
80         }
81
82         $result = $confirm->delete();
83
84         if (!$result) {
85             common_log_db_error($confirm, 'DELETE', __FILE__);
86             $this->server_error(_('Couldn\'t delete email confirmation.'));
87             return;
88         }
89
90         $cur->query('COMMIT');
91
92         common_show_header(_('Confirm Address'));
93         common_element('p', null,
94                        sprintf(_('The address "%s" has been confirmed for your account.'), $cur->$type));
95         common_show_footer();
96     }
97 }