]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/confirmaddress.php
d926864a6cc13a08d4359fd42344cd356ad6b24a
[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     function handle($args)
25     {
26         parent::handle($args);
27         if (!common_logged_in()) {
28             common_set_returnto($this->self_url());
29             common_redirect(common_local_url('login'));
30             return;
31         }
32         $code = $this->trimmed('code');
33         if (!$code) {
34             $this->client_error(_('No confirmation code.'));
35             return;
36         }
37         $confirm = Confirm_address::staticGet('code', $code);
38         if (!$confirm) {
39             $this->client_error(_('Confirmation code not found.'));
40             return;
41         }
42         $cur = common_current_user();
43         if ($cur->id != $confirm->user_id) {
44             $this->client_error(_('That confirmation code is not for you!'));
45             return;
46         }
47         $type = $confirm->address_type;
48         if (!in_array($type, array('email', 'jabber', 'sms'))) {
49             $this->server_error(sprintf(_('Unrecognized address type %s'), $type));
50             return;
51         }
52         if ($cur->$type == $confirm->address) {
53             $this->client_error(_('That address has already been confirmed.'));
54             return;
55         }
56
57         $cur->query('BEGIN');
58
59         $orig_user = clone($cur);
60
61         $cur->$type = $confirm->address;
62
63         if ($type == 'sms') {
64             $cur->carrier = ($confirm->address_extra)+0;
65             $carrier = Sms_carrier::staticGet($cur->carrier);
66             $cur->smsemail = $carrier->toEmailAddress($cur->sms);
67         }
68
69         $result = $cur->updateKeys($orig_user);
70
71         if (!$result) {
72             common_log_db_error($cur, 'UPDATE', __FILE__);
73             $this->server_error(_('Couldn\'t update user.'));
74             return;
75         }
76
77         if ($type == 'email') {
78             $cur->emailChanged();
79         }
80
81         $result = $confirm->delete();
82
83         if (!$result) {
84             common_log_db_error($confirm, 'DELETE', __FILE__);
85             $this->server_error(_('Couldn\'t delete email confirmation.'));
86             return;
87         }
88
89         $cur->query('COMMIT');
90
91         common_show_header(_('Confirm Address'));
92         common_element('p', null,
93                        sprintf(_('The address "%s" has been confirmed for your account.'), $cur->$type));
94         common_show_footer();
95     }
96 }