Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php][symfony2] logowanie "in memory"
peter13135
post 10.07.2012, 12:28:33
Post #1





Grupa: Zarejestrowani
Postów: 1 447
Pomógł: 191
Dołączył: 26.03.2008

Ostrzeżenie: (0%)
-----


Chcę zrobić logowanie dla adminów, bez użycia bazy danych ponieważ będzie ich tylko dwóch na stałe.

Znalazłem tutorial : http://symfony.com/doc/current/book/security.html
Ale jest dla mnie niezrozumiały.

Domyślam się, że muszę najpierw mieć formularz logowania i w sumie już go mam z przykładowego bundla :
  1. public function loginAction()
  2. {
  3. if ($this->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
  4. $error = $this->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
  5. } else {
  6. $error = $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
  7. }
  8.  
  9. return array(
  10. 'last_username' => $this->get('request')->getSession()->get(SecurityContext::LAST_USERNAME),
  11. 'error' => $error,
  12. );
  13. }


Teplatka też jest do niego.

  1. {% extends 'AcmeDemoBundle::layout.html.twig' %}
  2.  
  3. {% block content %}
  4. <h1>Login</h1>
  5.  
  6. <p>
  7. Choose between two default users: <em>user/userpass</em> <small>(ROLE_USER)</small> or <em>admin/adminpass</em> <small>(ROLE_ADMIN)</small>
  8. </p>
  9.  
  10. {% if error %}
  11. <div class="error">{{ error.message }}</div>
  12. {% endif %}
  13.  
  14. <form action="{{ path("_security_check") }}" method="post" id="login">
  15. <div>
  16. <label for="username">Username</label>
  17. <input type="text" id="username" name="_username" value="{{ last_username }}" />
  18. </div>
  19.  
  20. <div>
  21. <label for="password">Password</label>
  22. <input type="password" id="password" name="_password" />
  23. </div>
  24.  
  25. <input type="submit" class="symfony-button-grey" value="LOGIN" />
  26. </form>
  27. {% endblock %}
  28.  
  29. {% set code = code(_self) %}
  30.  


Formularz wysyła się do http://localhost/demo/secured/login_check

Chociaż nie bardzo wiem czemu, bo w pliku security mam takie coś (fragment) :
Kod
        secured_area:
            pattern:    ^/demo/secured/
            pattern:    ^/valuation/admin
            form_login:
                check_path: /valuation/admin
                login_path: /demo/secured/login
            logout:
                path:   /demo/secured/logout
                target: /demo/


Kontroler do tego login check jest pustą funkcją, któa nawet niczego nie zwraca, więc są błędy.

Nie mam pojęcia w jaki sposób mam przechwycić te dane z formularza i sprawdzić czy są poprawne i potem co mam ustawić, żeby system rozpoznawał mnie jako admina, czy użytkownika.Czy możecie dać mi link do jakiegoś tutoriala, lub cokolwiek co by mi pomogło w rozwiązaniu problemu ?
Niestety ja nie znalazłem żadnych przykładów.



--------------------
:)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 24.04.2024 - 19:39