Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZendFramework] zend_auth problem z odczytem danych
Forum PHP.pl > Forum > PHP > Frameworki
kociupk
mam problem z odczytem danych ktore zostaly zapisane do sesji
  1. public function indexAction()
  2. {
  3. if(Zend_Auth::getInstance()->hasIdentity())
  4. {
  5. $this->_redirect('profile/index/edit');
  6. }
  7.  
  8.  
  9. $form = new App_Form_Login();
  10. $formData = array();
  11.  
  12. if($this->getRequest()->isPost())
  13. {
  14. $formData = $this->getRequest()->getPost();
  15.  
  16. if($form->isValid($formData))
  17. {
  18. $auth = Zend_Auth::getInstance();
  19.  
  20. $authAdabter = new Zend_Auth_Adapter_DbTable(
  21. Zend_Registry::get('db'),
  22. 'portal_user',
  23. 'user_name',
  24. 'user_password',
  25. 'MD5(?) and active = 1'
  26. );
  27.  
  28. $authAdabter->setIdentity($form->getValue('user_name'))
  29. ->setCredential($form->getValue('user_password'));
  30.  
  31. $result = $auth->authenticate($authAdabter);
  32.  
  33. if($result->isValid())
  34. {
  35. $userObj = $authAdabter->getResultRowObject('null', 'user_password');
  36.  
  37. $auth->getStorage()->write($userObj);
  38.  
  39. $this->_redirect('profile/index/edit');
  40. } else {
  41. $errorMessage = 'Nieprawidlowe login lub haslo!';
  42. }
  43.  
  44. }
  45. }
  46. $this->view->error = $errorMessage;
  47. $this->view->form = $form;
  48. }

i tak odczytuje
  1. $user = Zend_Auth::getInstance()->getIdentity()->user_id;

batman
Zanim pobierzesz dane użytkownika, sprawdź czy jest zalogowany (hasIdentity). Sprawdź co jest w obiekcie $userObj. Możliwe, że nie ma czegoś takiego jak user_id.
kociupk
loguje sie prawidlowo jak nie jestem zalogowany to mnie przenosi na strone logowania wiec to dziala
  1. function init()
  2. {
  3. if(!Zend_Auth::getInstance()->hasIdentity()){
  4. $this->_redirect('login/index');
  5. }
  6. }
batman
W takim razie sprawdź co jest w zmiennej $userObj przed zapisaniem tych danych do sesji oraz co jest w Zend_Auth::getInstance()->getIdentity() przed wyciągnięciem id użytkownika.
kociupk
dane sa pobierane
stdClass Object ( [user_id] => 4 [user_name] => admin [user_email] => pawel@koteluk.pl
batman
Jeśli dane te znajdują się w $userObj, a nie ma ich w Zend_Auth::getInstance()->getIdentity() to prawdopodobnie jest to problem z ciasteczkami. Możliwe, że coś je blokuje. Ewentualnie nadpisujesz gdzieś te dane.
kociupk
zrobilem tak i dziala poprawnie
  1. $storage = $auth->getStorage();
  2. $storage->write($authAdabter->getResultRowObject(null, 'user_password'));
  3.  
  4. $this->_redirect('profile/index/edit');


dzieki batman za wspolne rozwiazywanie mojego problemu pozdrawiam
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.