123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <?php
- if (!defined('STATUSNET')) {
-
-
- exit(1);
- }
- class ConfirmfirstemailAction extends Action
- {
- public $confirm;
- public $code;
- public $password;
- public $user;
-
- function prepare(array $args = [])
- {
- parent::prepare($args);
- $user = common_current_user();
- if (!empty($user)) {
-
- throw new ClientException(_m('You are already logged in.'));
- }
- $this->code = $this->trimmed('code');
- $this->confirm = Confirm_address::getKV('code', $this->code);
- if (empty($this->confirm)) {
-
- throw new ClientException(_m('Confirmation code not found.'));
- }
- $this->user = User::getKV('id', $this->confirm->user_id);
- if (empty($this->user)) {
-
- throw new ServerException(_m('No user for that confirmation code.'));
- }
- $type = $this->confirm->address_type;
- if ($type != 'email') {
-
-
- throw new ServerException(sprintf(_m('Unrecognized address type %s.'), $type));
- }
- if (!empty($this->user->email) && $this->user->email == $this->confirm->address) {
-
- throw new ClientException(_m('That address has already been confirmed.'));
- }
- if ($this->isPost()) {
- $this->checkSessionToken();
- $password = $this->trimmed('password');
- $confirm = $this->trimmed('confirm');
- if (strlen($password) < 6) {
-
- throw new ClientException(_m('Password too short.'));
- } else if (0 != strcmp($password, $confirm)) {
-
- throw new ClientException(_m('Passwords do not match.'));
- }
- $this->password = $password;
- }
- return true;
- }
-
- function handle()
- {
- $homepage = common_local_url('all',
- 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;
-
- $this->user->updateWithKeys($orig);
- $this->user->emailChanged();
- $orig = clone($this->user);
- $this->user->password = common_munge_password($this->password, $this->user->getProfile());
- $this->user->update($orig);
- $this->confirm->delete();
- }
- function showContent()
- {
- $this->element('p', 'instructions',
-
- sprintf(_m('You have confirmed the email address for your new user account %s. ' .
- 'Use the form below to set your new password.'),
- $this->user->nickname));
- $form = new ConfirmFirstEmailForm($this, $this->code);
- $form->show();
- }
- function title()
- {
-
- return _m('Set a password');
- }
- }
- class ConfirmFirstEmailForm extends Form
- {
- public $code;
- function __construct($out, $code)
- {
- parent::__construct($out);
- $this->code = $code;
- }
- function formLegend()
- {
-
- return _m('Confirm email address');
- }
- function action()
- {
- return common_local_url('confirmfirstemail',
- array('code' => $this->code));
- }
- function formClass()
- {
- return 'form_settings';
- }
- function formData()
- {
- $this->out->elementStart('ul', 'form_data');
- $this->out->elementStart('li');
-
- $this->out->password('password', _m('New password'),
-
- _m('6 or more characters.'));
- $this->out->elementEnd('li');
- $this->out->elementStart('li');
-
- $this->out->password('confirm', _m('LABEL', 'Confirm'),
-
- _m('Same as password above.'));
- $this->out->elementEnd('li');
- $this->out->elementEnd('ul');
- }
- function formActions()
- {
-
- $this->out->submit('save', _m('BUTTON', 'Save'));
- }
- }
|