We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

confirmaddress.php 4.46 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1
<?php
Evan Prodromou's avatar
Evan Prodromou committed
2
/**
3
 * StatusNet, the distributed open-source microblogging tool
Evan Prodromou's avatar
Evan Prodromou committed
4
 *
Evan Prodromou's avatar
Evan Prodromou committed
5 6 7 8 9
 * Confirm an address
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
Evan Prodromou's avatar
Evan Prodromou committed
10 11 12 13 14 15 16 17 18 19 20
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Evan Prodromou's avatar
Evan Prodromou committed
21 22
 *
 * @category  Confirm
23
 * @package   StatusNet
24
 * @author    Evan Prodromou <evan@status.net>
25
 * @copyright 2008-2009 StatusNet, Inc.
Evan Prodromou's avatar
Evan Prodromou committed
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/
Evan Prodromou's avatar
Evan Prodromou committed
28 29
 */

30
if (!defined('STATUSNET') && !defined('LACONICA')) {
Evan Prodromou's avatar
Evan Prodromou committed
31 32 33 34 35 36 37 38 39 40 41
    exit(1);
}

/**
 * Confirm an address
 *
 * When users change their SMS, email, Jabber, or other addresses, we send out
 * a confirmation code to make sure the owner of that address approves. This class
 * accepts those codes.
 *
 * @category Confirm
42
 * @package  StatusNet
43
 * @author   Evan Prodromou <evan@status.net>
Evan Prodromou's avatar
Evan Prodromou committed
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/
Evan Prodromou's avatar
Evan Prodromou committed
46
 */
Evan Prodromou's avatar
Evan Prodromou committed
47

48 49
class ConfirmaddressAction extends Action
{
Evan Prodromou's avatar
Evan Prodromou committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63
    /** type of confirmation. */

    var $type = null;

    /**
     * Accept a confirmation code
     *
     * Checks the code and confirms the address in the
     * user record
     *
     * @param args $args $_REQUEST array
     *
     * @return void
     */
Evan Prodromou's avatar
Evan Prodromou committed
64

65 66
    function handle($args)
    {
67 68
        parent::handle($args);
        if (!common_logged_in()) {
69
            common_set_returnto($this->selfUrl());
70
            common_redirect(common_local_url('login'));
71 72 73 74
            return;
        }
        $code = $this->trimmed('code');
        if (!$code) {
75
            $this->clientError(_('No confirmation code.'));
76 77
            return;
        }
Evan Prodromou's avatar
Evan Prodromou committed
78 79
        $confirm = Confirm_address::staticGet('code', $code);
        if (!$confirm) {
80
            $this->clientError(_('Confirmation code not found.'));
81 82 83
            return;
        }
        $cur = common_current_user();
Evan Prodromou's avatar
Evan Prodromou committed
84
        if ($cur->id != $confirm->user_id) {
85
            $this->clientError(_('That confirmation code is not for you!'));
86 87
            return;
        }
88 89
        $type = $confirm->address_type;
        if (!in_array($type, array('email', 'jabber', 'sms'))) {
90
            $this->serverError(sprintf(_('Unrecognized address type %s'), $type));
91 92
            return;
        }
Evan Prodromou's avatar
Evan Prodromou committed
93
        if ($cur->$type == $confirm->address) {
94
            $this->clientError(_('That address has already been confirmed.'));
95 96
            return;
        }
97

98
        $cur->query('BEGIN');
99

100
        $orig_user = clone($cur);
Evan Prodromou's avatar
Evan Prodromou committed
101

102
        $cur->$type = $confirm->address;
Evan Prodromou's avatar
Evan Prodromou committed
103

104
        if ($type == 'sms') {
Evan Prodromou's avatar
Evan Prodromou committed
105 106
            $cur->carrier  = ($confirm->address_extra)+0;
            $carrier       = Sms_carrier::staticGet($cur->carrier);
107 108
            $cur->smsemail = $carrier->toEmailAddress($cur->sms);
        }
109

110
        $result = $cur->updateKeys($orig_user);
111

112
        if (!$result) {
113
            common_log_db_error($cur, 'UPDATE', __FILE__);
114
            $this->serverError(_('Couldn\'t update user.'));
115 116
            return;
        }
117

118 119 120
        if ($type == 'email') {
            $cur->emailChanged();
        }
Evan Prodromou's avatar
Evan Prodromou committed
121

Evan Prodromou's avatar
Evan Prodromou committed
122
        $result = $confirm->delete();
123

124
        if (!$result) {
125
            common_log_db_error($confirm, 'DELETE', __FILE__);
126
            $this->serverError(_('Couldn\'t delete email confirmation.'));
127 128
            return;
        }
129

130
        $cur->query('COMMIT');
Evan Prodromou's avatar
Evan Prodromou committed
131

Evan Prodromou's avatar
Evan Prodromou committed
132 133 134 135 136 137 138 139 140 141 142 143
        $this->type = $type;
        $this->showPage();
    }

    /**
     * Title of the page
     *
     * @return string title
     */

    function title()
    {
144
        return _('Confirm address');
Evan Prodromou's avatar
Evan Prodromou committed
145 146 147 148 149 150 151 152 153 154 155 156 157
    }

    /**
     * Show a confirmation message.
     *
     * @return void
     */

    function showContent()
    {
        $cur  = common_current_user();
        $type = $this->type;

158
        $this->element('p', null,
Evan Prodromou's avatar
Evan Prodromou committed
159 160 161
                       sprintf(_('The address "%s" has been '.
                                 'confirmed for your account.'),
                               $cur->$type));
162
    }
Evan Prodromou's avatar
Evan Prodromou committed
163
}