3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Action for confirming first email registration
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * @category Confirmation
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2011 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
42 * @author Evan Prodromou <evan@status.net>
43 * @copyright 2011 StatusNet, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45 * @link http://status.net/
48 class ConfirmfirstemailAction extends Action
56 * For initializing members of the class.
58 * @param array $argarray misc. arguments
60 * @return boolean true
63 function prepare($argarray)
65 parent::prepare($argarray);
66 $user = common_current_user();
69 throw new ClientException(_('You are already logged in.'));
72 $this->code = $this->trimmed('code');
74 $this->confirm = Confirm_address::staticGet('code', $this->code);
76 if (empty($this->confirm)) {
77 throw new ClientException(_('Confirmation code not found.'));
81 $this->user = User::staticGet('id', $this->confirm->user_id);
83 if (empty($this->user)) {
84 throw new ServerException(_('No user for that confirmation code.'));
87 $type = $this->confirm->address_type;
89 if ($type != 'email') {
90 throw new ServerException(sprintf(_('Unrecognized address type %s.'), $type));
93 if (!empty($this->user->email) && $this->user->email == $confirm->address) {
94 // TRANS: Client error for an already confirmed email/jabber/sms address.
95 throw new ClientException(_('That address has already been confirmed.'));
98 if ($this->isPost()) {
100 $this->checkSessionToken();
102 $password = $this->trimmed('password');
103 $confirm = $this->trimmed('confirm');
105 if (strlen($password) < 6) {
106 throw new ClientException(_('Password too short.'));
108 } else if (0 != strcmp($password, $confirm)) {
109 throw new ClientException(_("Passwords don't match."));
113 $this->password = $password;
122 * @param array $argarray is ignored since it's now passed in in prepare()
127 function handle($argarray=null)
129 $homepage = common_local_url('all',
130 array('nickname' => $this->user->nickname));
132 if ($this->isPost()) {
133 $this->confirmUser();
134 common_set_user($this->user);
135 common_real_login(true);
136 common_redirect($homepage, 303);
143 function confirmUser()
145 $orig = clone($this->user);
147 $this->user->email = $this->confirm->address;
149 $this->user->updateKeys($orig);
151 $this->user->emailChanged();
153 $orig = clone($this->user);
155 $this->user->password = common_munge_password($this->password, $this->user->id);
157 $this->user->update($orig);
159 $this->confirm->delete();
162 function showContent()
164 $this->element('p', 'instructions',
165 sprintf(_('You have confirmed the email address for your new user account %s. '.
166 'Use the form below to set your new password.'),
167 $this->user->nickname));
169 $form = new ConfirmFirstEmailForm($this, $this->code);
175 return _('Set a password');
179 class ConfirmFirstEmailForm extends Form
183 function __construct($out, $code)
185 parent::__construct($out);
189 function formLegend()
191 return _('Confirm email');
196 return common_local_url('confirmfirstemail',
197 array('code' => $this->code));
202 return 'form_settings';
207 $this->out->elementStart('ul', 'form_data');
208 $this->out->elementStart('li');
209 $this->out->password('password', _('New password'),
210 _('6 or more characters.'));
211 $this->out->elementEnd('li');
212 $this->out->elementStart('li');
213 $this->out->password('confirm', _('Confirm'),
214 _('Same as password above.'));
215 $this->out->elementEnd('li');
216 $this->out->elementEnd('ul');
219 function formActions()
221 $this->out->submit('save', _('Save'));