我试图自己解决这个问题,但三天后,我放弃并寻求帮助..
我收到“证件不好”。 erros(详情:pastebin)
这是我的security.yml:
security:
encoders:
Common\UserBundle\Entity\User:
algorithm: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
request_users:
entity:
class: CommonUserBundle:User
property: username
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
request_security:
pattern: ^/
anonymous: ~
form_login:
check_path: _check_path
login_path: login_page
default_target_path: gemmi_start_homepage
logout:
path: _logout
target: signup_page
access_control:
#- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
我的LoginController:
<?php
namespace Common\UserBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\HttpFoundation\Request;
class LoginController extends Controller
{
public function indexAction(Request $Request)
{
$Session = $this->get('session');
if($Request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) {
$loginError = $Request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR);
} else {
$loginError = $Session->remove(SecurityContextInterface::AUTHENTICATION_ERROR);
}
$userName = $Session->get(SecurityContextInterface::LAST_USERNAME);
echo $loginError;
return $this->render('CommonUserBundle::login.html.twig', array(
'loginError' => $loginError,
'userName' => $userName
));
}
}
还有我的routing.yml:
login_page:
path: /login
defaults: { _controller: CommonUserBundle:Login:index }
signup_page:
path: /signup
defaults: { _controller: CommonUserBundle:Login:signup }
_check_path:
path: /login-check
_logout:
path: /logout
和:
gemmi_start_homepage:
path: /
defaults: { _controller: GemmiStartBundle:Default:index }
我的表格:
<form method="post" action="{{ path('_check_path') }}" name="contactform" id="contactform">
<fieldset>
<label for="login" accesskey="E"></label>
<input name="_username" type="text" id="login" size="30" value="{{ userName }}" placeholder="{% trans %} nickname {% endtrans %}" />
<br> <br>
<label for="passwd" accesskey="E"></label>
<input name="_password" type="password" id="passwd" size="30" value="" placeholder="{% trans %} password {% endtrans %}" />
<br> <br>
<button type="submit" class="submit btn btn-send" id="submit" value="Submit">
<i class="fa fa-user"></i>
{% trans %} log_in {% endtrans %}
</button>
</fieldset>
</form>
用户实体:pastebin
最后一个 - UserFixtures:pastebin
我知道有很多东西需要检查,但有人可以帮助我吗?
答案 0 :(得分:1)
您是否注意到您错过了firewalls:
文件中名为security.yml
的特定选项?或者你在粘贴代码时意外地将其遗漏了?语法应如下所示:
providers:
request_users:
entity:
class: CommonUserBundle:User
property: username
firewalls:
# your firewalls definitions goes here.
我快速应用了您的配置,并设法传递了表单。虽然我没有完全认证,但它没有给我Bad credentials
的错误。尝试编辑您的文件(如果确实缺少该行),看看会发生什么。如果情况并非如此,我们将继续进一步调查此问题。