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/
47 class ConfirmaddressAction extends Action
49 /** type of confirmation. */
54 * Accept a confirmation code
56 * Checks the code and confirms the address in the
59 * @param args $args $_REQUEST array
63 function handle($args)
65 parent::handle($args);
66 if (!common_logged_in()) {
67 common_set_returnto($this->selfUrl());
68 common_redirect(common_local_url('login'));
71 $code = $this->trimmed('code');
73 // TRANS: Client error displayed when not providing a confirmation code in the contact address confirmation action.
74 $this->clientError(_('No confirmation code.'));
77 $confirm = Confirm_address::staticGet('code', $code);
79 // TRANS: Client error displayed when providing a non-existing confirmation code in the contact address confirmation action.
80 $this->clientError(_('Confirmation code not found.'));
83 $cur = common_current_user();
84 if ($cur->id != $confirm->user_id) {
85 // TRANS: Client error displayed when not providing a confirmation code for another user in the contact address confirmation action.
86 $this->clientError(_('That confirmation code is not for you!'));
89 $type = $confirm->address_type;
90 $transports = array();
91 Event::handle('GetImTransports', array(&$transports));
92 if (!in_array($type, array('email', 'sms')) && !in_array($type, array_keys($transports))) {
93 // 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')
94 $this->serverError(sprintf(_('Unrecognized address type %s'), $type));
97 $this->address = $confirm->address;
99 if (in_array($type, array('email', 'sms')))
101 if ($cur->$type == $confirm->address) {
102 // TRANS: Client error for an already confirmed email/jabber/sms address.
103 $this->clientError(_('That address has already been confirmed.'));
107 $orig_user = clone($cur);
109 $cur->$type = $confirm->address;
111 if ($type == 'sms') {
112 $cur->carrier = ($confirm->address_extra)+0;
113 $carrier = Sms_carrier::staticGet($cur->carrier);
114 $cur->smsemail = $carrier->toEmailAddress($cur->sms);
117 $result = $cur->updateKeys($orig_user);
120 common_log_db_error($cur, 'UPDATE', __FILE__);
121 // TRANS: Server error displayed when confirming an e-mail address or IM address fails.
122 $this->serverError(_('Could not update user.'));
126 if ($type == 'email') {
127 $cur->emailChanged();
132 $user_im_prefs = new User_im_prefs();
133 $user_im_prefs->transport = $confirm->address_type;
134 $user_im_prefs->user_id = $cur->id;
135 if ($user_im_prefs->find() && $user_im_prefs->fetch()) {
136 if($user_im_prefs->screenname == $confirm->address){
137 // TRANS: Client error for an already confirmed IM address.
138 $this->clientError(_('That address has already been confirmed.'));
141 $user_im_prefs->screenname = $confirm->address;
142 $result = $user_im_prefs->update();
145 common_log_db_error($user_im_prefs, 'UPDATE', __FILE__);
146 // TRANS: Server error displayed when updating IM preferences fails.
147 $this->serverError(_('Could not update user IM preferences.'));
151 $user_im_prefs = new User_im_prefs();
152 $user_im_prefs->screenname = $confirm->address;
153 $user_im_prefs->transport = $confirm->address_type;
154 $user_im_prefs->user_id = $cur->id;
155 $result = $user_im_prefs->insert();
158 common_log_db_error($user_im_prefs, 'INSERT', __FILE__);
159 // TRANS: Server error displayed when adding IM preferences fails.
160 $this->serverError(_('Could not insert user IM preferences.'));
167 $result = $confirm->delete();
170 common_log_db_error($confirm, 'DELETE', __FILE__);
171 // TRANS: Server error displayed when an address confirmation code deletion from the
172 // TRANS: database fails in the contact address confirmation action.
173 $this->serverError(_('Could not delete address confirmation.'));
177 $cur->query('COMMIT');
184 * @return string title
188 // TRANS: Title for the contact address confirmation action.
189 return _('Confirm address');
193 * Show a confirmation message.
197 function showContent()
199 $cur = common_current_user();
201 $this->element('p', null,
202 // TRANS: Success message for the contact address confirmation action.
203 // TRANS: %s can be 'email', 'jabber', or 'sms'.
204 sprintf(_('The address "%s" has been '.
205 'confirmed for your account.'),