3 * StatusNet, the distributed open-source microblogging tool
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.
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.
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/>.
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/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
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.
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/
48 class ConfirmaddressAction extends Action
50 /** type of confirmation. */
55 * Accept a confirmation code
57 * Checks the code and confirms the address in the
60 * @param args $args $_REQUEST array
65 function handle($args)
67 parent::handle($args);
68 if (!common_logged_in()) {
69 common_set_returnto($this->selfUrl());
70 common_redirect(common_local_url('login'));
73 $code = $this->trimmed('code');
75 $this->clientError(_('No confirmation code.'));
78 $confirm = Confirm_address::staticGet('code', $code);
80 $this->clientError(_('Confirmation code not found.'));
83 $cur = common_current_user();
84 if ($cur->id != $confirm->user_id) {
85 $this->clientError(_('That confirmation code is not for you!'));
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 $this->serverError(sprintf(_('Unrecognized address type %s'), $type));
95 $this->address = $confirm->address;
97 if (in_array($type, array('email', 'sms')))
99 if ($cur->$type == $confirm->address) {
100 $this->clientError(_('That address has already been confirmed.'));
104 $orig_user = clone($cur);
106 $cur->$type = $confirm->address;
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);
114 $result = $cur->updateKeys($orig_user);
117 common_log_db_error($cur, 'UPDATE', __FILE__);
118 $this->serverError(_('Couldn\'t update user.'));
122 if ($type == 'email') {
123 $cur->emailChanged();
128 $user_im_prefs = new User_im_prefs();
129 $user_im_prefs->transport = $confirm->address_type;
130 $user_im_prefs->user_id = $cur->id;
131 if ($user_im_prefs->find() && $user_im_prefs->fetch()) {
132 if($user_im_prefs->screenname == $confirm->address){
133 $this->clientError(_('That address has already been confirmed.'));
136 $user_im_prefs->screenname = $confirm->address;
137 $result = $user_im_prefs->update();
140 common_log_db_error($user_im_prefs, 'UPDATE', __FILE__);
141 $this->serverError(_('Couldn\'t update user im preferences.'));
145 $user_im_prefs = new User_im_prefs();
146 $user_im_prefs->screenname = $confirm->address;
147 $user_im_prefs->transport = $confirm->address_type;
148 $user_im_prefs->user_id = $cur->id;
149 $result = $user_im_prefs->insert();
152 common_log_db_error($user_im_prefs, 'INSERT', __FILE__);
153 $this->serverError(_('Couldn\'t insert user im preferences.'));
160 $result = $confirm->delete();
163 common_log_db_error($confirm, 'DELETE', __FILE__);
164 $this->serverError(_('Couldn\'t delete email confirmation.'));
168 $cur->query('COMMIT');
175 * @return string title
180 return _('Confirm address');
184 * Show a confirmation message.
189 function showContent()
191 $cur = common_current_user();
193 $this->element('p', null,
194 sprintf(_('The address "%s" has been '.
195 'confirmed for your account.'),