Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [ZendFramework] zend_auth problem z odczytem danych
kociupk
post 22.03.2010, 18:27:58
Post #1





Grupa: Zarejestrowani
Postów: 97
Pomógł: 1
Dołączył: 29.03.2006

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


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;

Go to the top of the page
+Quote Post
batman
post 22.03.2010, 19:04:42
Post #2





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




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.


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
kociupk
post 22.03.2010, 19:20:22
Post #3





Grupa: Zarejestrowani
Postów: 97
Pomógł: 1
Dołączył: 29.03.2006

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


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. }
Go to the top of the page
+Quote Post
batman
post 22.03.2010, 19:48:50
Post #4





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




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.


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
kociupk
post 22.03.2010, 20:09:41
Post #5





Grupa: Zarejestrowani
Postów: 97
Pomógł: 1
Dołączył: 29.03.2006

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


dane sa pobierane
stdClass Object ( [user_id] => 4 [user_name] => admin [user_email] => pawel@koteluk.pl

Ten post edytował kociupk 22.03.2010, 20:28:18
Go to the top of the page
+Quote Post
batman
post 22.03.2010, 20:32:16
Post #6





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




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.


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
kociupk
post 22.03.2010, 20:39:21
Post #7





Grupa: Zarejestrowani
Postów: 97
Pomógł: 1
Dołączył: 29.03.2006

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


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

Ten post edytował kociupk 22.03.2010, 20:40:48
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: 28.06.2025 - 04:10