php - Same form for login and registration in FOSUserBundle -
i using newest versions of fosuserbundle , symfony2. have provide form can used login , registration. has 2 fields:
mail adress (required) password (only required login)and 2 buttons:
login registerif user enters mail service adress , clicks login, error password missing. if enters mail service adress , clicks register gets business relationship , password generated. implemented whole functionality, utilize 2 separated forms login , register.
now want merge these forms. tried far:
public function welcomeaction() { $data = array(); $form = $this->createformbuilder($data) ->add("email", "email") ->add("password", "password", array("required" => false)) ->add("register", "submit") ->add("login", "submit") ->getform(); $form->handlerequest($this->getrequest()); if ($form->isvalid()) { if ($form->get("login")->isclicked()) { homecoming $this->forward('fosuserbundle:security:check', array('_username' => $form->getdata()["email"], '_password' => $form->getdata()["password"] ) ); } else if ($form->get("register")->isclicked()) { echo "reg"; #testing } else die("error_welcome_form"); } homecoming $this->render('mybundle:index:welcome.html.twig', array("form" => $form->createview())); }
i using forwards instead of redirect because not possible pass post parameters when redirecting.
when submit form clicking login button get:
you must configure check path handled firewall using form_login in security firewall configuration.
so changed check_path parameter in security.yml from
check_path: fos_user_security_check
to
check_path: welcome (that route index:welcome() action
and test again. error disappears expected 2 new problems.
first, not able utilize single login form new check_path anymore. because original fos_user_security_check removed, obviously. need able utilize both merged form , single form.
second, error
invalid csrf-token.
does have solution this? possible without hacking fosuserbundle or implementing login action hand? need same register part of form think analog.
is maybe wrong approach? can somehow utilize same field (email) 2 separated forms?
php forms symfony2 login fosuserbundle
No comments:
Post a Comment