/** * @covers Authentication::getLoginController * @todo Implement testGetLoginController(). */ public function testGetLoginController() { $aclxml = dirname(dirname(dirname(dirname(__FILE__)))) . '/testfiles/test_aclxml.xml'; Authentication::setAclXml($aclxml); $result = Authentication::getLoginController("test_module2"); $compare = "UserLogin"; $this->assertEquals($result, $compare); }
/** * Constructor of the class. * @param string $formId * @param string $formName * @param string $uidLabel * @param string $pwdLabel * @param string $moduleName * @param string $formDecoration * @param string $loginMsgId * @param string $formAction */ public function __construct($formId = null, $formName = null, $uidLabel = null, $pwdLabel = null, $moduleName = null, $formDecoration = null, $loginMsgId = null, $formAction = null) { $this->_formId = is_null($formId) ? self::DEFAULT_LOGIN_FORM_ID : $formId; $formName = is_null($formName) ? $this->_formId : $formName; $this->_loginMsgId = is_null($loginMsgId) ? self::DEFAULT_LOEGIN_MESSAGE_ID : $loginMsgId; parent::__construct($formId); $moduleName = !is_null($moduleName) ? $moduleName : MvcReg::getModuleName(); $signInActionName = Authentication::getSignInAction($moduleName); $loginControllerName = Authentication::getLoginController($moduleName); $formAction = is_null($formAction) ? PathService::getFormActionURL($moduleName, $loginControllerName, $signInActionName) : $formAction; if (is_null($uidLabel) || $uidLabel == "") { $uidLabel = self::DEFAULT_UID; } if (is_null($pwdLabel) || $pwdLabel == "") { $pwdLabel = self::DEFAULT_PWD; } $this->_formDecoration = $formDecoration; $this->createForm($formAction, $this->_formId, $formName, $uidLabel, $pwdLabel, $moduleName, $this->_loginMsgId); }
/** * The forward function is to call the action according to the module, controller and action. * The function needs to consider all the forward restrictions and rules. * * @param string $moduleName the forwarding module name * @param string $controllerName the forwarding controller name * @param string $actionName the forwarding action name * @param array $params the url params * @param object $router an instance of Router the default value = null * */ public static function forward($moduleName, $controllerName, $actionName, $params, $router = null) { $Router = is_null($router) ? new Router() : $router; $Router->setDefaultModelView($controllerName); $controller = $controllerName . self::CONTROLLER_POSTFIX; $action = $actionName . self::ACTION_POSTFIX; $controllerfile = RouterHelper::getControllerFile($moduleName, $controller); try { if (file_exists($controllerfile)) { require_once $controllerfile; //Check special Authentication controller /* * If status */ $Config = Config::getInstance(); $auth_array = $Config->getAuthenticationConfig(); if ($auth_array['use_authentication'] == "enable") { /** * if the controller and actions are those login related ones, * we exclude them, let them dispatch. */ if (Authentication::isLogin($moduleName)) { // need to acl rule after login // put them here // if (Authentication::getSuccessController($moduleName) == $controllerName && Authentication::getSuccessAction($moduleName) == $actionName) { Dispatcher::setRoute($moduleName, $controllerName, $actionName); } Dispatcher::toMVC($controller, $action, $params); return; } else { //all allowed actions that are defined in acl.xml $allows = Authentication::getAllAllows($moduleName); //Change the controllerName to ControllerName //because the router already transform the value $controllerName = ucfirst($controllerName); //Dispatch sequence - checking allowing actions before checking login related actions //(1) Check acl access exclusions //Case #1: allow all controllers in the module if ($allows == self::ALL_CONTROLLERS) { Dispatcher::toMVC($controller, $action, $params); return; } //Case #2: allow all actions in a specific controller if (isset($allows[$controllerName]) && $allows[$controllerName] == self::ALL_ACTIONS) { Dispatcher::toMVC($controller, $action, $params); return; } //Case #3: allow a specific action in a specific controller if (isset($allows[$controllerName])) { $allowActions = $allows[$controllerName]; foreach ($allowActions as $idx => $allowAction) { //echo "{$allowAction}=={$actionName}"; if ($allowAction == $actionName) { Dispatcher::toMVC($controller, $action, $params); return; } } } //Case #4: Special cases, passing the actions in layout (due to using http request to get view) if (isset(Authentication::$layoutAllows[$moduleName][$controllerName])) { $allowActions = Authentication::$layoutAllows[$moduleName][$controllerName]; foreach ($allowActions as $idx => $allowAction) { if ($allowAction == $actionName) { //unset the action Authentication::removeLayoutAllowAction($moduleName, $controllerName, $actionName); Dispatcher::toMVC($controller, $action, $params); return; } } } //(2) Check login related actions $loginActions = Authentication::getLoginExcludeActions($moduleName); if (isset($loginActions[$controllerName][$actionName])) { Dispatcher::toMVC($controller, $action, $params); return; } //(3) None of above satisfies, forward to login controller action $loginControllerName = Authentication::getLoginController($moduleName); $loginController = Authentication::getLoginController($moduleName) . self::CONTROLLER_POSTFIX; $loginActionName = Authentication::getLoginAction($moduleName); $loginAction = Authentication::getLoginAction($moduleName) . self::ACTION_POSTFIX; Dispatcher::setRoute($moduleName, $loginControllerName, $loginActionName); Dispatcher::toMVC($loginController, $loginAction, $params); } } else { Dispatcher::toMVC($controller, $action, $params); } } else { $errorMsg = "Controller {$controller} or controller file {$controllerfile} is missing"; throw new AiryException($errorMsg); } } catch (Exception $e) { $errorMsg = "<h3><b>Dispatching ERROR!</b></h3>" . $e->getMessage(); $ifDisplayError = $Config = Config::getInstance()->getDisplayError(); if ($ifDisplayError == "enable") { echo $errorMsg; } } }