Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Kohana] Logowanie
nmts
post
Post #1





Grupa: Zarejestrowani
Postów: 283
Pomógł: 34
Dołączył: 21.03.2008

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


Mam taką rejestrację, która działa poprawnie:
  1. class Controller_Rejestracja extends Controller_Index {
  2.  
  3. function action_index(){
  4. $this->template->content = new View("rejestracja");
  5. if($_POST){
  6. # Instancja nowego usera
  7. $user = ORM::factory('user');
  8.  
  9. # Walidacja
  10. if($user->values($_POST)->check())
  11. {
  12. # Uzupełniam dane
  13. $user->key = md5($user->password);
  14.  
  15. # Zapisuje
  16. if($user->save()){
  17. # Wysyłam e-mail aktywacyjny
  18. Mailer::factory('mail')->send_welcome(array(
  19. 'username' => $user->username,
  20. 'email' => $user->email,
  21. 'key' => $user->key
  22. ));
  23. $this->template->content->is_registered = true;
  24. }
  25. } else {
  26. # Błędnie wypełniony formularz
  27. $this->template->content->errors = $user->validate()->errors("user");
  28. }
  29. }
  30. }


I takie logowanie, które działa nie poprawnie ($status zwraca zawsze false):
  1. class Controller_Zaloguj extends Controller_Index {
  2.  
  3. function action_index(){
  4.  
  5. $this->template->content = new View("zaloguj");
  6.  
  7. if(Auth::instance()->logged_in()!= 0){
  8. Request::instance()->redirect('account/myaccount');
  9. }
  10.  
  11.  
  12. if($_POST){
  13. $user = ORM::factory('user');
  14. $status = $user->login($_POST);
  15.  
  16. if($status){
  17. $this->request->redirect('/xxx/');
  18. } else {
  19. $this->session->set('error_auth',true);
  20. $this->request->redirect("http://localhost/xxx/zaloguj/");
  21. }
  22. }
  23. $this->template->content->is_error = $this->session->get('error_auth');
  24. $this->session->delete('error_auth');
  25.  
  26. }
  27.  
  28. }


Co mogę robić źle lub o czym zapomniałem? :/
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
k_@_m_i_l
post
Post #2





Grupa: Zarejestrowani
Postów: 349
Pomógł: 72
Dołączył: 22.01.2008
Skąd: Wadowice/Oświęcim

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


Zauważ, że masz błąd w skłądni (IMG:style_emoticons/default/smile.gif)
Powinno być :
  1. $user = ORM::factory('user', $form['username']);
  2. // orm user object or $form['username'] could be used
  3. Auth::instance()->login($user->username, $form['password']);
  4. url::redirect('/user/login');


A poza tym, polecam użyć modułu Simple Auth. Jest lżejszy niż standardowy moduł i ma większe możliwości (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 3.10.2025 - 21:26