webcron/src/Controller/SecurityController.php

33 lines
1.1 KiB
PHP
Raw Normal View History

2021-04-06 19:33:20 +02:00
<?php
namespace JeroenED\Webcron\Controller;
use JeroenED\Framework\Controller;
2021-04-08 12:54:49 +02:00
use JeroenED\Webcron\Repository\User;
2021-04-06 23:19:51 +02:00
use Symfony\Component\HttpFoundation\RedirectResponse;
2021-04-06 19:33:20 +02:00
use Symfony\Component\HttpFoundation\Response;
class SecurityController extends Controller
{
public function loginAction(): Response
{
2021-04-06 23:19:51 +02:00
if(isset($_SESSION['isAuthenticated']) && $_SESSION['isAuthenticated']) {
return new RedirectResponse($this->generateRoute('default'));
}
2021-04-06 19:33:20 +02:00
return $this->render('security/login.html.twig');
}
2021-04-07 13:31:57 +02:00
public function loginCheckAction(): Response
{
2021-04-08 12:54:49 +02:00
$request = $this->getRequest();
$userRepository = new User($this->getDbCon());
$credentials = $request->request->all();
if($userRepository->checkAuthentication($credentials['name'], $credentials['passwd'])) {
$_SESSION['isAuthenticated'] = true;
return new RedirectResponse($this->generateRoute('default'));
}
2021-04-08 16:34:25 +02:00
$this->addFlash('danger', 'Username or password incorrect');
2021-04-08 12:54:49 +02:00
return new RedirectResponse($this->generateRoute('login'));
2021-04-07 13:31:57 +02:00
}
2021-04-06 19:33:20 +02:00
}