Skip to content

Commit d14bd92

Browse files
committed
feat: enabled logging in on browswers
1 parent 1173784 commit d14bd92

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

config/packages/security.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ security:
2222

2323
# https://symfony.com/doc/current/security/impersonating_user.html
2424
# switch_user: true
25+
form_login:
26+
login_path: app_login
27+
check_path: app_login
2528

2629
# Easy way to control access for large sections of your site
2730
# Note: Only the *first* access control that matches will be used

src/Controller/LoginController.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Controller;
4+
5+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
6+
use Symfony\Component\HttpFoundation\Response;
7+
use Symfony\Component\Routing\Annotation\Route;
8+
9+
class LoginController extends AbstractController
10+
{
11+
#[Route('/login', name: 'app_login')]
12+
public function index(): Response
13+
{
14+
return $this->render('login/index.html.twig');
15+
}
16+
}

templates/login/index.html.twig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% extends 'base.html.twig' %}
2+
3+
{% block body %}
4+
<form action="{{ path('app_login') }}" method="post">
5+
<label for="username">Email:</label>
6+
<input type="text" id="username" name="_username">
7+
8+
<label for="password">Password:</label>
9+
<input type="password" id="password" name="_password">
10+
11+
<input type="hidden" name="_target_path" value="/profile">
12+
13+
<button type="submit">login</button>
14+
</form>
15+
{% endblock %}

tests/Controller/ProfileControllerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ public function test(): void
4343
public function testNotAuthenticated(): void
4444
{
4545
$this->client->request('GET', '/profile');
46-
$this->assertEquals(401, $this->client->getResponse()->getStatusCode());
46+
$this->assertTrue($this->client->getResponse()->isRedirect('http://localhost/login'));
4747
}
4848
}

0 commit comments

Comments
 (0)