Exemplo n.º 1
0
 /**
  * create action for account controller
  *
  */
 public function createAction()
 {
     try {
         $translate = Zend_Registry::get('Zend_Translate');
         $frmAccount = new Acl_Form_Account();
         $frmAccount->setAction($this->_request->getBaseUrl() . "/acl/account/create");
         $this->view->frmAccount = $frmAccount;
         /*$fields = array();
         		foreach ( $frmAccount->getElements() as $element ) $fields[] = $element->getName();
         		$frmAccount->addDisplayGroup( $fields, 'form', array( 'legend' => "ACL_CREATE_ACCOUNT" ) );*/
         if ($this->getRequest()->isPost()) {
             if ($frmAccount->isValid($_POST)) {
                 $mdlAccount = new Acl_Model_Account();
                 $account = $mdlAccount->createRow($frmAccount->getValues());
                 #$account->salt = hash('SHA512',md5(uniqid(rand(), TRUE)).time());
                 $salt = hash('SHA512', md5(uniqid(rand(), TRUE)) . time());
                 $account->password = crypt($account->password, '$6$5000$' . $salt . '$');
                 #$account->password = md5( $account->salt.$account->password );
                 $account->save();
                 $this->_helper->flashMessenger->addMessage(array('type' => 'info', 'header' => '', 'message' => $translate->translate("LBL_CHANGES_SAVED")));
                 $this->_helper->redirector("list", "account", "acl");
             } else {
                 #print_r( $frmAccount->getErrorMessages() );
                 #throw new Zend_Exception( 'w|'.$translate->translate("LABEL_FIELDS_NOT_VALID") );
                 #$this->_helper->flashMessenger->addMessage( 'w|'.$translate->translate("LABEL_FIELDS_NOT_VALID") );
             }
         }
     } catch (Exception $e) {
         $this->_helper->flashMessenger->addMessage(array('type' => 'error', 'header' => '', 'message' => $e->getMessage()));
         $this->_helper->redirector("list", "account", "acl");
     }
 }
 /**
  * Login action for authentication controller
  */
 public function loginAction()
 {
     $translate = Zend_Registry::get('Zend_Translate');
     try {
         $auth = Zend_Auth::getInstance();
         $identity = $auth->getIdentity();
         $role = $auth->hasIdentity() ? $auth->getIdentity()->role_id : 3;
         $frmLogin = new Acl_Form_Login();
         $this->view->identity = $role != 3 ? $identity : null;
         $frmLogin->setAction($this->_request->getBaseUrl() . '/login');
         $this->view->frmLogin = $frmLogin;
         if ($this->getRequest()->isPost()) {
             if ($frmLogin->isValid($this->getRequest()->getParams())) {
                 $mdlAccount = new Acl_Model_Account();
                 $objAccount = $mdlAccount->createRow($frmLogin->getValues());
                 $objAccount->password = $objAccount->password;
                 if ($mdlAccount->Login($objAccount)) {
                     $role = $auth->getInstance()->getIdentity()->role_id;
                     if ($role < 3) {
                         // is root or super administrator
                     }
                     $this->redirect('login');
                 } else {
                     throw new Exception($translate->translate("ACL_ACCESS_DENIED"));
                 }
             } else {
                 /*$msgs = "";
                 		$ErrorMsgsForm = $frmLogin->getMessages();
                 		foreach ( $ErrorMsgsForm as $errorMsg ) {
                 			foreach ( $errorMsg as $key => $value ) {
                 				$msgs .= $value."<br>";
                 			}
                 		}
                 		throw new Exception($msgs);*/
                 /*
                  * /!\ Warning
                  * si se lanza una excepcion aca entonces los widgets tendran problemas cuando esta accion sea usada como widget
                  * este form de login deberia apuntar a una nueva accion llamada validate o algo similar 
                  * toda funcion usada como widget que traiga consigo un form debe tener como action una funcion distinta para evitar
                  * este problema.
                  * /!\ To do
                  * Anybody wants to take this enhacement-issue?
                  * */
             }
         }
         $fields = array();
         foreach ($frmLogin->getElements() as $element) {
             $fields[] = $element->getName();
         }
         $frmLogin->addDisplayGroup($fields, 'form', array('legend' => "ACL_LOGIN"));
     } catch (Exception $e) {
         $this->_helper->flashMessenger->addMessage(array('type' => 'error', 'header' => '', 'message' => $e->getMessage()));
         $this->redirect('login');
         #echo $e->getMessage();
     }
 }