parent
7c62293b76
commit
45674f74bf
5 changed files with 27 additions and 25 deletions
|
@ -19,7 +19,7 @@ maxSearchTokens=4
|
|||
|
||||
[registration]
|
||||
emailActivation = 0
|
||||
adminActivation = 0
|
||||
staffActivation = 0
|
||||
passMinLength = 5
|
||||
passRegex = "/^.+$/"
|
||||
userNameMinLength = 3
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
form.auth {
|
||||
margin: 0 auto;
|
||||
display: table;
|
||||
border-collapse:separate;
|
||||
border-spacing: 0 0.5em;
|
||||
|
|
|
@ -35,10 +35,10 @@ class AuthController
|
|||
if ($suppliedPassHash != $dbUser->pass_hash)
|
||||
throw new SimpleException('Invalid password');
|
||||
|
||||
if (!$dbUser->admin_confirmed)
|
||||
throw new SimpleException('An admin hasn\'t confirmed your registration yet');
|
||||
if (!$dbUser->staff_confirmed and $this->config->registration->staffActivation)
|
||||
throw new SimpleException('Staff hasn\'t confirmed your registration yet');
|
||||
|
||||
if (!$dbUser->email_confirmed)
|
||||
if (!$dbUser->email_confirmed and $this->config->registration->emailActivation)
|
||||
throw new SimpleException('You haven\'t confirmed your e-mail address yet');
|
||||
|
||||
$_SESSION['user-id'] = $dbUser->id;
|
||||
|
@ -89,9 +89,9 @@ class AuthController
|
|||
$userNameMinLength = intval($regConfig->userNameMinLength);
|
||||
$userNameRegex = $regConfig->userNameRegex;
|
||||
$emailActivation = $regConfig->emailActivation;
|
||||
$adminActivation = $regConfig->adminActivation;
|
||||
$staffActivation = $regConfig->staffActivation;
|
||||
|
||||
$this->context->transport->adminActivation = $adminActivation;
|
||||
$this->context->transport->staffActivation = $staffActivation;
|
||||
$this->context->transport->emailActivation = $emailActivation;
|
||||
|
||||
if ($suppliedUser !== null)
|
||||
|
@ -102,12 +102,18 @@ class AuthController
|
|||
if (!$dbUser->email_confirmed)
|
||||
throw new SimpleException('User with this name is already registered and awaits e-mail confirmation');
|
||||
|
||||
if (!$dbUser->admin_confirmed)
|
||||
if (!$dbUser->staff_confirmed)
|
||||
throw new SimpleException('User with this name is already registered and awaits admin confirmation');
|
||||
|
||||
throw new SimpleException('User with this name is already registered');
|
||||
}
|
||||
|
||||
if (strlen($suppliedUser) < $userNameMinLength)
|
||||
throw new SimpleException(sprintf('User name must have at least %d characters', $userNameMinLength));
|
||||
|
||||
if (!preg_match($userNameRegex, $suppliedUser))
|
||||
throw new SimpleException('User name contains invalid characters');
|
||||
|
||||
if ($suppliedPass1 != $suppliedPass2)
|
||||
throw new SimpleException('Specified passwords must be the same');
|
||||
|
||||
|
@ -117,12 +123,6 @@ class AuthController
|
|||
if (!preg_match($passRegex, $suppliedPass1))
|
||||
throw new SimpleException('Password contains invalid characters');
|
||||
|
||||
if (strlen($suppliedUser) < $userNameMinLength)
|
||||
throw new SimpleException(sprintf('User name must have at least %d characters', $userNameMinLength));
|
||||
|
||||
if (!preg_match($userNameRegex, $suppliedUser))
|
||||
throw new SimpleException('User name contains invalid characters');
|
||||
|
||||
if (empty($suppliedEmail) and $emailActivation)
|
||||
throw new SimpleException('E-mail address is required - you will be sent confirmation e-mail.');
|
||||
|
||||
|
@ -136,7 +136,7 @@ class AuthController
|
|||
$dbUser->pass_salt = md5(mt_rand() . uniqid());
|
||||
$dbUser->pass_hash = self::hashPassword($suppliedPass1, $dbUser->pass_salt);
|
||||
$dbUser->email = $suppliedEmail;
|
||||
$dbUser->admin_confirmed = $adminActivation ? false : true;
|
||||
$dbUser->staff_confirmed = $staffActivation ? false : true;
|
||||
$dbUser->email_confirmed = $emailActivation ? false : true;
|
||||
$dbUser->access_rank = R::findOne('user') === null ? AccessRank::Admin : AccessRank::Registered;
|
||||
|
||||
|
@ -151,7 +151,6 @@ class AuthController
|
|||
//send the e-mail
|
||||
if ($emailActivation)
|
||||
{
|
||||
|
||||
$tokens = [];
|
||||
$tokens['host'] = $_SERVER['HTTP_HOST'];
|
||||
$tokens['link'] = \Chibi\UrlHelper::route('auth', 'activation', ['token' => $dbUser->email_token]);
|
||||
|
@ -172,7 +171,7 @@ class AuthController
|
|||
R::store($dbUser);
|
||||
$this->context->transport->success = true;
|
||||
|
||||
if (!$emailActivation and !$adminActivation)
|
||||
if (!$emailActivation and !$staffActivation)
|
||||
{
|
||||
$_SESSION['user-id'] = $dbUser->id;
|
||||
\Chibi\Registry::getBootstrap()->attachUser();
|
||||
|
@ -208,9 +207,9 @@ class AuthController
|
|||
R::store($dbUser);
|
||||
$this->context->transport->success = true;
|
||||
|
||||
$adminActivation = $this->config->registration->adminActivation;
|
||||
$this->context->transport->adminActivation = $adminActivation;
|
||||
if (!$adminActivation)
|
||||
$staffActivation = $this->config->registration->staffActivation;
|
||||
$this->context->transport->staffActivation = $staffActivation;
|
||||
if (!$staffActivation)
|
||||
{
|
||||
$_SESSION['user-id'] = $dbUser->id;
|
||||
\Chibi\Registry::getBootstrap()->attachUser();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php if ($this->context->transport->success === true): ?>
|
||||
<p>Activation completed successfully.</p>
|
||||
<?php if ($this->context->transport->adminActivation): ?>
|
||||
<p>However, you still need to be approved by admin.</p>
|
||||
<?php if ($this->context->transport->staffActivation): ?>
|
||||
<p>However, your account still must be confirmed by staff.</p>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
<?php if ($this->context->transport->success === true): ?>
|
||||
<p>Congratulations, you are registered.</p>
|
||||
<p>Congratulations, your account was created.</p>
|
||||
<?php if ($this->context->transport->emailActivation): ?>
|
||||
<p>Please wait for activation e-mail.</p>
|
||||
<?php endif ?>
|
||||
<?php if ($this->context->transport->adminActivation): ?>
|
||||
<p>After this, an admin will have to confirm your registration.</p>
|
||||
<?php if ($this->context->transport->staffActivation): ?>
|
||||
<p>After this, your registration must be confirmed by staff.</p>
|
||||
<?php endif ?>
|
||||
<?php elseif ($this->context->transport->staffActivation): ?>
|
||||
<p>Your registration must be confirmed by staff.</p>
|
||||
<?php endif ?>
|
||||
<?php else: ?>
|
||||
<form action="<?php echo \Chibi\UrlHelper::route('auth', 'register') ?>" class="auth" method="post">
|
||||
|
|
Loading…
Reference in a new issue