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