Exemple #1
0
 /**
  * IMPORTANT side effect. This method will automatically authenticate using to CMS if
  * enable_cms_integration is on in config.
  *
  * @param Zend_Request_Interface $request
  * @return bool
  */
 function validate($request)
 {
     $result = true;
     //We check username for alphanumeric
     $username = $request->getParam('username', null);
     $validatorChain = new RM_Validate('Username');
     $usernameResult = $validatorChain->addValidator(new Zend_Validate_Alnum())->isValid($username);
     if (!$usernameResult) {
         $this->_errors = $validatorChain->getErrors();
         $result = false;
     }
     //We check password for alphanumeric
     $password = $request->getParam('password', null);
     $validatorChain = new RM_Validate('Password');
     $passwordResult = $validatorChain->addValidator(new Zend_Validate_Alnum())->isValid($password);
     if (!$passwordResult) {
         $this->_errors = array_merge($this->_errors, $validatorChain->getErrors());
         $result = false;
     }
     $config = new RM_Config();
     $isCmsAuthentication = $config->getValue('rm_config_enable_cms_integration');
     if ($isCmsAuthentication) {
         $authenticationResult = RM_Environment::getConnector()->authenticate($request->getParam('username'), $request->getParam('password'));
         if ($authenticationResult !== true) {
             if (is_object($authenticationResult)) {
                 $this->_errors[] = $authenticationResult->getMessage();
             } else {
                 $this->_errors[] = 'UserNotFound';
             }
             $result = false;
         }
     } else {
         $userModel = new RM_Users();
         $user = $userModel->getBy($request->getParam('username'));
         if ($user === null) {
             $this->_errors[] = 'UserNotFound';
             $result = false;
         }
         //Finally we tries to find existing user in database with the same username/password
         $userModel = new RM_Users();
         $user = $userModel->getBy($request->getParam('username'), $request->getParam('password'));
         if ($user === null) {
             $this->_errors[] = 'WrongPassword';
             $result = false;
         }
     }
     return $result;
 }
Exemple #2
0
 /**
  * Login validate action
  *
  * validates the users login then redirects the user
  */
 function loginvalidateAction()
 {
     $this->_withoutView();
     $formModel = new RM_Forms();
     $form = $formModel->find('login')->current();
     $valid = $form->validate($this->getRequest());
     if (!$valid) {
         RM_Reservation_Manager::getInstance()->setFormErrors('login', $form->getErrors())->save();
         $this->_redirect('User', 'userdetails');
     }
     $config = new RM_Config();
     $isCmsAuthentication = $config->getValue('rm_config_enable_cms_integration');
     if ($isCmsAuthentication) {
         $cmsUser = RM_Environment::getConnector()->getUser();
         $user = $cmsUser->findResmaniaUser();
         if ($user == null) {
             $user = $cmsUser->convertToResmaniaUser();
         }
         RM_Reservation_Manager::getInstance()->setUser($user);
     } else {
         $userModel = new RM_Users();
         $user = $userModel->getBy($this->_getParam('username'), $this->_getParam('password'));
     }
     if ($user !== null) {
         RM_Reservation_Manager::getInstance()->resetFormErrors('login')->setUser($user)->save();
         $this->_redirect('Reservations', 'summary');
     }
 }