Я хочу перейти на страницу администратора.Я иду в URL / админ.Я перенаправлен на страницу входа.И теперь проблема, я заполняю форму, нажимаю на логин и перенаправляюсь на страницу индекса не на / admin и не аутентифицируюсь.
Я использую symfony3.4 и form_login.Я посмотрел в профилировщике, и мне кажется, что вход в систему работает, но сразу после этого я выхожу из системы.
Сеансы: https://imgur.com/yJDRBxT
Безопасность при отправке запроса на /логин: https://imgur.com/tnrcYMH
на индексной странице после логина: https://imgur.com/RJTFRim
config / security.yml
security:
providers:
in_memory:
memory:
users:
admin:
password: $2y$13$xAvoz5UgaciMjR2wCashoOcdOku13ieKsRPMlNh7.uimmDmojkYCi
roles: 'ROLE_ADMIN'
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
form_login:
login_path: login
check_path: login
logout:
path: /logout
target: /
anonymous: ~
logout_on_user_change: true
encoders:
Symfony\Component\Security\Core\User\User: bcrypt
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
routing.yml
login:
path: /login
defaults: { _controller: AdminBundle:Security:login }
login_check:
path: /login
logout:
path: /logout
easyadmin.entryPoint:
path: /admin/entryPoint
defaults: { _controller: AdminBundle:Admin:entryPoint }
easy_admin_bundle:
resource: '@AdminBundle/Controller/AdminController.php'
type: annotation
prefix: /admin
SecurityController
<?php
namespace AdminBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class SecurityController extends Controller
{
/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public function loginAction()
{
$authenticationUtils = $this->get('security.authentication_utils');
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('@Admin/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
]);
}
}
login.html.twig
{% extends '@App/base.html.twig' %}
{% block stylesheets %}
{{ parent() }}
{{ encore_entry_link_tags('admin_bundle_login') }}
{% endblock %}
{% block body %}
<form id="login-form" action="{{ path('login') }}" method="post">
<div id="username">
<label for="username">Username:</label>
<input type="text" id="username" name="_username" value="{{ last_username }}"/>
</div>
<div id="password">
<label for="password">Password:</label>
<input type="password" id="password" name="_password"/>
</div>
{% if error %}
<div id="login-error">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
<button type="submit" id="login-submit">login</button>
</form>
{% endblock %}
dev.log
[2019-03-31 12:32:58] request.INFO: Matched route "login". {"route":"login","route_parameters":{"_controller":"AdminBundle\\Controller\\SecurityController::loginAction","_route":"login"},"request_uri":"http://localhost:8000/admin/login","method":"GET"} []
[2019-03-31 12:32:58] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2019-03-31 12:32:58] request.INFO: Matched route "_wdt". {"route":"_wdt","route_parameters":{"_controller":"web_profiler.controller.profiler:toolbarAction","token":"ff647b","_route":"_wdt"},"request_uri":"http://localhost:8000/_wdt/ff647b","method":"GET"} []
[2019-03-31 12:33:11] request.INFO: Matched route "login". {"route":"login","route_parameters":{"_controller":"AdminBundle\\Controller\\SecurityController::loginAction","_route":"login"},"request_uri":"http://localhost:8000/admin/login","method":"POST"} []
[2019-03-31 12:33:11] security.INFO: User has been authenticated successfully. {"username":"admin"} []
[2019-03-31 12:33:11] security.DEBUG: Stored the security token in the session. {"key":"_security_main"} []
[2019-03-31 12:33:11] request.INFO: Matched route "index". {"route":"index","route_parameters":{"_controller":"AppBundle\\Controller\\DefaultController::indexAction","_route":"index"},"request_uri":"http://localhost:8000/","method":"GET"} []
[2019-03-31 12:33:11] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2019-03-31 12:33:12] request.INFO: Matched route "_wdt". {"route":"_wdt","route_parameters":{"_controller":"web_profiler.controller.profiler:toolbarAction","token":"03981c","_route":"_wdt"},"request_uri":"http://localhost:8000/_wdt/03981c","method":"GET"} []
[2019-03-31 12:33:12] request.INFO: Matched route "ajaxProvider". {"route":"ajaxProvider","route_parameters":{"_controller":"AppBundle\\Controller\\DefaultController::ajaxProviderAction","_route":"ajaxProvider"},"request_uri":"http://localhost:8000/slots.json","method":"GET"} []
[2019-03-31 12:33:12] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
[2019-03-31 12:33:13] request.INFO: Matched route "ajaxProvider". {"route":"ajaxProvider","route_parameters":{"_controller":"AppBundle\\Controller\\DefaultController::ajaxProviderAction","_route":"ajaxProvider"},"request_uri":"http://localhost:8000/slots.json","method":"GET"} []
[2019-03-31 12:33:13] security.INFO: Populated the TokenStorage with an anonymous Token. [] []
Я ожидаю аутентификацию после входа в систему