From 45674f74bfb62ff1241c608dab0baee6011097e8 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 13 Oct 2013 13:53:24 +0200 Subject: [PATCH] Closed #26; closed #25 Small changes to schema --- config.ini | 2 +- public_html/media/css/auth.css | 1 + src/Controllers/AuthController.php | 35 +++++++++++++++--------------- src/Views/auth-activation.phtml | 4 ++-- src/Views/auth-register.phtml | 10 +++++---- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/config.ini b/config.ini index d7985493..53fcbe1d 100644 --- a/config.ini +++ b/config.ini @@ -19,7 +19,7 @@ maxSearchTokens=4 [registration] emailActivation = 0 -adminActivation = 0 +staffActivation = 0 passMinLength = 5 passRegex = "/^.+$/" userNameMinLength = 3 diff --git a/public_html/media/css/auth.css b/public_html/media/css/auth.css index d8bb2c49..40a11206 100644 --- a/public_html/media/css/auth.css +++ b/public_html/media/css/auth.css @@ -1,4 +1,5 @@ form.auth { + margin: 0 auto; display: table; border-collapse:separate; border-spacing: 0 0.5em; diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index a8ccddde..e7d8271a 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -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(); diff --git a/src/Views/auth-activation.phtml b/src/Views/auth-activation.phtml index 611f767f..bfc8b2ea 100644 --- a/src/Views/auth-activation.phtml +++ b/src/Views/auth-activation.phtml @@ -1,6 +1,6 @@ context->transport->success === true): ?>

Activation completed successfully.

- context->transport->adminActivation): ?> -

However, you still need to be approved by admin.

+ context->transport->staffActivation): ?> +

However, your account still must be confirmed by staff.

diff --git a/src/Views/auth-register.phtml b/src/Views/auth-register.phtml index bc6889d1..b1bdd931 100644 --- a/src/Views/auth-register.phtml +++ b/src/Views/auth-register.phtml @@ -1,10 +1,12 @@ context->transport->success === true): ?> -

Congratulations, you are registered.

+

Congratulations, your account was created.

context->transport->emailActivation): ?>

Please wait for activation e-mail.

- - context->transport->adminActivation): ?> -

After this, an admin will have to confirm your registration.

+ context->transport->staffActivation): ?> +

After this, your registration must be confirmed by staff.

+ + context->transport->staffActivation): ?> +

Your registration must be confirmed by staff.