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/
47 class ConfirmfirstemailAction extends Action
55 * For initializing members of the class.
57 * @param array $argarray misc. arguments
59 * @return boolean true
61 function prepare($argarray)
63 parent::prepare($argarray);
64 $user = common_current_user();
67 // TRANS: Client exception thrown when trying to register while already logged in.
68 throw new ClientException(_m('You are already logged in.'));
71 $this->code = $this->trimmed('code');
73 $this->confirm = Confirm_address::getKV('code', $this->code);
75 if (empty($this->confirm)) {
76 // TRANS: Client exception thrown when trying to register with a non-existing confirmation code.
77 throw new ClientException(_m('Confirmation code not found.'));
81 $this->user = User::getKV('id', $this->confirm->user_id);
83 if (empty($this->user)) {
84 // TRANS: Client exception thrown when trying to register with a confirmation code that is not connected with a user.
85 throw new ServerException(_m('No user for that confirmation code.'));
88 $type = $this->confirm->address_type;
90 if ($type != 'email') {
91 // TRANS: Client exception thrown when trying to register with a invalid e-mail address.
92 // TRANS: %s is the invalid e-mail address.
93 throw new ServerException(sprintf(_m('Unrecognized address type %s.'), $type));
96 if (!empty($this->user->email) && $this->user->email == $confirm->address) {
97 // TRANS: Client error for an already confirmed email/jabber/sms address.
98 throw new ClientException(_m('That address has already been confirmed.'));
101 if ($this->isPost()) {
103 $this->checkSessionToken();
105 $password = $this->trimmed('password');
106 $confirm = $this->trimmed('confirm');
108 if (strlen($password) < 6) {
109 // TRANS: Client exception thrown when trying to register with too short a password.
110 throw new ClientException(_m('Password too short.'));
112 } else if (0 != strcmp($password, $confirm)) {
113 // TRANS: Client exception thrown when trying to register without providing the same password twice.
114 throw new ClientException(_m('Passwords do not match.'));
118 $this->password = $password;
127 * @param array $argarray is ignored since it's now passed in in prepare()
131 function handle($argarray=null)
133 $homepage = common_local_url('all',
134 array('nickname' => $this->user->nickname));
136 if ($this->isPost()) {
137 $this->confirmUser();
138 common_set_user($this->user);
139 common_real_login(true);
140 common_redirect($homepage, 303);
147 function confirmUser()
149 $orig = clone($this->user);
151 $this->user->email = $this->confirm->address;
153 // Throws exception on failure.
154 $this->user->updateWithKeys($orig);
156 $this->user->emailChanged();
158 $orig = clone($this->user);
160 $this->user->password = common_munge_password($this->password, $this->user->getProfile());
162 $this->user->update($orig);
164 $this->confirm->delete();
167 function showContent()
169 $this->element('p', 'instructions',
170 // TRANS: Form instructions. %s is the nickname of the to be registered user.
171 sprintf(_m('You have confirmed the email address for your new user account %s. '.
172 'Use the form below to set your new password.'),
173 $this->user->nickname));
175 $form = new ConfirmFirstEmailForm($this, $this->code);
181 // TRANS: Page title.
182 return _m('Set a password');
186 class ConfirmFirstEmailForm extends Form
190 function __construct($out, $code)
192 parent::__construct($out);
196 function formLegend()
198 // TRANS: Form legend.
199 return _m('Confirm email address');
204 return common_local_url('confirmfirstemail',
205 array('code' => $this->code));
210 return 'form_settings';
215 $this->out->elementStart('ul', 'form_data');
216 $this->out->elementStart('li');
217 // TRANS: Field label.
218 $this->out->password('password', _m('New password'),
219 // TRANS: Field title for password field.
220 _m('6 or more characters.'));
221 $this->out->elementEnd('li');
222 $this->out->elementStart('li');
223 // TRANS: Field label for repeat password field.
224 $this->out->password('confirm', _m('LABEL','Confirm'),
225 // TRANS: Field title for repeat password field.
226 _m('Same as password above.'));
227 $this->out->elementEnd('li');
228 $this->out->elementEnd('ul');
231 function formActions()
233 // TRANS: Button text for completing registration by e-mail.
234 $this->out->submit('save', _m('BUTTON','Save'));