openrat-cms

OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs | README

commit 4f16d999948f5a3b36f6884f79ab0ae821d4b455
parent a8555cdcda61e3f80b7cbd3e4c51b49c6195057d
Author: Jan Dankert <develop@jandankert.de>
Date:   Mon, 16 Nov 2020 16:34:36 +0100

Missing the AuthRunner since last commit.

Diffstat:
Amodules/cms/auth/AuthRunner.class.php | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+), 0 deletions(-)

diff --git a/modules/cms/auth/AuthRunner.class.php b/modules/cms/auth/AuthRunner.class.php @@ -0,0 +1,67 @@ +<?php + + +namespace cms\auth; + + +use cms\base\Configuration; +use logger\Logger; + +class AuthRunner +{ + protected static function getModulesFor($section, $callback ) + { + $securityConfig = Configuration::subset('security'); + + $modules = $securityConfig->subset($section )->get('modules',[]); + + foreach ($modules as $module) { + + $moduleClass = Auth::NS . '\\' . $module . 'Auth'; + + if (!class_exists($moduleClass)) { + throw new \LogicException('module is not available: ' . $moduleClass ); + } + + /** @var \cms\auth\Auth $auth */ + $auth = new $moduleClass; + $result = $callback( $auth ); + + if ( $result ) + return $result; + + // next module. + } + + return null; + } + + + public static function getUsername( $section ) { + + return self::getModulesFor(/** + * @param $auth Auth + */ $section, function($auth) { + $username = $auth->username(); + + if ($username) + Logger::debug('Preselecting User ' . $username . ' from ' . get_class($auth) ); + + return $username; + }); + } + + + public static function checkLogin( $section, $user,$password,$token ) { + + return self::getModulesFor($section, /** + * @param $auth Auth + * @return null|boolean|int + */ function($auth) use ($token, $password, $user) { + Logger::info('Trying to login with module '.get_class($auth)); + + return $auth->login($user,$password,$token); + } + ); + } +}+ \ No newline at end of file