我有与FOSUser和HWIO Bundle的symfony。在我只认证HWIO(仅限社交网络)之前,我现在需要使用表单身份验证,使用电子邮件和密码。我创建表单注册和身份验证操作,当用户注册时,通过表单,用户有电子邮件和密码(sha1),开始用户在表单登录中输入电子邮件和密码
The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?
这是我的安全,我创建编码器并创建提供商' chain_provider'他正在使用' user_dev',为' chain_provider'创建admin_secured_area。我知道为什么不工作,请帮助。我需要通过电子邮件和密码为注册用户做些什么?我做错了什么?
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
UserBundle\Entity\User:
algorithm: sha1
encode_as_base64: false
iterations: 1
Symfony\Component\Security\Core\User\User: plaintext
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
my_custom_hwi_provider:
id: app.provider.user_provider
chain_provider:
chain:
providers: [user_dev]
user_dev:
entity: { class: UserBundle\Entity\User, property: email }
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
oauth:
resource_owners:
facebook: "/login/check-facebook"
vkontakte: "/login/check-vkontakte"
login_path: /login
failure_path: /login
oauth_user_provider:
#this is my custom user provider, created from FOSUBUserProvider - will manage the
#automatic user registration on your site, with data from the provider (facebook. google, etc.)
service: app.provider.user_provider
logout: true
anonymous: true
admin_secured_area:
pattern: ^/auth/
anonymous: ~
form_login:
provider: chain_provider
login_path: /auth/login
check_path: /auth/login_check
logout:
path: /auth/logout
target: /
invalidate_session: false
access_control:
- { path: ^/auth/login$, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
这是我的SecurityController:
/**
* @Route("/auth")
*/
class SecurityController extends Controller
{
/**
* @Route("/login", name="login_route")
* @Template()
*/
public function loginAction()
{
$request = $this->getRequest();
$session = $request->getSession();
$securityContext = $this->container->get('security.context');
if ( $securityContext->isGranted('IS_AUTHENTICATED_FULLY') ) {
return $this->redirect($this->generateUrl('get_all_posts'));
}
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
} else {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}
return array(
'_last' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error,
);
}
/**
* @Route("/login_check", name="login_check")
*/
public function loginCheckAction()
{
// this controller will not be executed,
// as the route is handled by the Security system
}
这是我的模板
<h2>LOG IN</h2>
<form id="artel-list" method="post" action="{{ path('login_check') }}">
<div>
<ul>
<li>
<div><label for="username">Email</label></div>
<div class="indent"><input type="text" name="_username" id="username" value="{{ _last }}"/></div>
</li>
<li>
<div><label for="password">Password</label></div>
<div class="indent"><input type="password" name="_password" id="password" value=""/></div>
<a class="popup-link-1" href="">Forgot your password?</a>
</li>
<li class="next">
<button type="submit" id="sign-in" class="artel-button">Log in</button>
</li>
</ul>
</div>
</form>
请帮助
答案 0 :(得分:0)
您似乎并未真正呈现登录表单。我没有使用过这个特定的捆绑包,但是我已经实现了自己的捆绑包,然后我回复了:
return $this->render(
'MySecurityBundle:Security:login.html.twig',
array(
// last username entered by the user
'last_username' => $session->get(SecurityContextInterface::LAST_USERNAME),
'error' => $error,
)
);
尝试从loginAction函数返回实际渲染。