From 2a51a8f9f2096688bb2729f3a854a59a58747343 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 14 Feb 2013 20:38:47 +0100 Subject: [PATCH] UserAuthenticationFactory is now a SingletonFactory --- com.woltlab.wcf/coreObject.xml | 3 ++ .../files/lib/acp/form/LoginForm.class.php | 2 +- .../system/session/SessionHandler.class.php | 2 +- .../UserAuthenticationFactory.class.php | 45 +++++++++++-------- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/com.woltlab.wcf/coreObject.xml b/com.woltlab.wcf/coreObject.xml index 6f75bc6d48..212aece5ac 100644 --- a/com.woltlab.wcf/coreObject.xml +++ b/com.woltlab.wcf/coreObject.xml @@ -16,5 +16,8 @@ + + + diff --git a/wcfsetup/install/files/lib/acp/form/LoginForm.class.php b/wcfsetup/install/files/lib/acp/form/LoginForm.class.php index d352c06d1e..5e03f77180 100755 --- a/wcfsetup/install/files/lib/acp/form/LoginForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/LoginForm.class.php @@ -81,7 +81,7 @@ class LoginForm extends AbstractForm { */ protected function validateUser() { try { - $this->user = UserAuthenticationFactory::getUserAuthentication()->loginManually($this->username, $this->password); + $this->user = UserAuthenticationFactory::getInstance()->getUserAuthentication()->loginManually($this->username, $this->password); } catch (UserInputException $e) { // TODO: create an option for the authentication with email address diff --git a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php index 8be2ac7711..ef7c05b5b9 100644 --- a/wcfsetup/install/files/lib/system/session/SessionHandler.class.php +++ b/wcfsetup/install/files/lib/system/session/SessionHandler.class.php @@ -331,7 +331,7 @@ class SessionHandler extends SingletonFactory { $sessionID = StringUtil::getRandomID(); // get user automatically - $this->user = UserAuthenticationFactory::getUserAuthentication()->loginAutomatically(call_user_func(array($this->sessionClassName, 'supportsPersistentLogins'))); + $this->user = UserAuthenticationFactory::getInstance()->getUserAuthentication()->loginAutomatically(call_user_func(array($this->sessionClassName, 'supportsPersistentLogins'))); // create user if ($this->user === null) { diff --git a/wcfsetup/install/files/lib/system/user/authentication/UserAuthenticationFactory.class.php b/wcfsetup/install/files/lib/system/user/authentication/UserAuthenticationFactory.class.php index 090d240162..b253a98c3e 100644 --- a/wcfsetup/install/files/lib/system/user/authentication/UserAuthenticationFactory.class.php +++ b/wcfsetup/install/files/lib/system/user/authentication/UserAuthenticationFactory.class.php @@ -1,45 +1,54 @@ * @package com.woltlab.wcf * @subpackage system.user.authentication * @category Community Framework */ -class UserAuthenticationFactory { +class UserAuthenticationFactory extends SingletonFactory { + /** + * user authentication class name + * @var string + */ + public $className = 'wcf\system\user\authentication\DefaultUserAuthentication'; + /** * user authentication instance * @var wcf\system\user\authentication\IUserAuthentication */ - protected static $userAuthentication = null; + protected $userAuthentication = null; /** - * Returns user authentication instance. - * - * @return wcf\system\user\authentication\IUserAuthentication + * @see wcf\system\SingletonFactory */ - public static function getUserAuthentication() { - if (static::$userAuthentication === null) { - // call loadInstance event - EventHandler::getInstance()->fireAction(__CLASS__, 'loadUserAuthentication'); - - // get default implementation - static::loadUserAuthentication(); + protected static function init() { + // call loadInstance event + EventHandler::getInstance()->fireAction($this, 'init'); + + if (!ClassUtil::isInstanceOf($this->className, 'wcf\system\user\authentication\IUserAuthentication')) { + throw new SystemException("'" . $this->className . "' does not implement 'wcf\system\user\authentication\IUserAuthentication'"); } - return static::$userAuthentication; + $this->userAuthentication = call_user_func(array($this->className, 'getInstance')); } /** - * Loads the user authentication . + * Returns user authentication instance. + * + * @return wcf\system\user\authentication\IUserAuthentication */ - protected static function loadUserAuthentication() { - static::$userAuthentication = DefaultUserAuthentication::getInstance(); + public static function getUserAuthentication() { + return $this->userAuthentication; } } -- 2.20.1