From 309a2c8e8f9725790ace5eb1d5454d344d1a2fe7 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 18 Apr 2015 13:03:27 +0200 Subject: [PATCH] More fixes ... MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- inc/classes/interfaces/login/class_LoginableUser.php | 9 +++++++++ inc/classes/main/class_BaseFrameworkSystem.php | 2 +- .../main/factories/login/class_LoginFactory.php | 10 ++++++++-- .../filter/validator/class_UserNameValidatorFilter.php | 1 - inc/classes/main/user/class_BaseUser.php | 7 ++++--- inc/classes/main/user/member/class_Member.php | 2 +- 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/inc/classes/interfaces/login/class_LoginableUser.php b/inc/classes/interfaces/login/class_LoginableUser.php index c9906c80..d1c26b32 100644 --- a/inc/classes/interfaces/login/class_LoginableUser.php +++ b/inc/classes/interfaces/login/class_LoginableUser.php @@ -32,6 +32,15 @@ interface LoginableUser extends FrameworkInterface { * @return void */ function doLogin (Requestable $requestInstance, Responseable $responseInstance); + + /** + * Check if the implementation is correct. Only the request instance is + * needed as no redirect is done here. + * + * @param $requestInstance An instance of a Requestable class + * @return + */ + function testLogin (Requestable $requestInstance); } // [EOF] diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 2e42a794..a6302248 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -1948,7 +1948,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { */ protected final function getDatabaseEntry () { // Is there an instance? - if (is_null($this->getResultInstance())) { + if (!$this->getResultInstance() instanceof SearchableResult) { // Throw an exception here throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } // END - if diff --git a/inc/classes/main/factories/login/class_LoginFactory.php b/inc/classes/main/factories/login/class_LoginFactory.php index 63db93d5..3faf50eb 100644 --- a/inc/classes/main/factories/login/class_LoginFactory.php +++ b/inc/classes/main/factories/login/class_LoginFactory.php @@ -50,10 +50,16 @@ class LoginFactory extends ObjectFactory { // Probe on member instance try { // Try to instance member login class - $loginInstance = self::createObjectByConfiguredName('user_login_class', array($requestInstance)); + $loginInstance = self::createObjectByConfiguredName('user_login_class'); + + // Test login + $loginInstance->testLogin($requestInstance); } catch (UnexpectedGuestAccountException $e) { // Then try guest login - $loginInstance = self::createObjectByConfiguredName('guest_login_class', array($requestInstance)); + $loginInstance = self::createObjectByConfiguredName('guest_login_class'); + + // Test login again + $loginInstance->testLogin($requestInstance); } // Set the instance in registry for further use diff --git a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php index c87a3a3f..256bf3d6 100644 --- a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php +++ b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php @@ -115,7 +115,6 @@ class UserNameValidatorFilter extends BaseFilter implements Filterable { // If this instance is created then the username *does* exist try { // Get a new instance - $userInstance = call_user_func_array(array($this->getConfigInstance()->getConfigEntry('user_class'), 'createMemberByUsername'), array($userName)); // Remember this user instance in our registry for later usage diff --git a/inc/classes/main/user/class_BaseUser.php b/inc/classes/main/user/class_BaseUser.php index ce67c061..bc7988a4 100644 --- a/inc/classes/main/user/class_BaseUser.php +++ b/inc/classes/main/user/class_BaseUser.php @@ -26,6 +26,7 @@ class BaseUser extends BaseFrameworkSystem implements Updateable { const EXCEPTION_USERNAME_NOT_FOUND = 0x150; const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x151; const EXCEPTION_USER_PASS_MISMATCH = 0x152; + const EXCEPTION_USER_IS_GUEST = 0x153; /** * Username of current user @@ -121,7 +122,7 @@ class BaseUser extends BaseFrameworkSystem implements Updateable { $exists = FALSE; // Is a previous result there? - if (is_null($this->getResultInstance())) { + if (!$this->getResultInstance() instanceof SearchableResult) { // Get a UserDatabaseWrapper instance $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class'); @@ -165,7 +166,7 @@ class BaseUser extends BaseFrameworkSystem implements Updateable { $exists = FALSE; // Is a previous result there? - if (is_null($this->getResultInstance())) { + if (!$this->getResultInstance() instanceof SearchableResult) { // Get a UserDatabaseWrapper instance $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class'); @@ -220,7 +221,7 @@ class BaseUser extends BaseFrameworkSystem implements Updateable { $matches = FALSE; // Is a previous result there? - if (is_null($this->getResultInstance())) { + if ((!$this->getResultInstance() instanceof SearchableResult) || ($this->getResultInstance()->count() == 0)) { // Get a UserDatabaseWrapper instance $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class'); diff --git a/inc/classes/main/user/member/class_Member.php b/inc/classes/main/user/member/class_Member.php index b88b55be..1e4a9696 100644 --- a/inc/classes/main/user/member/class_Member.php +++ b/inc/classes/main/user/member/class_Member.php @@ -55,7 +55,7 @@ class Member extends BaseUser implements ManageableMember, Registerable { throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND); } elseif ($userInstance->isGuest() === TRUE) { // User should not be a guest here - throw new UnexpectedGuestAccountException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND); + throw new UnexpectedGuestAccountException(array($userInstance, $userName), self::EXCEPTION_USER_IS_GUEST); } // Return the instance -- 2.39.2