IndexController


~/tmp/ZF/hnext/IndexController.php.html  1 <?php  2 class IndexController extends Zend_Controller_Action {  3     protected $prawo;  4     static $daneForm;  5     public function init(){  6         $this->form = new Form_LoginForm();  7         $this->view->form=$this->form;  8         $this->prawo = new Application_Model_Auth_Prawo();  9     } 10     function indexAction() { 11         if ($this->_request->isPost()) { 12             self::$daneForm = $this->_request->getPost(); 13             if ($this->form->isValid(self::$daneForm)){ 14                 return $this->_forward('next'); 15             } else { 16                 $this->form->populate(self::$daneForm); 17             } 18         } 19         $this->view->form = $this->form; 20     } 21     public function nextAction(){ 22         if ($this->_request->isPost()){ 23             $auth = Zend_Auth::getInstance(); 24             //utworzenie adaptera ZendAuth bazy danych 25             $authAdapter = new Zend_Auth_Adapter_DbTable($this->prawo->getAdapter(),'prawo'); 26             //ustawienie w tabeli 'prawo'  pól do uwierzytelnienia 27             $authAdapter->setIdentityColumn('login') 28                         ->setCredentialColumn('password'); 29 30             //wstawienie wartości z formularza 31             $password = md5(self::$daneForm['haslo']); 32             $authAdapter->setIdentity(self::$daneForm['login']); 33             $authAdapter->setCredential($password); 34 35 //uwierzytelnianie 36 //$result 37 //Zend_Auth_Result::SUCCESS - logowanie powiodło się, 38 //Zend_Auth_Result::FAILURE - logowanie nie powiodło się, 39 //Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND - niepoprawna nazwa użytkownika, 40 //Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS - niejednoznaczna nazwa użytkownika, 41 //Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID - niepoprawne hasło, 42 //Zend_Auth_Result::FAILURE_UNCATEGORIZED - inny błąd podczas logowania. 43 44             $result = $auth->authenticate($authAdapter); 45             if ($result->isValid()){ 46                 $this->_forward('index', 'ochrona'); 47             } 48             else { 49                 $this->_redirect("/"); 50             } 51         } 52         else { 53             $this->_redirect("/"); 54         } 55      } 56      public function logoutAction(){ 57          Zend_Auth::getInstance()->clearIdentity(); 58          $this->_forward('index'); 59      } 60 }

Wyszukiwarka

Podobne podstrony:
java awt image IndexColorModel
indexc052
indexcb67
IndexController 4
IndexController
indexc856
IndexController

więcej podobnych podstron