]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/confirmaddress.php
fix notices in dumpschema
[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@status.net>
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://status.net/
28  */
29
30 if (!defined('STATUSNET') && !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@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  */
47
48 class ConfirmaddressAction extends Action
49 {
50     /** type of confirmation. */
51
52     var $address;
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             common_redirect(common_local_url('login'));
71             return;
72         }
73         $code = $this->trimmed('code');
74         if (!$code) {
75             $this->clientError(_('No confirmation code.'));
76             return;
77         }
78         $confirm = Confirm_address::staticGet('code', $code);
79         if (!$confirm) {
80             $this->clientError(_('Confirmation code not found.'));
81             return;
82         }
83         $cur = common_current_user();
84         if ($cur->id != $confirm->user_id) {
85             $this->clientError(_('That confirmation code is not for you!'));
86             return;
87         }
88         $type = $confirm->address_type;
89         $transports = array();
90         Event::handle('GetImTransports', array(&$transports));
91         if (!in_array($type, array('email', 'sms')) && !in_array($type, array_keys($transports))) {
92             // TRANS: Server error for an unknown address type, which can be 'email', 'sms', or the name of an IM network (such as 'xmpp' or 'aim')
93             $this->serverError(sprintf(_('Unrecognized address type %s'), $type));
94             return;
95         }
96         $this->address = $confirm->address;
97         $cur->query('BEGIN');
98         if (in_array($type, array('email', 'sms')))
99         {
100             if ($cur->$type == $confirm->address) {
101                 $this->clientError(_('That address has already been confirmed.'));
102                 return;
103             }
104
105             $orig_user = clone($cur);
106
107             $cur->$type = $confirm->address;
108
109             if ($type == 'sms') {
110                 $cur->carrier  = ($confirm->address_extra)+0;
111                 $carrier       = Sms_carrier::staticGet($cur->carrier);
112                 $cur->smsemail = $carrier->toEmailAddress($cur->sms);
113             }
114
115             $result = $cur->updateKeys($orig_user);
116
117             if (!$result) {
118                 common_log_db_error($cur, 'UPDATE', __FILE__);
119                 $this->serverError(_('Couldn\'t update user.'));
120                 return;
121             }
122
123             if ($type == 'email') {
124                 $cur->emailChanged();
125             }
126
127         } else {
128
129             $user_im_prefs = new User_im_prefs();
130             $user_im_prefs->transport = $confirm->address_type;
131             $user_im_prefs->user_id = $cur->id;
132             if ($user_im_prefs->find() && $user_im_prefs->fetch()) {
133                 if($user_im_prefs->screenname == $confirm->address){
134                     $this->clientError(_('That address has already been confirmed.'));
135                     return;
136                 }
137                 $user_im_prefs->screenname = $confirm->address;
138                 $result = $user_im_prefs->update();
139
140                 if (!$result) {
141                     common_log_db_error($user_im_prefs, 'UPDATE', __FILE__);
142                     $this->serverError(_('Couldn\'t update user im preferences.'));
143                     return;
144                 }
145             }else{
146                 $user_im_prefs = new User_im_prefs();
147                 $user_im_prefs->screenname = $confirm->address;
148                 $user_im_prefs->transport = $confirm->address_type;
149                 $user_im_prefs->user_id = $cur->id;
150                 $result = $user_im_prefs->insert();
151
152                 if (!$result) {
153                     common_log_db_error($user_im_prefs, 'INSERT', __FILE__);
154                     $this->serverError(_('Couldn\'t insert user im preferences.'));
155                     return;
156                 }
157             }
158
159         }
160
161         $result = $confirm->delete();
162
163         if (!$result) {
164             common_log_db_error($confirm, 'DELETE', __FILE__);
165             $this->serverError(_('Couldn\'t delete email confirmation.'));
166             return;
167         }
168
169         $cur->query('COMMIT');
170         $this->showPage();
171     }
172
173     /**
174      * Title of the page
175      *
176      * @return string title
177      */
178
179     function title()
180     {
181         return _('Confirm address');
182     }
183
184     /**
185      * Show a confirmation message.
186      *
187      * @return void
188      */
189
190     function showContent()
191     {
192         $cur  = common_current_user();
193
194         $this->element('p', null,
195                        sprintf(_('The address "%s" has been '.
196                                  'confirmed for your account.'),
197                                $this->address));
198     }
199 }