我正在尝试用我的数据库用Symfony3建立一个基本的登录系统。但每次我输入正确的凭据时,我总是得到
Invalid credentials.
Bad credentials.
我也不知道原因。
下面是我的代码:
login.html.twig
{% extends 'base.html.twig' %}
{% block body %}
<div class="container-fluid" style="width: 400px">
<h2>Please Sign In</h2>
{% if error %}
<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
<form class="form-signin" method='post' action='{{path('login_check')}}'>
{% if error %}
<div class='red'>{{ error.message }}</div><br>
{% endif %}
<label for="inputName" class="sr-only">User Name</label>
<input type="email" id="email" name='_username' class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="password" name="_password" class="form-control" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Connection</button>
</form>
</div>
{% endblock %}
SecurityController
class SecurityController extends Controller
{
/**
* @Route("/login", name="login")
*/
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('Security/login.html.twig', array(
'last_username' => $lastUsername,
'error' => $error,
));
//return $this->render('F3ILCocktailBundle:Default:index.html.twig');
}
}
security.yml
security:
firewalls:
authentification:
anonymous: true
form_login:
check_path: login_check
default_target_path: admin_recette_new
login_path: login
logout:
path: logout
target: /login
pattern: ^/
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/login
security: false
main:
anonymous: true
pattern: ^/admin
provider: our_db_provider
providers:
in_memory:
memory: ~
our_db_provider:
entity:
class: "F3ILCocktailBundle:User"
property: email
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
encoders:
F3ILCocktailBundle\Entity\User:
algorithm: bcrypt
cost: 12
routing.yml
f3_il_cocktail:
resource: "@F3ILCocktailBundle/Controller/"
type: annotation
prefix: /
app:
resource: "@AppBundle/Controller/"
type: annotation
login.:
path: /login
defaults: { _controller: F3ILCocktailBundle:Security:login}
login_check:
path: /login_check
logout:
path: /logout
连接后,我希望用户继续路由admin_recette_new
,但什么都不起作用。总是得到:
Invalid credentials,
Bad credentials.
即使所有的凭证都是正确的。请问出什么事了?
发布于 2017-01-16 03:03:54
https://stackoverflow.com/questions/41662672
复制相似问题