From 7784be18387bbec9c43e7779d79aea12c1177342 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Mon, 5 May 2014 08:25:52 +0200 Subject: [PATCH] Fixed login when mail activation is enabled --- src/Access.php | 25 ++++++++++++++++++------- src/Auth.php | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Access.php b/src/Access.php index 44e85cec..833343f9 100644 --- a/src/Access.php +++ b/src/Access.php @@ -32,12 +32,14 @@ class Access } } - public static function check(Privilege $privilege) + public static function check(Privilege $privilege, $user = null) { if (php_sapi_name() == 'cli') return true; - $user = Auth::getCurrentUser(); + if ($user === null) + $user = Auth::getCurrentUser(); + $minAccessRank = AccessRank::Nobody; $key = TextCaseConverter::convert($privilege->toString(), @@ -58,22 +60,31 @@ class Access return $user->getAccessRank()->toInteger() >= $minAccessRank; } + public static function checkEmailConfirmation($user = null) + { + if ($user === null) + $user = Auth::getCurrentUser(); + + if (!$user->emailConfirmed) + return false; + return true; + } + public static function assertAuthentication() { if (!Auth::isLoggedIn()) self::fail('Not logged in'); } - public static function assert(Privilege $privilege) + public static function assert(Privilege $privilege, $user = null) { - if (!self::check($privilege)) + if (!self::check($privilege, $user)) self::fail(); } - public static function assertEmailConfirmation() + public static function assertEmailConfirmation($user = null) { - $user = Auth::getCurrentUser(); - if (!$user->emailConfirmed) + if (!self::checkEmailConfirmation($user)) self::fail('Need e-mail address confirmation to continue'); } diff --git a/src/Auth.php b/src/Auth.php index 951ee42a..c91f33be 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -28,7 +28,7 @@ class Auth throw new SimpleException('You are banned'); if ($config->registration->needEmailForRegistering) - Access::requireEmail($user); + Access::assertEmailConfirmation($user); if ($remember) {