Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Symfony]2 Autnetykacja kody błędów
Forum PHP.pl > Forum > PHP > Frameworki
meron11
Zrobiłem sobie autentykacje, controlel do login forma z dokumentacji symfony:
  1. public function loginAction()
  2. {
  3. // get the login error if there is one
  4. if ($this->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR))
  5. {
  6. $error = $this->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
  7. }
  8. else
  9. {
  10. $error = $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
  11. }
  12.  
  13. return $this->render('cmsAdminBundle:Secured:login.html.twig', array(
  14. // last username entered by the user
  15. 'last_username' => $this->get('request')->getSession()->get(SecurityContext::LAST_USERNAME),
  16. 'error' => $error,
  17. ));
  18. }



Działą tworzy sesje,ale jedna zagadka, zawsze jak wejdę na stronę logowania jest ostatni błąd, czyli np źle wpisałem hasło, wchodzę jeszcze raz wpisujac od nowa url ,błąd tkwi nadal, idize to jakoś "naprawić"?
destroyerr
Uzależnij wyświetlanie błędów od tego czy żądanie jest GET czy POST. Jeśli to GET to znaczy, że nie został wysłany i powinieneś wyświetlać tylko formularz, bez błędów.
meron11
  1. $this->get('request')



To nie jest to?

Zrobiłem teraz tak:

  1. $request2 = Request::createFromGlobals();
  2.  
  3. if($request2->getMethod() == "POST"){
  4.  
  5. if ($this->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR))
  6. {
  7. $error = $this->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
  8. }
  9. else
  10. {
  11. $error = $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
  12. }
  13. }
  14. else
  15. {
  16. $error='';
  17. }
  18.  


To wgl błędu nie pokazuje .
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.