3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
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.
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.
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/>.
20 if (!defined('LACONICA')) { exit(1); }
22 class ConfirmemailAction extends Action {
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'));
31 $code = $this->trimmed('code');
33 $this->client_error(_t('No confirmation code.'));
36 $confirm_email = Confirm_email::staticGet('code', $code);
37 if (!$confirm_email) {
38 $this->client_error(_t('Confirmation code not found.'));
41 $cur = common_current_user();
42 if ($cur->id != $confirm_email->user_id) {
43 $this->client_error(_t('That confirmation code is not for you!'));
46 if ($cur->email == $confirm_email->email) {
47 $this->client_error(_t('That email address is already confirmed.'));
53 $orig_user = clone($cur);
55 $cur->email = $confirm_email->email;
56 $result = $cur->updateKeys($orig_user);
59 common_log_db_error($cur, 'UPDATE', __FILE__);
60 $this->server_error(_t('Couldn\'t update user.'));
64 $result = $confirm_email->delete();
67 common_log_db_error($confirm_email, 'DELETE', __FILE__);
68 $this->server_error(_t('Couldn\'t delete email confirmation.'));
72 $cur->query('COMMIT');
74 common_show_header(_t('Confirm E-mail Address'));
75 common_element('p', NULL,
76 _t('The email address "') . $cur->email .
77 _t('" has been confirmed for your account.'));
78 common_show_footer(_t('Confirm E-mail Address'));