/** * */ public function authenticateByToken($authToken) { list($identifier, $token) = explode(':', $authToken); $now = time(); $theLogin = $this->getByIdentifierAndToken($identifier, $token); if (!$theLogin) { \Lib\AppFactory::log()->error(new \Exception('Could not find a login for the given token.')); return false; } elseif ($theLogin['timeout'] < $now) { \Lib\AppFactory::log()->error(new \Exception('Authentication timeout.')); return false; } $authToken = $this->generateAuthenticationToken($theLogin); return array('token' => $authToken, 'timeout' => $theLogin['timeout'], 'loginId' => $theLogin['loginId']); }
/** * */ public function init() { parent::init(); \Lib\Hooks::instance()->addAnswer('Cookies.Path', '/'); /** * Setup database connection parameters. */ $this->setupDbParams(); /** * Load the INI file located in the application's hidden root directory. */ $this->loadIni(); /** * Load applicaiton parameters in the Core domain. * Core is totally arbitrary, any name can be used. */ parent::loadAppParams('Core'); /** * Initialize error reporting */ $app = \Lib\AppFactory::app(); $app->displayErrors(\Lib\Hooks::instance()->ask('Debug.Enabled', 'false')); if (\Lib\Hooks::instance()->ask('Debug.ErrorReporting', 'false') == 'false') { $app->errorReporting(0); } /** * Routes */ $this->registerRoute("/home", 'MainController')->get(); /** * If the application will use the provided menu system; this is a good place to * create the link to the home or dashboard page. */ // $dashboard = new MainMenuItem( 'home', 'home', '/', \App\Helpers\MyUser::VISITOR, 'fa-home' ); // MainMenu::instance()->add( $dashboard, 1 ); }
/** * */ public function isAuthenticated() { $app = \Lib\AppFactory::app(); $authCookie = $app->request()->cookies($this->authCookieName); if (!$authCookie) { return false; } $loginModel = DataFactory::model('Authentication.Logins'); $authentication = $loginModel->authenticateByToken($authCookie); if (!$authentication) { return false; } return $authentication; }
die("Invalid domain: " . BASE_PATH); } if (!defined('LIB_PATH')) { /** * Location of the a3gFramework's library. */ define('LIB_PATH', dirname(PRIVATE_PATH) . DS . 'Lib' . DS); } if (!defined('APP_PATH')) { /** * Location of application's files. * In a SAAS environment, the application is shared by all domains. */ define('APP_PATH', PRIVATE_PATH . 'App' . DS); } if (!defined('PLUGIN_PATH')) { /** * Location of plugin files. * In a SAAS environment, plugins are specific to each client's domain. */ define('PLUGIN_PATH', BASE_PATH . 'Plugins' . DS); } /** * Produce an application object depending on the environment: Console or Web. */ if (!is_readable(LIB_PATH . DS . 'AppFactory.php')) { die("Not found: " . LIB_PATH . DS . 'AppFactory.php'); } include LIB_PATH . DS . 'AppFactory.php'; \Lib\AppFactory::app(php_sapi_name())->main(); // EOF
/** * */ protected function setupJsonResponse() { // Make text translator available in the controller $this->lang = \Lib\AppFactory::translator($this->app->request()->language()); $this->response = new \Lib\Http\JsonResponse(); return $this; }