/** * Validate the configuration by creating a backend and requesting the user count * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidUserBackend(Form $form) { $backend = new DbUserBackend(ResourceFactory::createResource($form->getResourceConfig())); $result = $backend->inspect(); if ($result->hasError()) { $form->addError(sprintf($form->translate('Using the specified backend failed: %s'), $result->getError())); } // TODO: display diagnostics in $result->toArray() to the user return !$result->hasError(); }
protected function createAccount() { try { $backend = new DbUserBackend(ResourceFactory::createResource(new ConfigObject($this->data['adminAccountData']['resourceConfig']))); if ($backend->select()->where('user_name', $this->data['adminAccountData']['username'])->count() === 0) { $backend->insert('user', array('user_name' => $this->data['adminAccountData']['username'], 'password' => $this->data['adminAccountData']['password'], 'is_active' => true)); } } catch (Exception $e) { $this->dbError = $e; return false; } $this->dbError = false; return true; }
/** * Validate the configuration by creating a backend and requesting the user count * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidUserBackend(Form $form) { try { $dbUserBackend = new DbUserBackend(ResourceFactory::createResource($form->getResourceConfig())); if ($dbUserBackend->select()->where('is_active', true)->count() < 1) { $form->addError($form->translate('No active users found under the specified database backend')); return false; } } catch (Exception $e) { $form->addError(sprintf($form->translate('Using the specified backend failed: %s'), $e->getMessage())); return false; } return true; }
/** * {@inheritdoc} */ public function isValid($formData) { $valid = parent::isValid($formData); if (!$valid) { return false; } $oldPasswordEl = $this->getElement('old_password'); if (!$this->backend->authenticate($this->Auth()->getUser(), $oldPasswordEl->getValue())) { $oldPasswordEl->addError($this->translate('Old password is invalid')); $this->markAsError(); return false; } return true; }