/** * @return string */ public function helper() { $request = Application::getInstance()->getRouter()->getRequest(); $template = new Template('CatLab/OpenIDClient/helpers/welcome.phpt'); $template->set('user', $request->getUser()); $template->set('logout', URLBuilder::getURL($this->moduleController->getRoutePath() . '/logout')); $template->set('login', URLBuilder::getURL($this->moduleController->getRoutePath() . '/login', array('return' => $request->getUrl()))); return $template; }
/** * Set template paths, config vars, etc * @param string $routepath The prefix that should be added to all route paths. * @return void */ public function initialize($routepath) { // Set path $this->routepath = $routepath; // Add templates Template::addPath(__DIR__ . '/../templates/', 'CatLab/OAuth2/'); Application::getInstance()->on('dispatch:before', array($this, 'setRequestUser')); // Add locales Text::getInstance()->addPath('catlab.oauth2', __DIR__ . '/locales/'); $this->setErrorResponder(new JSON()); }
/** * Set template paths, config vars, etc * @param string $routepath The prefix that should be added to all route paths. * @return void */ public function initialize($routepath) { $this->routepath = $routepath; Template::addPath(__DIR__ . '/templates/', 'CatLab/OpenIDClient/'); // Set session variable Application::getInstance()->on('dispatch:before', array($this, 'setRequestUser')); // Set the global user mapper, unless one is set already Application::getInstance()->on('dispatch:first', array($this, 'setUserMapper')); // Add helper methods $helper = new LoginForm($this); Template::addHelper('CatLab.OpenIDClient.LoginForm', $helper); }
/** * Set template paths, config vars, etc * @param string $routepath The prefix that should be added to all route paths. * @return void */ public function initialize($routepath) { // Set path $this->routepath = $routepath; // Add templates Template::addPath(__DIR__ . '/templates/', 'CatLab/Accounts/'); // Add locales Text::getInstance()->addPath('catlab.accounts', __DIR__ . '/locales/'); // Set session variable Application::getInstance()->on('dispatch:before', array($this, 'setRequestUser')); // Set the global user mapper, unless one is set already Application::getInstance()->on('dispatch:first', array($this, 'setUserMapper')); // Add helper methods $helper = new LoginForm($this); Template::addHelper('CatLab.Accounts.LoginForm', $helper); }
/** * @return string */ public function helper() { $request = Application::getInstance()->getRouter()->getRequest(); $user = $request->getUser(); if (!$user) { // The helper should also check for non verified users. $userId = $request->getSession()->get('catlab-non-verified-user-id'); if ($userId) { $user = MapperFactory::getUserMapper()->getFromId($userId); } } if ($user) { $template = new Template('CatLab/Accounts/helpers/welcome.phpt'); $template->set('user', $user); $template->set('logout', URLBuilder::getURL($this->moduleController->getRoutePath() . '/logout')); return $template; } else { $template = new Template('CatLab/Accounts/helpers/form-small.phpt'); $authenticators = $this->moduleController->getAuthenticators(); $authenticators->setRequest($request); $template->set('authenticators', $authenticators); return $template; } }
private function storeAccessTokenInSession(\OAuth2\ResponseInterface $response) { $location = $response->getHttpHeader('Location'); $parsed = parse_url($location); if (isset($parsed['fragment'])) { $fragment = $parsed['fragment']; } else { $fragment = $parsed['query']; } parse_str($fragment, $attributes); if (isset($attributes['access_token'])) { //$_SESSION['oauth2_access_token'] = $attributes['access_token']; Application::getInstance()->getRouter()->getRequest()->getSession()->set('oauth2_access_token', $attributes['access_token']); } }
<?php error_reporting(E_ALL); $loader = (require_once '../../vendor/autoload.php'); // Start the app $app = \Neuron\Application::getInstance(); // Set config folder \Neuron\Config::folder(__DIR__ . '/../config/'); // Optionally, set an environment $hostname = trim(file_get_contents('/etc/hostname')); switch ($hostname) { case 'my-computer': case 'thijs-home-i7': case 'thijs-i7': \Neuron\Config::environment('development'); break; } // Set the template folder \Neuron\Core\Template::addPath(__DIR__ . '/../templates/'); // Always set a locale $app->setLocale('nl_BE.utf8'); // Load the router $app->setRouter(include 'router.php'); // Return app return $app;
<?php // Initialize router $router = new \Neuron\Router(); // Accounts module $signinmodule = new \CatLab\Accounts\Module(); $signinmodule->requireEmailValidation(); //$signinmodule->setLayout ('index-account.phpt'); $password = new \CatLab\Accounts\Authenticators\Password(); $signinmodule->addAuthenticator($password); $facebook = new \CatLab\Accounts\Authenticators\Facebook(); $signinmodule->addAuthenticator($facebook); $steam = new \CatLab\Accounts\Authenticators\Steam(); $signinmodule->addAuthenticator($steam); $mailer = new \CatLab\Mailer\Module(); $router->module('/mailer', $mailer); // Make the module available on /account $router->module('/account', $signinmodule); $router->get('/thirdparty', function () { $request = \Neuron\Application::getInstance()->getRouter()->getRequest(); $deligatedAccounts = $request->getUser()->getDeligatedAccounts(); return \Neuron\Net\Response::template('thirdparty.phpt', array('accounts' => $deligatedAccounts)); })->filter('authenticated'); // Catch the default route $router->get('/', function () { return \Neuron\Net\Response::template('home.phpt'); }); return $router;
/** * @throws DataNotSet * @return \Neuron\Net\Session */ public function getSession() { if (!isset($this->session)) { // First check the router if ($this instanceof Response) { $router = Application::getInstance()->getRouter(); if ($router) { $this->session = $router->getRequest()->getSession(); } } else { throw new DataNotSet("No session is set in the request."); } } return $this->session; }