/** * Form based authentication * * @param \Strong\Strong $auth * @param object $req */ private function formAuth($auth, $req) { $app = $this->app; $config = $this->config; $this->app->hook('slim.before.router', function () use($app, $auth, $req, $config) { $secured_urls = isset($config['security.urls']) && is_array($config['security.urls']) ? $config['security.urls'] : array(); foreach ($secured_urls as $surl) { $patternAsRegex = $surl['path']; if (substr($surl['path'], -1) === '/') { $patternAsRegex = $patternAsRegex . '?'; } $patternAsRegex = '@^' . $patternAsRegex . '$@'; if (preg_match($patternAsRegex, $req->getPathInfo())) { if (!$auth->loggedIn()) { if ($req->getPath() !== $config['login.url']) { $app->redirect($config['login.url']); } } } } }); $this->next->call(); }
public function testLoggedIn() { $strong = new Strong(array('provider' => 'mock')); \Strong\Provider\Mock::$logged = true; $this->assertTrue($strong->loggedIn()); }