2011-02-26 01:01:41 +09:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2011, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* Action for confirming first email registration
|
2011-06-06 02:58:11 +09:00
|
|
|
*
|
2011-02-26 01:01:41 +09:00
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
* @category Confirmation
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2011 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET')) {
|
|
|
|
// This check helps protect against security problems;
|
|
|
|
// your code file can't be executed directly from the web.
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class comment
|
|
|
|
*
|
|
|
|
* @category Action
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2011 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
class ConfirmfirstemailAction extends Action
|
|
|
|
{
|
|
|
|
public $confirm;
|
|
|
|
public $code;
|
|
|
|
public $password;
|
|
|
|
public $user;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For initializing members of the class.
|
|
|
|
*
|
|
|
|
* @param array $argarray misc. arguments
|
|
|
|
*
|
|
|
|
* @return boolean true
|
|
|
|
*/
|
|
|
|
function prepare($argarray)
|
|
|
|
{
|
|
|
|
parent::prepare($argarray);
|
|
|
|
$user = common_current_user();
|
|
|
|
|
|
|
|
if (!empty($user)) {
|
2011-06-06 02:58:11 +09:00
|
|
|
// TRANS: Client exception thrown when trying to register while already logged in.
|
2011-03-31 05:30:23 +09:00
|
|
|
throw new ClientException(_m('You are already logged in.'));
|
2011-02-26 01:01:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->code = $this->trimmed('code');
|
|
|
|
|
2013-08-18 20:04:58 +09:00
|
|
|
$this->confirm = Confirm_address::getKV('code', $this->code);
|
2011-02-26 01:01:41 +09:00
|
|
|
|
|
|
|
if (empty($this->confirm)) {
|
2011-06-06 02:58:11 +09:00
|
|
|
// TRANS: Client exception thrown when trying to register with a non-existing confirmation code.
|
2011-03-31 05:30:23 +09:00
|
|
|
throw new ClientException(_m('Confirmation code not found.'));
|
2011-02-26 01:01:41 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-18 20:04:58 +09:00
|
|
|
$this->user = User::getKV('id', $this->confirm->user_id);
|
2011-02-26 01:01:41 +09:00
|
|
|
|
|
|
|
if (empty($this->user)) {
|
2011-06-06 02:58:11 +09:00
|
|
|
// TRANS: Client exception thrown when trying to register with a confirmation code that is not connected with a user.
|
2011-03-31 05:30:23 +09:00
|
|
|
throw new ServerException(_m('No user for that confirmation code.'));
|
2011-02-26 01:01:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
$type = $this->confirm->address_type;
|
|
|
|
|
|
|
|
if ($type != 'email') {
|
2011-06-06 02:58:11 +09:00
|
|
|
// TRANS: Client exception thrown when trying to register with a invalid e-mail address.
|
|
|
|
// TRANS: %s is the invalid e-mail address.
|
2011-03-31 05:30:23 +09:00
|
|
|
throw new ServerException(sprintf(_m('Unrecognized address type %s.'), $type));
|
2011-02-26 01:01:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($this->user->email) && $this->user->email == $confirm->address) {
|
|
|
|
// TRANS: Client error for an already confirmed email/jabber/sms address.
|
2011-03-31 05:30:23 +09:00
|
|
|
throw new ClientException(_m('That address has already been confirmed.'));
|
2011-02-26 01:01:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->isPost()) {
|
|
|
|
|
|
|
|
$this->checkSessionToken();
|
|
|
|
|
|
|
|
$password = $this->trimmed('password');
|
|
|
|
$confirm = $this->trimmed('confirm');
|
|
|
|
|
|
|
|
if (strlen($password) < 6) {
|
2011-06-06 02:58:11 +09:00
|
|
|
// TRANS: Client exception thrown when trying to register with too short a password.
|
2011-03-31 05:30:23 +09:00
|
|
|
throw new ClientException(_m('Password too short.'));
|
2011-02-26 01:01:41 +09:00
|
|
|
return;
|
|
|
|
} else if (0 != strcmp($password, $confirm)) {
|
2011-06-06 02:58:11 +09:00
|
|
|
// TRANS: Client exception thrown when trying to register without providing the same password twice.
|
|
|
|
throw new ClientException(_m('Passwords do not match.'));
|
2011-02-26 01:01:41 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->password = $password;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler method
|
|
|
|
*
|
|
|
|
* @param array $argarray is ignored since it's now passed in in prepare()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function handle($argarray=null)
|
|
|
|
{
|
2011-06-06 02:58:11 +09:00
|
|
|
$homepage = common_local_url('all',
|
2011-02-26 01:01:41 +09:00
|
|
|
array('nickname' => $this->user->nickname));
|
|
|
|
|
|
|
|
if ($this->isPost()) {
|
|
|
|
$this->confirmUser();
|
|
|
|
common_set_user($this->user);
|
|
|
|
common_real_login(true);
|
|
|
|
common_redirect($homepage, 303);
|
|
|
|
} else {
|
|
|
|
$this->showPage();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function confirmUser()
|
|
|
|
{
|
|
|
|
$orig = clone($this->user);
|
|
|
|
|
|
|
|
$this->user->email = $this->confirm->address;
|
|
|
|
|
2015-01-25 20:07:26 +09:00
|
|
|
$this->user->updateWithKeys($orig);
|
2011-02-26 01:01:41 +09:00
|
|
|
|
|
|
|
$this->user->emailChanged();
|
|
|
|
|
|
|
|
$orig = clone($this->user);
|
|
|
|
|
|
|
|
$this->user->password = common_munge_password($this->password, $this->user->id);
|
|
|
|
|
|
|
|
$this->user->update($orig);
|
|
|
|
|
|
|
|
$this->confirm->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
function showContent()
|
|
|
|
{
|
|
|
|
$this->element('p', 'instructions',
|
2011-06-06 02:58:11 +09:00
|
|
|
// TRANS: Form instructions. %s is the nickname of the to be registered user.
|
2011-03-31 05:30:23 +09:00
|
|
|
sprintf(_m('You have confirmed the email address for your new user account %s. '.
|
2011-02-26 01:01:41 +09:00
|
|
|
'Use the form below to set your new password.'),
|
|
|
|
$this->user->nickname));
|
|
|
|
|
|
|
|
$form = new ConfirmFirstEmailForm($this, $this->code);
|
|
|
|
$form->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
function title()
|
|
|
|
{
|
2011-06-06 02:58:11 +09:00
|
|
|
// TRANS: Page title.
|
2011-03-31 05:30:23 +09:00
|
|
|
return _m('Set a password');
|
2011-02-26 01:01:41 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ConfirmFirstEmailForm extends Form
|
|
|
|
{
|
|
|
|
public $code;
|
|
|
|
|
|
|
|
function __construct($out, $code)
|
|
|
|
{
|
|
|
|
parent::__construct($out);
|
|
|
|
$this->code = $code;
|
|
|
|
}
|
|
|
|
|
|
|
|
function formLegend()
|
|
|
|
{
|
2011-06-06 02:58:11 +09:00
|
|
|
// TRANS: Form legend.
|
|
|
|
return _m('Confirm email address');
|
2011-02-26 01:01:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function action()
|
|
|
|
{
|
|
|
|
return common_local_url('confirmfirstemail',
|
|
|
|
array('code' => $this->code));
|
|
|
|
}
|
|
|
|
|
2011-02-26 06:18:28 +09:00
|
|
|
function formClass()
|
|
|
|
{
|
|
|
|
return 'form_settings';
|
|
|
|
}
|
|
|
|
|
2011-02-26 01:01:41 +09:00
|
|
|
function formData()
|
|
|
|
{
|
|
|
|
$this->out->elementStart('ul', 'form_data');
|
|
|
|
$this->out->elementStart('li');
|
2011-06-06 02:58:11 +09:00
|
|
|
// TRANS: Field label.
|
2011-03-31 05:30:23 +09:00
|
|
|
$this->out->password('password', _m('New password'),
|
2011-06-06 02:58:11 +09:00
|
|
|
// TRANS: Field title for password field.
|
2011-03-31 05:30:23 +09:00
|
|
|
_m('6 or more characters.'));
|
2011-02-26 01:01:41 +09:00
|
|
|
$this->out->elementEnd('li');
|
|
|
|
$this->out->elementStart('li');
|
2011-06-06 02:58:11 +09:00
|
|
|
// TRANS: Field label for repeat password field.
|
|
|
|
$this->out->password('confirm', _m('LABEL','Confirm'),
|
|
|
|
// TRANS: Field title for repeat password field.
|
2011-03-31 05:30:23 +09:00
|
|
|
_m('Same as password above.'));
|
2011-02-26 01:01:41 +09:00
|
|
|
$this->out->elementEnd('li');
|
|
|
|
$this->out->elementEnd('ul');
|
|
|
|
}
|
|
|
|
|
|
|
|
function formActions()
|
|
|
|
{
|
2011-06-06 02:58:11 +09:00
|
|
|
// TRANS: Button text for completing registration by e-mail.
|
|
|
|
$this->out->submit('save', _m('BUTTON','Save'));
|
2011-02-26 01:01:41 +09:00
|
|
|
}
|
|
|
|
}
|