Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ZF]Autoryzacja z kilkoma warunkami, kilka zmiennych warunkowych
IceManSpy
post
Post #1





Grupa: Zarejestrowani
Postów: 1 006
Pomógł: 111
Dołączył: 23.07.2010
Skąd: Kraków

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


Witam

Mam niewielki problem z Zend Auth (IMG:style_emoticons/default/smile.gif) Potrzebuję sprawdzać, oprócz hasła i loginu-maila, także typ konta np czy to jest użytkownik, admin czy inny. Napisałem sobie coś takiego:
  1. $auth = new Zend_Auth_Adapter_DbTable(null,'user','use_email','use_password');
  2. $auth->setCredentialTreatment('? and use_activate = 1 and use_verify = 1 and use_block = 0');
  3. $auth->setIdentity($data['mail']);
  4. $user = new Model_User();
  5. $password = $user->getHashedPassword($data['password']);
  6. $auth->setCredential($password);

I to działa, ale nie sprawdza tego typu konta (jest wybierane w formularzu jako combobox).
Próbowałem tak:
  1. $auth->setCredentialTreatment('? and ? and use_activate = 1 and use_verify = 1 and use_block = 0');
  2. $auth->setCredential(array($password,$data['type'])); // $data['type'] -> zmienna dla typu uzytkownika z combobox

Próbowałem też tak:
  1. $auth->setCredentialTreatment('? and use_role = .'$data['type']'. and use_activate = 1 and use_verify = 1 and use_block = 0');

Nie działa. Jest sposób, aby weryfikować usera po tych dwóch lub więcej zmiennych?

Mogę napisać sobie jakiegoś ifa, który będzie to weryfikował, ale może da się to zrobić za pomocą Zend Auth.

Ten post edytował IceManSpy 3.11.2011, 20:17:19
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
5k7
post
Post #2





Grupa: Zarejestrowani
Postów: 65
Pomógł: 2
Dołączył: 5.12.2006

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


Po prostu jezeli masz coś jeszcze do dodania to po autoryzacji sprawdź to normalnie if'em i jeżeli masz negatywny wynik to czyść autoryzacje -> Zend_Auth::getInstance()->clearIdentity(); i po temacie

Ten post edytował 5k7 13.11.2011, 12:33:31
Go to the top of the page
+Quote Post
pgrzelka
post
Post #3





Grupa: Zarejestrowani
Postów: 313
Pomógł: 24
Dołączył: 9.08.2008
Skąd: Kielce

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


  1. $select = $auth->getDbSelect();
  2. $select->where();
Go to the top of the page
+Quote Post
mortus
post
Post #4





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Manual proponuje coś takiego:
  1. $auth = new Zend_Auth_Adapter_DbTable(
  2. null,
  3. 'user',
  4. 'use_email',
  5. 'use_password',
  6. '? and use_activate = 1 and use_verify = 1 and use_block = 0'
  7. );
  8. $user = new Model_User();
  9. $password = $user->getHashedPassword($data['password']);
  10. $auth->setIdentity($data['mail']);
  11. $auth->setCredential($password);

Jak również rozwiązanie, które podał pgrzelka (zobacz przykłady w manualu).
Go to the top of the page
+Quote Post
IceManSpy
post
Post #5





Grupa: Zarejestrowani
Postów: 1 006
Pomógł: 111
Dołączył: 23.07.2010
Skąd: Kraków

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


Cytat(mortus @ 15.11.2011, 10:23:33 ) *
Manual proponuje coś takiego:
  1. $auth = new Zend_Auth_Adapter_DbTable(
  2. null,
  3. 'user',
  4. 'use_email',
  5. 'use_password',
  6. '? and use_activate = 1 and use_verify = 1 and use_block = 0'
  7. );
  8. $user = new Model_User();
  9. $password = $user->getHashedPassword($data['password']);
  10. $auth->setIdentity($data['mail']);
  11. $auth->setCredential($password);

Jak również rozwiązanie, które podał pgrzelka (zobacz przykłady w manualu).

W Twoim przypadku jest tylko opcja na hasło, a ja potrzebowałem hasło oraz typ użytkownika. Rozwiązałem to tworząc "zapytanie":
  1. $CredentialTreatment = '? and use_role = "'.$data["type"].'" and use_activate = 1 and use_verify = 1 and use_block = 0';
  2. $auth->setCredentialTreatment($CredentialTreatment);

I działa jak należy (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: 22.08.2025 - 19:05