From: Evan Prodromou Date: Fri, 25 Feb 2011 16:01:41 +0000 (-0800) Subject: Let users who aren't allowed to login confirm their email separately X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7c192dabe23dd2256ed3fb491853e69008b46521;p=quix0rs-gnu-social.git Let users who aren't allowed to login confirm their email separately --- diff --git a/plugins/RequireValidatedEmail/RequireValidatedEmailPlugin.php b/plugins/RequireValidatedEmail/RequireValidatedEmailPlugin.php index ad6503e0b7..e6508adc7e 100644 --- a/plugins/RequireValidatedEmail/RequireValidatedEmailPlugin.php +++ b/plugins/RequireValidatedEmail/RequireValidatedEmailPlugin.php @@ -83,6 +83,27 @@ class RequireValidatedEmailPlugin extends Plugin public $disallowLogin = false; + function onAutoload($cls) + { + $dir = dirname(__FILE__); + + switch ($cls) + { + case 'ConfirmfirstemailAction': + include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php'; + return false; + default: + return true; + } + } + + function onRouterInitialized($m) + { + $m->connect('main/confirmfirst/:code', + array('action' => 'confirmfirstemail')); + return true; + } + /** * Event handler for notice saves; rejects the notice * if user's address isn't validated. diff --git a/plugins/RequireValidatedEmail/confirmfirstemail.php b/plugins/RequireValidatedEmail/confirmfirstemail.php new file mode 100644 index 0000000000..bdf7c43a1b --- /dev/null +++ b/plugins/RequireValidatedEmail/confirmfirstemail.php @@ -0,0 +1,218 @@ +. + * + * @category Confirmation + * @package StatusNet + * @author Evan Prodromou + * @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 + * @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)) { + throw new ClientException(_('You are already logged in.')); + } + + $this->code = $this->trimmed('code'); + + $this->confirm = Confirm_address::staticGet('code', $this->code); + + if (empty($this->confirm)) { + throw new ClientException(_('Confirmation code not found.')); + return; + } + + $this->user = User::staticGet('id', $this->confirm->user_id); + + if (empty($this->user)) { + throw new ServerException(_('No user for that confirmation code.')); + } + + $type = $this->confirm->address_type; + + if ($type != 'email') { + throw new ServerException(sprintf(_('Unrecognized address type %s.'), $type)); + } + + if (!empty($this->user->email) && $this->user->email == $confirm->address) { + // TRANS: Client error for an already confirmed email/jabber/sms address. + throw new ClientException(_('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(_('Password too short.')); + return; + } else if (0 != strcmp($password, $confirm)) { + throw new ClientException(_("Passwords don't match.")); + 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) + { + $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->updateKeys($orig); + + $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', + sprintf(_('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 _('Set a password'); + } +} + +class ConfirmFirstEmailForm extends Form +{ + public $code; + + function __construct($out, $code) + { + parent::__construct($out); + $this->code = $code; + } + + function formLegend() + { + return _('Confirm email'); + } + + function action() + { + return common_local_url('confirmfirstemail', + array('code' => $this->code)); + } + + function formData() + { + $this->out->elementStart('ul', 'form_data'); + $this->out->elementStart('li'); + $this->out->password('password', _('New password'), + _('6 or more characters.')); + $this->out->elementEnd('li'); + $this->out->elementStart('li'); + $this->out->password('confirm', _('Confirm'), + _('Same as password above.')); + $this->out->elementEnd('li'); + $this->out->elementEnd('ul'); + } + + function formActions() + { + $this->out->submit('save', _('Save')); + } +} diff --git a/plugins/RequireValidatedEmail/registerbyemail.php b/plugins/RequireValidatedEmail/registerbyemail.php new file mode 100644 index 0000000000..59c229b684 --- /dev/null +++ b/plugins/RequireValidatedEmail/registerbyemail.php @@ -0,0 +1,80 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..')); + +$shortoptions = "e:"; + +$helptext = <<user_id = $user->id; + $confirm->address_type = 'email'; + + if ($confirm->find(true)) { + $url = common_local_url('confirmfirstemail', + array('code' => $confirm->code)); + + print "$url\n"; + } else { + print "User not waiting for confirmation.\n"; + } + + exit; +} + +$user = User::register(array('nickname' => $nickname, + 'password' => null)); + +$confirm = new Confirm_address(); +$confirm->code = common_confirmation_code(128); +$confirm->user_id = $user->id; +$confirm->address = $email; +$confirm->address_type = 'email'; + +$confirm->insert(); + +$url = common_local_url('confirmfirstemail', + array('code' => $confirm->code)); + +print "$url\n"; + +mail_confirm_address($user, + $confirm->code, + $user->nickname, + $email, + $url);