-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserController.php
More file actions
45 lines (38 loc) · 1.52 KB
/
UserController.php
File metadata and controls
45 lines (38 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Translation\LocaleSwitcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Bundle\SecurityBundle\Security;
class UserController extends AbstractController
{
public function __construct(
private LocaleSwitcher $localeSwitcher,
) {
}
#[Route('/change-locale/{locale}', name: 'app_user_change_locale', requirements: ['locale' => '[a-z]{2}'])]
public function changeLocale(Request $request, string $locale): Response
{
$request->getSession()->set('_locale', $locale);
return $this->redirect($request->headers->get('referer'));
}
#[Route(path: '/login', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = ($error) ? $authenticationUtils->getLastUsername() : '';
return $this->redirectToRoute('app_home_index', [
'error' => (!empty($error)) ? 'failed' : '',
'lastUsername' => $lastUsername
]);
}
#[Route(path: '/logout', name: 'app_user_logout')]
public function logout(Security $security): Response
{
$security->logout(false);
return $this->redirectToRoute('app_home_index');
}
}