From: Roland Haeder Date: Sat, 18 Apr 2015 11:03:58 +0000 (+0200) Subject: Use testLogin(), if no exception comes the login helper may do the login. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4e26150662bc2955327e1040d2a3529aba5626e5;p=city.git Use testLogin(), if no exception comes the login helper may do the login. Signed-off-by: Roland Haeder --- diff --git a/application/city/main/login/class_CityGuestLogin.php b/application/city/main/login/class_CityGuestLogin.php index 4b8f5eb..61f00b4 100644 --- a/application/city/main/login/class_CityGuestLogin.php +++ b/application/city/main/login/class_CityGuestLogin.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class CityGuestLogin extends BaseFrameworkSystem implements LoginableUser { +class CityGuestLogin extends BaseFrameworkSystem implements LoginableUser, Registerable { /** * The hashed password */ @@ -58,42 +58,18 @@ class CityGuestLogin extends BaseFrameworkSystem implements LoginableUser { * @param $requestInstance An instance of a Requestable class * @param $responseInstance An instance of a Responseable class * @return void - * @throws UserAuthMethodException If wether username nor email login - * was detected - * @throws MissingMethodException If a method was not found in the - * User class * @throws UserPasswordMismatchException If the supplied password did not * match with the stored password */ public function doLogin (Requestable $requestInstance, Responseable $responseInstance) { - // By default no method is selected - $method = null; - $data = ""; - - // Detect login method (username or email) and try to get a userinstance - if (!is_null($requestInstance->getRequestElement('user'))) { - // Username found! - $method = 'createGuestByUsername'; - $data = $requestInstance->getRequestElement('user'); - } // END - if - - // Is a method detected? - if (is_null($method)) { - // Then abort here - throw new UserAuthMethodException($this, self::EXCEPTION_MISSING_METHOD); - } elseif (!method_exists($this->getConfigInstance()->getConfigEntry('guest_class'), $method)) { - // The method is invalid! - throw new MissingMethodException(array($this, $method), self::EXCEPTION_MISSING_METHOD); - } - // Get a user instance - $userInstance = call_user_func_array(array($this->getConfigInstance()->getConfigEntry('guest_class'), $method), array($data)); + $userInstance = UserFactory::createUserByRequest($requestInstance); // Remember this new instance in registry Registry::getRegistry()->addInstance('user', $userInstance); // Is the password correct? - if ($userInstance->ifPasswordHashMatches($requestInstance) === false) { + if ($userInstance->ifPasswordHashMatches($requestInstance) === FALSE) { // Mismatching password throw new UserPasswordMismatchException(array($this, $userInstance), BaseUser::EXCEPTION_USER_PASS_MISMATCH); } // END - if @@ -107,6 +83,18 @@ class CityGuestLogin extends BaseFrameworkSystem implements LoginableUser { $helperInstance->executeLogin($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 + */ + public function testLogin (Requestable $requestInstance) { + // Create dummy instance + $dummyInstance = Guest::createGuestByRequest($requestInstance); + } + /** * Determines wether the login was fine. This is done by checking if 'login' instance is in registry * diff --git a/application/city/main/login/class_CityUserLogin.php b/application/city/main/login/class_CityUserLogin.php index 0957e71..9901ee4 100644 --- a/application/city/main/login/class_CityUserLogin.php +++ b/application/city/main/login/class_CityUserLogin.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class CityUserLogin extends BaseFrameworkSystem implements LoginableUser { +class CityUserLogin extends BaseFrameworkSystem implements LoginableUser, Registerable { /** * The hashed password */ @@ -65,17 +65,14 @@ class CityUserLogin extends BaseFrameworkSystem implements LoginableUser { * @todo user account. */ public function doLogin (Requestable $requestInstance, Responseable $responseInstance) { - // Get member class - $userClass = $this->getConfigInstance()->getConfigEntry('user_class'); - - // Get a user instance - $userInstance = call_user_func_array(array($userClass, 'createMemberByRequest'), array($requestInstance)); + // Get a user instance from factory + $userInstance = UserFactory::createUserByRequest($requestInstance); // Remember this new instance in registry Registry::getRegistry()->addInstance('user', $userInstance); // Is the password correct? - if ($userInstance->ifPasswordHashMatches($requestInstance) === false) { + if ($userInstance->ifPasswordHashMatches($requestInstance) === FALSE) { // Mismatching password throw new UserPasswordMismatchException(array($this, $userInstance), BaseUser::EXCEPTION_USER_PASS_MISMATCH); } // END - if @@ -94,6 +91,18 @@ class CityUserLogin extends BaseFrameworkSystem implements LoginableUser { $helperInstance->executeLogin($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 + */ + public function testLogin (Requestable $requestInstance) { + // Create a dummy instance + $dummyInstance = Member::createMemberByRequest($requestInstance); + } + /** * Determines wether the login was fine. This is done by checking if 'login' instance is in registry * diff --git a/core b/core index 607732d..7852304 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 607732d1a427409037b600f2c5a17ca9846f0f5f +Subproject commit 785230449d5d2102aa803a6c09bed8c1f398c0cb