Esempio n. 1
0
 public function indexAction()
 {
     $this->_helper->layout->setLayout('adminlogin');
     $this->_redirectIfAuthenticated();
     $form = new Auth_Form_Login(array('dbAdapter' => Zend_Db_Table_Abstract::getDefaultAdapter(), 'tableName' => 'auth_user', 'loginColumn' => 'username', 'passwordColumn' => 'password', 'authAdapter' => 'Centurion_Auth_Adapter_DbTable', 'checkColumn' => 'is_active = 1'));
     if (null !== $this->_getParam('next', null)) {
         $form->getElement('next')->setValue($this->_getParam('next', null));
     }
     if ($this->getRequest()->isPost()) {
         $posts = $this->getRequest()->getParams();
         if ($form->isValid($posts)) {
             $userRow = Centurion_Auth::getInstance()->getIdentity();
             $userRow->last_login = date('Y-m-d h:i:s');
             $userRow->save();
             $this->_redirectIfAuthenticated();
         } else {
             $form->populate($posts);
         }
     }
     $this->view->form = $form;
 }
Esempio n. 2
0
 /**
  * Authenticates a given user.
  * @param array $formParams
  * @return $response
  */
 public function login(array $formParams = array())
 {
     // get the form object
     $form = new Auth_Form_Login();
     // check if request is POST
     if (!empty($formParams)) {
         if ($form->isValid($formParams)) {
             // form is valid, get values
             $values = $form->getValues();
             // create DbAuth model and authenticate
             $result = Daiquiri_Auth::getInstance()->authenticateUser($values['username'], $values['password'], $values['remember']);
             // redirect depending on result of authentication
             if ($result) {
                 return array('status' => 'redirect');
             } else {
                 $form->setDescription('Wrong credentials provided');
                 return $this->getModelHelper('CRUD')->validationErrorResponse($form);
             }
         } else {
             return $this->getModelHelper('CRUD')->validationErrorResponse($form);
         }
     }
     return array('form' => $form, 'status' => 'form');
 }