Code cleanup + Settings

This commit is contained in:
2020-06-26 01:47:43 +02:00
parent 1896351a9b
commit 6eb9bf333f
17 changed files with 397 additions and 396 deletions

View File

@@ -18,7 +18,6 @@ namespace Api {
return $this->success && $res[0]["count"] > 0;
}
}
}
namespace Api\Groups {

View File

@@ -14,6 +14,7 @@ namespace Api\Settings {
use Api\Parameter\StringType;
use Api\SettingsAPI;
use Driver\SQL\Column\Column;
use Driver\SQL\Condition\Compare;
use Driver\SQL\Condition\CondLike;
use Driver\SQL\Condition\CondRegex;
use Driver\SQL\Strategy\UpdateStrategy;
@@ -44,6 +45,10 @@ namespace Api\Settings {
$query->where(new CondRegex($key, new Column("name")));
}
if ($this->isExternalCall()) {
$query->where(new Compare("name", "jwt_secret", "!="));
}
$res = $query->execute();
$this->success = ($res !== FALSE);

View File

@@ -519,17 +519,36 @@ If the invitation was not intended, you can simply ignore this email.<br><br><a
return $this->success;
}
private function checkSettings() {
$req = new \Api\Settings\Get($this->user);
$this->success = $req->execute(array("key" => "user_registration_enabled"));
$this->lastError = $req->getLastError();
if ($this->success) {
return ($req->getResult()["user_registration_enabled"] ?? "0") === "1";
}
return $this->success;
}
public function execute($values = array()) {
if (!parent::execute($values)) {
return false;
}
if ($this->user->isLoggedIn()) {
$this->lastError = L('You are already logged in');
$this->success = false;
return $this->createError(L('You are already logged in'));
}
$registrationAllowed = $this->checkSettings();
if (!$this->success) {
return false;
}
if(!$registrationAllowed) {
return $this->createError("User Registration is not enabled.");
}
$username = $this->getParam("username");
$email = $this->getParam('email');
if (!$this->userExists($username, $email)) {