Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZF]Autoryzacja z kilkoma warunkami
Forum PHP.pl > Forum > PHP > Frameworki
IceManSpy
Witam

Mam niewielki problem z Zend Auth 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.
5k7
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
pgrzelka
  1. $select = $auth->getDbSelect();
  2. $select->where();
mortus
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).
IceManSpy
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 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.