2020-01-18 17:50:11 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-05-22 13:20:31 +02:00
|
|
|
namespace Shaarli\Front\Controller\Visitor;
|
2020-01-18 17:50:11 +01:00
|
|
|
|
|
|
|
use Shaarli\Front\Exception\LoginBannedException;
|
2020-07-06 08:04:35 +02:00
|
|
|
use Shaarli\Render\TemplatePage;
|
2020-01-18 17:50:11 +01:00
|
|
|
use Slim\Http\Request;
|
|
|
|
use Slim\Http\Response;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class LoginController
|
|
|
|
*
|
|
|
|
* Slim controller used to render the login page.
|
|
|
|
*
|
|
|
|
* The login page is not available if the user is banned
|
|
|
|
* or if open shaarli setting is enabled.
|
|
|
|
*/
|
2020-05-22 13:20:31 +02:00
|
|
|
class LoginController extends ShaarliVisitorController
|
2020-01-18 17:50:11 +01:00
|
|
|
{
|
|
|
|
public function index(Request $request, Response $response): Response
|
|
|
|
{
|
2020-01-26 09:06:13 +01:00
|
|
|
if ($this->container->loginManager->isLoggedIn()
|
|
|
|
|| $this->container->conf->get('security.open_shaarli', false)
|
|
|
|
) {
|
2020-06-13 13:08:01 +02:00
|
|
|
return $this->redirect($response, '/');
|
2020-01-18 17:50:11 +01:00
|
|
|
}
|
|
|
|
|
2020-01-26 09:06:13 +01:00
|
|
|
$userCanLogin = $this->container->loginManager->canLogin($request->getServerParams());
|
2020-01-18 17:50:11 +01:00
|
|
|
if ($userCanLogin !== true) {
|
|
|
|
throw new LoginBannedException();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($request->getParam('username') !== null) {
|
|
|
|
$this->assignView('username', escape($request->getParam('username')));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this
|
|
|
|
->assignView('returnurl', escape($request->getServerParam('HTTP_REFERER')))
|
2020-01-26 09:06:13 +01:00
|
|
|
->assignView('remember_user_default', $this->container->conf->get('privacy.remember_user_default', true))
|
|
|
|
->assignView('pagetitle', t('Login') .' - '. $this->container->conf->get('general.title', 'Shaarli'))
|
2020-01-18 17:50:11 +01:00
|
|
|
;
|
|
|
|
|
2020-07-06 08:04:35 +02:00
|
|
|
return $response->write($this->render(TemplatePage::LOGIN));
|
2020-01-18 17:50:11 +01:00
|
|
|
}
|
|
|
|
}
|