Ejemplo n.º 1
0
 /**
  * Get the node settings from this form
  * @param boolean $updateValues set to true to get the submitted node settings, false to get the initial node settings
  * @return joppa\model\NodeSettings
  * @throws zibo\ZiboException when the form is not submitted and $updateValues is set to true
  * @throws zibo\library\validation\exception\ValidationException when the submitted settings are not valid and $updateValues is set to true
  */
 public function getNodeSettings($updateValues = true)
 {
     if (!$updateValues) {
         return $this->nodeSettings;
     }
     if (!$this->isSubmitted()) {
         throw new ZiboException('Form not submitted');
     }
     $settings = @parse_ini_string($this->getValue(self::FIELD_SETTINGS));
     if ($settings === false) {
         $error = error_get_last();
         $error = new ValidationError('error', '%error%', array('error' => $error['message']));
         $exception = new ValidationException();
         $exception->addErrors(self::FIELD_SETTINGS, array($error));
         throw $exception;
     }
     $nodeSettings = new NodeSettings($this->nodeSettings->getNode(), $this->nodeSettings->getInheritedNodeSettings());
     // set the values from the form
     $inheritPrefixLength = strlen(NodeSettings::INHERIT_PREFIX);
     foreach ($settings as $key => $value) {
         $inherit = false;
         if (strlen($key) > $inheritPrefixLength && strncmp($key, NodeSettings::INHERIT_PREFIX, $inheritPrefixLength) == 0) {
             $key = substr($key, $inheritPrefixLength);
             $inherit = true;
         }
         $nodeSettings->set($key, $value, $inherit);
     }
     return $nodeSettings;
 }
Ejemplo n.º 2
0
 /**
  * Perform the advanced node action
  */
 public function indexAction()
 {
     $nodeSettings = $this->models['NodeSetting']->getNodeSettings($this->node->id);
     $form = new NodeSettingsForm($this->request->getBasePath(), $nodeSettings);
     if (!$form->isSubmitted()) {
         $this->setAdvancedView($form);
         return;
     }
     if ($form->isCancelled()) {
         $this->response->setRedirect($this->request->getBasePath());
         return;
     }
     try {
         $nodeSettings = $form->getNodeSettings(true);
         $this->models['NodeSetting']->setNodeSettings($nodeSettings);
         $this->clearCache();
         $this->addInformation(self::TRANSLATION_INFORMATION_SAVED, array('name' => $this->node->name));
         $this->response->setRedirect($this->request->getBasePath());
     } catch (ValidationException $saveException) {
         $validationException = new ValidationException();
         $errors = $saveException->getAllErrors();
         foreach ($errors as $fieldErrors) {
             $validationException->addErrors(NodeSettingsForm::FIELD_SETTINGS, $fieldErrors);
         }
         $form->setValidationException($validationException);
         $this->setAdvancedView($form);
     }
 }
 /**
  * Validates the field of a data object of a model
  * @param zibo\library\validation\exception\ValidationException $exception the exception where the validation errors will be assigned to
  * @param string $fieldName name of the field
  * @param mixed $value value to be validated
  * @return null
  */
 public function validateField(ValidationException $exception, $fieldName, $value)
 {
     $errors = array();
     if (!isset($this->validators[$fieldName])) {
         return;
     }
     foreach ($this->validators[$fieldName] as $validator) {
         if (!$validator->isValid($value)) {
             $errors = array_merge($errors, $validator->getErrors());
         }
     }
     if ($errors) {
         $exception->addErrors($fieldName, $errors);
     }
 }
Ejemplo n.º 4
0
 /**
  * Get the value from the request
  * @param string $name name of the request value
  * @return mixed value of this field
  * @throws zibo\library\validation\exception\ValidationException when a invalid date is entered
  */
 protected function getRequestValue($name = null)
 {
     $value = parent::getRequestValue($name);
     if (!$value) {
         return $value;
     }
     try {
         $locale = I18n::getInstance()->getLocale();
         $value = $locale->parseDate($value);
         $value = mktime(0, 0, 0, date('m', $value), date('d', $value), date('Y', $value));
     } catch (Exception $e) {
         $error = new ValidationError('error.date.format', '%value% is not in the right format', array('value' => $value));
         $exception = new ValidationException();
         $exception->addErrors($this->getName(), array($error));
         throw $exception;
     }
     return $value;
 }
 /**
  * Action to switch the current user
  * @param string $username Username of the user to switch to
  * @return null
  */
 public function indexAction($username = null)
 {
     if ($username) {
         $this->securityManager->switchUser($username);
         $this->response->setRedirect($this->getReferer());
         return;
     }
     $basePath = $this->request->getBasePath();
     $form = new UserSwitchForm($basePath);
     $form->setAutoComplete($basePath . '/' . self::ACTION_AUTO_COMPLETE_USER, 2);
     if (!$form->isSubmitted()) {
         $this->setUserSwitchView($form);
         return;
     }
     if ($form->isCancelled()) {
         $this->response->setRedirect($this->request->getBaseUrl());
         return;
     }
     try {
         $form->validate();
         $username = $form->getUsername();
         $this->securityManager->switchUser($username);
         $this->response->setRedirect($this->request->getBaseUrl());
         return;
     } catch (UserNotFoundException $userNotFoundException) {
         $validationError = new ValidationError(self::TRANSLATION_ERROR_USER_NOT_FOUND, 'Could not find user %user%', array('user' => $username));
         $validationException = new ValidationException();
         $validationException->addErrors(UserSwitchForm::FIELD_USERNAME, array($validationError));
         $form->setValidationException($validationException);
     } catch (UserSwitchException $userSwitchException) {
         $validationError = new ValidationError(self::TRANSLATION_ERROR_USER_NOT_ALLOWED, 'You are not allowed to switch to %user%', array('user' => $username));
         $validationException = new ValidationException();
         $validationException->addErrors(UserSwitchForm::FIELD_USERNAME, array($validationError));
         $form->setValidationException($validationException);
     } catch (ValidationException $validationException) {
     }
     $this->setUserSwitchView($form);
 }
 /**
  * Validate the permissions configuration value
  * @param string $permissions permissions configuration setting
  * @param zibo\library\validation\exception\ValidationException $validationException when a ValidationError occures, it will be added to this exception and null will be returned
  * @return string valid permissions configuration value
  */
 private function validatePermissions($permissions, ValidationException $validationException)
 {
     if ($permissions == NodeSettingModel::AUTHENTICATION_STATUS_ANONYMOUS || $permissions == NodeSettingModel::AUTHENTICATION_STATUS_AUTHENTICATED || $permissions == NodeSettingModel::AUTHENTICATION_STATUS_EVERYBODY) {
         return $permissions;
     }
     $configurationString = '';
     $securityManager = SecurityManager::getInstance();
     $permissions = explode(',', $permissions);
     foreach ($permissions as $permission) {
         $permission = trim($permission);
         if ($securityManager->hasPermission($permission)) {
             $configurationString .= ($configurationString ? ',' : '') . $permission;
             continue;
         }
         $error = new ValidationError('joppa.error.permission', 'permission \'%permission%\' does not exist', array('permission' => $permission));
         $validationException->addErrors(NodeSettingModel::SETTING_PERMISSIONS, array($error));
         return null;
     }
     return $configurationString;
 }
Ejemplo n.º 7
0
 /**
  * Provides a hook for additional form validation
  * @return null
  * @throws zibo\library\validation\exception\ValidationException when a validation error occurs
  */
 public function onProfileFormValidate()
 {
     $validationException = new ValidationException();
     if ($this->isPasswordSubmitted()) {
         $password = $this->getPassword();
         $passwordConfirmation = $this->getPasswordConfirmation();
         $validator = new RequiredValidator();
         if (!$validator->isValid($password)) {
             $validationException->addErrors(self::FIELD_PASSWORD, $validator->getErrors());
         }
         if (!$validator->isValid($passwordConfirmation)) {
             $validationException->addErrors(self::FIELD_PASSWORD_CONFIRM, $validator->getErrors());
         }
         if (!$validationException->hasErrors() && $password != $passwordConfirmation) {
             $error = new ValidationError(self::TRANSLATION_ERROR_PASSWORD_MATCH, "Your passwords do not match");
             $validationException->addErrors(self::FIELD_PASSWORD, array($error));
         }
     }
     if ($validationException->hasErrors()) {
         throw $validationException;
     }
 }
 /**
  * Perform the visibility node action
  */
 public function indexAction()
 {
     $nodeSettings = $this->models[NodeSettingModel::NAME]->getNodeSettings($this->node->id);
     $form = new NodeVisibilityForm($this->request->getBasePath(), $nodeSettings);
     if (!$form->isSubmitted()) {
         $this->setVisibilityView($form);
         return;
     }
     if (!$form->getValue(NodeVisibilityForm::FIELD_SAVE)) {
         $this->response->setRedirect($this->request->getBasePath());
         return;
     }
     try {
         $nodeSettings = $form->getNodeSettings(true);
         $this->models[NodeSettingModel::NAME]->setNodeSettings($nodeSettings);
         $this->clearCache();
         $this->addInformation(self::TRANSLATION_INFORMATION_SAVED, array('name' => $this->node->name));
         $this->response->setRedirect($this->request->getBasePath());
     } catch (ValidationException $saveException) {
         $validationException = new ValidationException();
         $errors = $saveException->getAllErrors();
         foreach ($errors as $field => $fieldErrors) {
             if ($field == NodeSettingModel::SETTING_PUBLISH) {
                 $validationException->addErrors(NodeVisibilityForm::FIELD_PUBLISH, $fieldErrors);
             } elseif ($field == NodeSettingModel::SETTING_PUBLISH_START) {
                 $validationException->addErrors(NodeVisibilityForm::FIELD_PUBLISH_START, $fieldErrors);
             } elseif ($field == NodeSettingModel::SETTING_PUBLISH_STOP) {
                 $validationException->addErrors(NodeVisibilityForm::FIELD_PUBLISH_STOP, $fieldErrors);
             } else {
                 $validationException->addErrors($field, $fieldErrors);
             }
         }
         $form->setValidationException($validationException);
         $this->setVisibilityView($form);
     }
 }
Ejemplo n.º 9
0
 /**
  * Get a XML-RPC request for the provided method and parameters
  * @param string $method full name of the method
  * @param string $parameters submitted parameters in string format, ready to be parsed
  * @return zibo\library\xmlrpc\Request the request for the XML RPC server
  * @throws zibo\library\validation\exception\ValidationException when the parameters could not be parsed
  */
 private function getXmlrpcRequest($method, $parameters)
 {
     $request = new Request($method);
     if (!$parameters) {
         return $request;
     }
     $parser = new ParameterParser();
     try {
         $parameters = $parser->parse($parameters);
     } catch (ZiboException $exception) {
         $error = new ValidationError(self::TRANSLATION_ERROR_PARAMETERS, 'Could not parse the parameters: %error%', array('error' => $exception->getMessage()));
         $validationException = new ValidationException();
         $validationException->addErrors(ClientForm::FIELD_PARAMETERS, array($error));
         throw $validationException;
     }
     foreach ($parameters as $parameter) {
         $request->addParameter($parameter);
     }
     return $request;
 }
Ejemplo n.º 10
0
 /**
  * Action to show the authentication form and to process authentication
  * @return null
  */
 public function indexAction()
 {
     $securityManager = SecurityManager::getInstance();
     $session = $this->getSession();
     $redirect = $this->getRedirect();
     $user = $securityManager->getUser();
     if ($user) {
         // user is already logged in
         $redirectUrl = null;
         switch ($redirect) {
             case self::REDIRECT_HOME:
                 $redirectUrl = $this->request->getBaseUrl();
                 break;
             case self::REDIRECT_REFERER:
                 $redirectUrl = $this->getReferer();
                 break;
         }
         if ($redirectUrl) {
             $this->response->setRedirect($redirectUrl);
         }
         return;
     }
     // gets the general referer
     $referer = $session->get(AdminModule::SESSION_REFERER);
     if (!$referer || substr_compare($referer, $this->request->getBasePath(), 0, strlen($this->request->getBasePath())) == 1) {
         $referer = $this->request->getBaseUrl();
     }
     $form = new AuthenticationForm($this->request->getBasePath());
     if (!$form->isSubmitted()) {
         // the form is not submitted, store the general referer as the login referer
         $session->set(self::SESSION_REFERER, $referer);
         $this->setLoginView($form);
         return;
     }
     // gets the login referer
     $redirectUrl = $session->get(self::SESSION_REFERER, $referer);
     if ($form->isCancelled()) {
         // the form is cancelled, redirect to the login referer
         $this->response->setRedirect($redirectUrl);
         return;
     }
     try {
         // try to authenticate the user
         $form->validate();
         $username = $form->getValue(SecurityManager::USERNAME);
         $password = $form->getValue(SecurityManager::PASSWORD);
         $securityManager->login($username, $password);
         // get the redirect url
         $redirect = $this->getRedirect();
         switch ($redirect) {
             case self::REDIRECT_NO:
                 $redirectUrl = $this->request->getBasePath();
                 break;
             case self::REDIRECT_HOME:
                 $redirectUrl = $this->request->getBaseUrl();
                 break;
         }
         $this->response->setRedirect($redirectUrl);
         return;
     } catch (AuthenticationException $e) {
         // authentication error
         if ($e->getField() == null) {
             throw $e;
         }
         $error = new ValidationError($e->getTranslationKey(), $e->getMessage());
         $exception = new ValidationException();
         $exception->addErrors($e->getField(), array($error));
         $form->setValidationException($exception);
     } catch (ValidationException $exception) {
         // no username or password filled in, exception already set to the form
     }
     $this->setLoginView($form);
 }
Ejemplo n.º 11
0
 /**
  * Sets a validation exception to this form
  * @param zibo\library\validation\exception\ValidationException $exception
  * @return null
  */
 public function setValidationException(ValidationException $exception)
 {
     $this->validationException = $exception;
     foreach ($this->fields as $fieldName => $field) {
         if ($exception->hasErrors($fieldName)) {
             $field->appendToClass(Field::CLASS_VALIDATION_ERROR);
         }
     }
 }
Ejemplo n.º 12
0
 /**
  * Validates this form
  * @return null
  * @throws zibo\library\validation\exception\ValidationException when one of the fields or
  * the form itself is not validated
  */
 public function validate()
 {
     if (!$this->isSubmitted()) {
         throw new ZiboException('Form is not submitted');
     }
     $this->validationException = new ValidationException();
     $iterator = $this->fields->getIterator();
     foreach ($iterator as $field) {
         $field->validate($this->validationException);
     }
     foreach ($this->validators as $validator) {
         $validator->isValid($this);
     }
     if ($this->validationException->hasErrors()) {
         throw $this->validationException;
     }
 }
Ejemplo n.º 13
0
 /**
  * Action to ask for the user and send a mail with the password reset URL
  * @return null
  */
 public function indexAction()
 {
     $basePath = $this->request->getBasePath();
     $form = new ResetPasswordForm($basePath);
     if (!$form->isSubmitted()) {
         // form not submitted, show the view
         $this->setResetPasswordView($form);
         return;
     }
     if ($form->isCancelled()) {
         // not implemented
         $this->response->setRedirect($basePath);
         return;
     }
     try {
         // validates the form
         $form->validate();
         // initialize needed variables
         $securityModel = SecurityManager::getInstance()->getSecurityModel();
         $username = $form->getUsername();
         $email = $form->getEmail();
         $error = null;
         $errorField = null;
         // gets the user by the provided field
         if ($username) {
             $errorField = ResetPasswordForm::FIELD_USERNAME;
             $user = $securityModel->getUserByUsername($username);
             if (!$user) {
                 $error = new ValidationError(self::TRANSLATION_ERROR_USER_NOT_FOUND_USERNAME, 'Could not find the profile for username %username%', array('username' => $username));
             }
         } else {
             $errorField = ResetPasswordForm::FIELD_EMAIL;
             $user = $securityModel->getUserByEmail($email);
             if (!$user) {
                 $error = new ValidationError(self::TRANSLATION_ERROR_USER_NOT_FOUND_EMAIL, 'Could not find the profile for email address %email%', array('email' => $email));
             }
         }
         if ($error) {
             // validation errors occured
             $exception = new ValidationException();
             $exception->addErrors($errorField, array($error));
             throw $exception;
         }
         $email = $user->getUserEmail();
         if (!$email) {
             // no email set for the user
             $error = new ValidationError(self::TRANSLATION_ERROR_USER_NO_EMAIL, 'No email address set for your profile');
             $exception = new ValidationException();
             $exception->addErrors($errorField, array($error));
             throw $exception;
         }
         // generates a secure key and the reset URL
         $key = $this->getUserKey($user);
         $resetUrl = $basePath . '/' . self::ACTION_RESET . '/' . $email . '/' . $key;
         // send the reset URL to the user
         $this->sendMail($user, $resetUrl);
         // show information message and redirect the page
         $this->addInformation(self::TRANSLATION_INFORMATION_SEND_MAIL);
         $this->response->setRedirect($basePath);
         return;
     } catch (ValidationException $exception) {
         $form->setValidationException($exception);
     }
     // a error occured, show the form with the errors
     $this->setResetPasswordView($form);
 }
Ejemplo n.º 14
0
 /**
  * Saves a connection
  * @param string $name Name of the connection
  * @param string $dsn DSN string for the connection
  * @param string $oldName Old name if we are doing a rename action
  * @return null
  * @throws Exception when an error occurs
  */
 public function saveConnection($name, $dsn, $oldName = null)
 {
     $zibo = Zibo::getInstance();
     $updateDefault = false;
     $baseKey = DatabaseManager::CONFIG_CONNECTION . Config::TOKEN_SEPARATOR;
     if (!empty($oldName) && $name != $oldName) {
         $defaultConnection = $this->getDefaultConnection();
         if ($defaultConnection->getName() == $oldName) {
             $updateDefault = true;
         }
         $zibo->setConfigValue($baseKey . $oldName, null);
     }
     $dsn = new Dsn($dsn);
     try {
         $this->manager->registerConnection($name, $dsn);
         $zibo->setConfigValue($baseKey . $name, $dsn->__toString());
         if ($updateDefault) {
             $this->setDefaultConnection($name);
         }
     } catch (Exception $exception) {
         $error = new ValidationError(self::TRANSLATION_ERROR, '%error%', array('error' => $exception->getMessage()));
         $validationException = new ValidationException();
         $validationException->addErrors('dsn', array($error));
         throw $validationException;
     }
 }
 /**
  * Action to rename a file or directory
  *
  * Every argument to this method is a part of the rename path. eg.
  * $fb->renameAction('application', 'data', 'test.txt') would rename to application/data/test.txt
  * @return null
  */
 public function renameAction()
 {
     $pieces = func_get_args();
     $file = $this->getFileFromPieces($pieces, false);
     if (!$file) {
         $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
     } else {
         $absoluteFile = new File($this->fileBrowser->getRoot(), $file);
         if (!$absoluteFile->exists()) {
             $this->addError(self::TRANSLATION_ERROR_EXIST_NOT, array('path' => $file));
             $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
         }
     }
     if ($this->response->getStatusCode() == Response::STATUS_CODE_NOT_FOUND) {
         $this->response->setView(new BaseView());
         return;
     }
     $basePath = $this->request->getBasePath();
     $parent = $absoluteFile->getParent();
     $redirectUrl = $basePath . '/' . self::ACTION_PATH . '/' . $this->fileBrowser->getPath($parent, false);
     $form = new RenameForm($basePath . '/' . self::ACTION_RENAME . '/' . $file, $file);
     if ($form->isSubmitted()) {
         if ($form->isCancelled()) {
             $this->response->setRedirect($redirectUrl);
             return;
         }
         try {
             $form->validate();
             $name = $form->getFileName();
             $name = String::safeString($name);
             $destination = new File($parent, $name);
             if ($destination->getAbsolutePath() != $absoluteFile->getPath() && $destination->exists()) {
                 $error = new ValidationError(self::TRANSLATION_ERROR_EXIST, '%path% exists already', array('path' => $this->fileBrowser->getPath($destination, false)));
                 $exception = new ValidationException();
                 $exception->addErrors(RenameForm::FIELD_NAME, array($error));
                 throw $exception;
             }
             $absoluteFile->move($destination);
             $this->addInformation(self::TRANSLATION_INFORMATION_RENAMED, array('old' => $file->getName(), 'new' => $name));
             $this->response->setRedirect($redirectUrl);
             return;
         } catch (ValidationException $exception) {
             $form->setValidationException($exception);
         } catch (Exception $exception) {
             Zibo::getInstance()->runEvent(Zibo::EVENT_LOG, $exception->getMessage(), $exception->getTraceAsString(), 1);
             $this->addError(self::TRANSLATION_ERROR, array('error' => $exception->getMessage()));
             $this->response->setStatusCode(Response::STATUS_CODE_SERVER_ERROR);
         }
     }
     if (!$absoluteFile->isWritable() || !$absoluteFile->getParent()->isWritable()) {
         $this->addWarning(self::TRANSLATION_ERROR_WRITABLE, array('path' => $file));
         $form->setIsDisabled(true, RenameForm::BUTTON_SUBMIT);
     }
     $view = new RenameView($form, $file);
     $view->setPageTitle(Module::TRANSLATION_FILE_BROWSER, true);
     $this->response->setView($view);
 }
Ejemplo n.º 16
0
 /**
  * Processes the next action of this step
  * return string Name of the next step
  */
 public function next()
 {
     try {
         $this->wizard->validate();
     } catch (ValidationException $validationException) {
         return null;
     }
     try {
         $protocol = $this->wizard->getValue(self::FIELD_PROTOCOL);
         $server = $this->wizard->getValue(self::FIELD_SERVER);
         $port = $this->wizard->getValue(self::FIELD_PORT);
         $database = $this->wizard->getValue(self::FIELD_DATABASE);
         $username = $this->wizard->getValue(self::FIELD_USERNAME);
         $password = $this->wizard->getValue(self::FIELD_PASSWORD);
         $authentication = null;
         if ($username) {
             $authentication = $username;
             if ($password) {
                 $authentication .= ':' . $password;
             }
             $authentication .= '@';
         }
         if ($port) {
             $port = ':' . $port;
         }
         $connectionName = 'default';
         $dsn = $protocol . '://' . $authentication . $server . $port . '/' . $database;
         $connectionModel = new ConnectionModel();
         $connectionModel->saveConnection($connectionName, $dsn);
         $connection = $connectionModel->getConnection($connectionName);
         if (!$connection->isConnectable()) {
             $validationException = new ValidationException();
             $validationException->addErrors('dsn', array(new ValidationError(self::TRANSLATION_DATABASE_ERROR, 'Could not connect with your database')));
             throw $validationException;
         }
         $dsn = new Dsn($dsn);
         $this->wizard->setVariable(self::VAR_DSN, $dsn);
         if (class_exists('zibo\\library\\orm\\ModelManager')) {
             ModelManager::getInstance()->defineModels();
         }
     } catch (ValidationException $validationException) {
         $this->wizard->setValidationException($validationException);
         return null;
     }
     return $this->wizard->getNextStep();
 }
Ejemplo n.º 17
0
 /**
  * Deletes data from this model
  * @param mixed $data Primary key of the data or a data object of this model
  * @return null
  */
 protected function deleteData($data)
 {
     $id = $this->getPrimaryKey($data);
     $data = $this->findById($id, 1, null, true);
     if ($data == null) {
         return;
     }
     if ($this->meta->willBlockDeleteWhenUsed() && $this->isDataReferencedInUnlinkedModels($data)) {
         $validationError = new ValidationError('orm.error.data.used', '%data% is still in use by another record', array('data' => $this->meta->formatData($data)));
         $validationException = new ValidationException();
         $validationException->addErrors('id', array($validationError));
         throw $validationException;
     }
     if ($this->meta->isLogged()) {
         $this->getLogModel()->logDelete($this->getName(), $data);
     }
     if ($this->meta->isLocalized()) {
         $this->deleteLocalized($data);
     }
     $this->deleteDataInUnlinkedModels($data);
     $condition = new SimpleCondition(new FieldExpression(ModelTable::PRIMARY_KEY), new SqlExpression($id), Condition::OPERATOR_EQUALS);
     $statement = new DeleteStatement();
     $statement->addTable(new TableExpression($this->getName()));
     $statement->addCondition($condition);
     $this->executeStatement($statement);
     $this->clearCache();
     $belongsTo = $this->meta->getBelongsTo();
     foreach ($belongsTo as $fieldName => $field) {
         $this->deleteBelongsTo($fieldName, $field, $data);
     }
     $hasOne = $this->meta->getHasOne();
     foreach ($hasOne as $fieldName => $field) {
         $this->deleteBelongsTo($fieldName, $field, $data);
     }
     $hasMany = $this->meta->getHasMany();
     foreach ($hasMany as $fieldName => $field) {
         $this->deleteHasMany($fieldName, $field, $data);
     }
     return $data;
 }
 /**
  * Action to login a user with username and password authentication
  * @return null
  */
 public function loginAction()
 {
     $user = $this->securityManager->getUser();
     if ($user !== null) {
         $this->response->setRedirect($this->request->getBaseUrl());
         return;
     }
     $form = new AuthenticationForm($this->request->getBasePath() . Request::QUERY_SEPARATOR . self::ACTION_LOGIN);
     if (!$form->isSubmitted()) {
         $this->setSecurityReferer();
         $this->setAuthenticationView($form);
         return;
     }
     if ($form->isCancelled()) {
         $this->response->setRedirect($this->getSecurityReferer());
         return;
     }
     try {
         $form->validate();
         $username = $form->getUsername();
         $password = $form->getPassword();
         $this->securityManager->login($username, $password);
         $this->response->setRedirect($this->getSecurityReferer());
         return;
     } catch (AuthenticationException $exception) {
         if ($exception->getField() == null) {
             throw $exception;
         }
         $validationError = new ValidationError($exception->getTranslationKey(), $exception->getMessage());
         $validationException = new ValidationException();
         $validationException->addErrors($exception->getField(), array($validationError));
         $form->setValidationException($validationException);
     } catch (ValidationException $validationException) {
     }
     $this->setAuthenticationView($form);
 }
Ejemplo n.º 19
0
 /**
  * Perform the validation on this field through the added validators
  * @param zibo\library\validation\exception\ValidationException $exception
  * @return zibo\library\validation\exception\ValidationException
  */
 public function validate(ValidationException $exception = null)
 {
     if (!$exception) {
         $exception = new ValidationException();
     }
     if (!$this->validator || $this->isDisabled()) {
         return $exception;
     }
     if (!$this->validator->isValid($this->getValue())) {
         $this->appendToClass(Field::CLASS_VALIDATION_ERROR);
         $exception->addErrors($this->getName(), $this->validator->getErrors());
     }
     return $exception;
 }