aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front/controllers
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-01-18 17:50:11 +0100
committerArthurHoaro <arthur@hoa.ro>2020-01-26 11:34:14 +0100
commit6c50a6ccceecf54850e62c312ab2397b84d89ab4 (patch)
tree3205aa447930eab020ea04bf00082880abec5001 /application/front/controllers
parent1410dce2db310e71b5e683b0871c2f28d8807844 (diff)
downloadShaarli-6c50a6ccceecf54850e62c312ab2397b84d89ab4.tar.gz
Shaarli-6c50a6ccceecf54850e62c312ab2397b84d89ab4.tar.zst
Shaarli-6c50a6ccceecf54850e62c312ab2397b84d89ab4.zip
Render login page through Slim controller
Diffstat (limited to 'application/front/controllers')
-rw-r--r--application/front/controllers/LoginController.php46
-rw-r--r--application/front/controllers/ShaarliController.php31
2 files changed, 77 insertions, 0 deletions
diff --git a/application/front/controllers/LoginController.php b/application/front/controllers/LoginController.php
new file mode 100644
index 00000000..47fa3ee3
--- /dev/null
+++ b/application/front/controllers/LoginController.php
@@ -0,0 +1,46 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller;
6
7use Shaarli\Front\Exception\LoginBannedException;
8use Slim\Http\Request;
9use Slim\Http\Response;
10
11/**
12 * Class LoginController
13 *
14 * Slim controller used to render the login page.
15 *
16 * The login page is not available if the user is banned
17 * or if open shaarli setting is enabled.
18 *
19 * @package Front\Controller
20 */
21class LoginController extends ShaarliController
22{
23 public function index(Request $request, Response $response): Response
24 {
25 if ($this->ci->loginManager->isLoggedIn() || $this->ci->conf->get('security.open_shaarli', false)) {
26 return $response->withRedirect('./');
27 }
28
29 $userCanLogin = $this->ci->loginManager->canLogin($request->getServerParams());
30 if ($userCanLogin !== true) {
31 throw new LoginBannedException();
32 }
33
34 if ($request->getParam('username') !== null) {
35 $this->assignView('username', escape($request->getParam('username')));
36 }
37
38 $this
39 ->assignView('returnurl', escape($request->getServerParam('HTTP_REFERER')))
40 ->assignView('remember_user_default', $this->ci->conf->get('privacy.remember_user_default', true))
41 ->assignView('pagetitle', t('Login') .' - '. $this->ci->conf->get('general.title', 'Shaarli'))
42 ;
43
44 return $response->write($this->ci->pageBuilder->render('loginform'));
45 }
46}
diff --git a/application/front/controllers/ShaarliController.php b/application/front/controllers/ShaarliController.php
new file mode 100644
index 00000000..2a166c3c
--- /dev/null
+++ b/application/front/controllers/ShaarliController.php
@@ -0,0 +1,31 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller;
6
7use Shaarli\Container\ShaarliContainer;
8
9abstract class ShaarliController
10{
11 /** @var ShaarliContainer */
12 protected $ci;
13
14 /** @param ShaarliContainer $ci Slim container (extended for attribute completion). */
15 public function __construct(ShaarliContainer $ci)
16 {
17 $this->ci = $ci;
18 }
19
20 /**
21 * Assign variables to RainTPL template through the PageBuilder.
22 *
23 * @param mixed $value Value to assign to the template
24 */
25 protected function assignView(string $name, $value): self
26 {
27 $this->ci->pageBuilder->assign($name, $value);
28
29 return $this;
30 }
31}