简体   繁体   English

Symfony身份验证用户表单登录

[英]Symfony Authentification Users Form Login

I have symfony with FOSUser and HWIO Bundle. 我对FOSUser和HWIO Bundle有共鸣。 And before I have authentication only HWIO(only social network), but now I need with form authentication, with email and password. 在我仅进行身份验证之前,只有HWIO(仅社交网络),但是现在,我需要表单身份验证,电子邮件和密码。 I create form registration and authentication action, and when user registration, by form, user have email and password (sha1), begin user enter email and password in form login 我创建表单注册和身份验证操作,并且当用户通过表单注册时,用户具有电子邮件和密码(sha1),开始用户在表单登录中输入电子邮件和密码

The controller must return a response (null given). Did you forget to add a return statement somewhere in your controller?

this is my security, I create encoders and create providers 'chain_provider' he is use 'user_dev', create admin_secured_area for 'chain_provider' and I know understand why not work, help please. 这是我的安全,我创建编码器并创建提供程序“ chain_provider”,他正在使用“ user_dev”,为“ chain_provider”创建admin_secured_area,我知道为什么不起作用,请帮忙。 what I need to do for registration user by email and password ? 通过电子邮件和密码注册用户需要做什么? What am I doing wrong? 我究竟做错了什么?

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 }

this is my SecurityController: 这是我的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
}

this is my template 这是我的模板

<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>

help please 请帮助

You don't appear to actually be rendering the login form. 您似乎并未真正呈现登录表单。 I haven't used this specific bundle, but I have implemented my own, and I return: 我没有使用这个特定的捆绑包,但是我实现了自己的捆绑包,然后返回:

    return $this->render(
        'MySecurityBundle:Security:login.html.twig',
        array(
            // last username entered by the user
            'last_username' => $session->get(SecurityContextInterface::LAST_USERNAME),
            'error' => $error,
        )
    );

Try returning an actual render out of the loginAction function. 尝试从loginAction函数返回实际的渲染。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM