dounei9043 2019-06-25 16:18
浏览 88

[symfony]连接注册在同一页面上?

I do have a problem with my symfony code, I'm actually searching how to put two forms, one for connections and one for login on the same page and this shows me error if I submit the register form, because it is the specified page in security.yaml : here is the code for my register form...

class SecurityController extends AbstractController
{
    /**
     * @Route("/", name="register_login")
     */
    public function register(UserPasswordEncoderInterface $hasher,
    Request $request, ObjectManager $manager)
    {
        $userInfos = new UserInfos();        
        $form = $this->createForm(RegistrationType::class, $userInfos);
        $form->handleRequest($request);
        if($form->isSubmitted() && $form->isValid())
        {
            $userInfos->setLastConnection(new \DateTime());
            $userInfos->setSubscribedAt(new \DateTime());
            $userInfos->setPassword($hasher->encodePassword($userInfos,
            $userInfos->getPassword()));
            $manager->persist($userInfos);
            $manager->flush();
        }
        return $this->render('security/login.html.twig', [
            'formUser' => $form->createView()
        ]);
    }
}

and it returns the twig file with the login form...

<form class="form-inline my-2 my-lg-0" action="{{ path('register_login') }}" method="post">
            <input class="form-control mr-sm-2" required type="email" name="_username" placeholder="Email">
            <input class="form-control mr-sm-2" required type="password" name="_password" placeholder="Mot de passe">
            <button class="btn btn-success my-2 my-sm-0" type="submit">Connexion</button>
        </form>

My security.yaml config: security: encoders: App\Entity\UserInfos: algorithm: bcrypt

# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
    in_memory: { memory: ~ }
    DB:
        entity:
            class: App\Entity\UserInfos
            property: email
firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false
    main:
        anonymous: true
        provider: DB
        form_login:
            login_path: register_login
            check_path: register_login

Thanks for your attention.

  • 写回答

1条回答 默认 最新

  • douyi0219 2019-06-25 20:37
    关注

    You put 2 form in twig, you must put the form in one controller (may be register)

    Put $formRegister->createView(); $formLogin->createView() in your template.

    the action of one form is in {{ path('register...') }} and login in {{ path('login') }}

    but pay attention you must control all variable else its show you an error

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序