Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Kohana] Logowanie
Forum PHP.pl > Forum > PHP > Frameworki
nmts
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? :/
k_@_m_i_l
Zauważ, że masz błąd w skłądni 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 smile.gif
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.