Skip to content

Commit 7f84113

Browse files
committed
Handle 0s and 1s
1 parent a3a2a90 commit 7f84113

3 files changed

Lines changed: 50 additions & 17 deletions

File tree

js/settings.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,23 @@ user_sql.adminSettingsUI = function () {
7373

7474
if (data.status === "success") {
7575
for (var index = 0, length = data.data.length; index < length; ++index) {
76-
content.append("<div><label for=\"opt-crypto_param_" + index
77-
+ "\"><span>" + data.data[index]["name"]
78-
+ "</span><input type=\"number\" id=\"opt-crypto_param_"
79-
+ index + "\" name=\"opt-crypto_param_" + index
80-
+ "\" step=\"1\" min=\"" + data.data[index]["min"] + "\" max=\""
81-
+ data.data[index]["max"] + "\" value=\"" + data.data[index]["value"]
82-
+ "\"></label></div>");
76+
var param = $("<div></div>");
77+
var label = $("<label></label>").attr({for: "opt-crypto_param_" + index});
78+
var title = $("<span></span>").text(data.data[index]["name"]);
79+
var input = $("<input/>").attr({
80+
type: "number",
81+
id: "opt-crypto_param_" + index,
82+
name: "opt-crypto_param_" + index,
83+
step: 1,
84+
min: data.data[index]["min"],
85+
max: data.data[index]["max"],
86+
value: data.data[index]["value"]
87+
});
88+
89+
label.append(title);
90+
param.append(label);
91+
param.append(input);
92+
content.append(param);
8393
content.show();
8494
}
8595
}

lib/Controller/SettingsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public function cryptoParams()
399399
"CRYPTO_PARAM_" . $key
400400
)];
401401

402-
if (!empty($param)) {
402+
if (!is_null($param)) {
403403
$value->value = $param;
404404
}
405405
}

lib/Properties.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class Properties implements \ArrayAccess
7070
*/
7171
public function __construct(
7272
$AppName, IConfig $config, ILogger $logger, Cache $cache
73-
) {
73+
)
74+
{
7475
$this->appName = $AppName;
7576
$this->config = $config;
7677
$this->logger = $logger;
@@ -99,10 +100,12 @@ private function loadProperties()
99100
foreach ($params as $param) {
100101
$value = $this->config->getAppValue($this->appName, $param, null);
101102

102-
if ($value === App::FALSE_VALUE) {
103-
$value = false;
104-
} elseif ($value === App::TRUE_VALUE) {
105-
$value = true;
103+
if ($this->isBooleanParam($param)) {
104+
if ($value === App::FALSE_VALUE) {
105+
$value = false;
106+
} elseif ($value === App::TRUE_VALUE) {
107+
$value = true;
108+
}
106109
}
107110

108111
$this->data[$param] = $value;
@@ -116,6 +119,24 @@ private function loadProperties()
116119
);
117120
}
118121

122+
/**
123+
* Is given parameter a boolean parameter.
124+
*
125+
* @param $param string Parameter name.
126+
*
127+
* @return bool Is a boolean parameter.
128+
*/
129+
private function isBooleanParam($param)
130+
{
131+
return in_array(
132+
$param, [
133+
Opt::APPEND_SALT, Opt::CASE_INSENSITIVE_USERNAME,
134+
Opt::NAME_CHANGE, Opt::PASSWORD_CHANGE, Opt::PREPEND_SALT,
135+
Opt::REVERSE_ACTIVE, Opt::USE_CACHE
136+
]
137+
);
138+
}
139+
119140
/**
120141
* Return an array with all supported parameters.
121142
*
@@ -186,10 +207,12 @@ public function offsetSet($offset, $value)
186207
{
187208
$this->config->setAppValue($this->appName, $offset, $value);
188209

189-
if ($value === App::FALSE_VALUE) {
190-
$value = false;
191-
} elseif ($value === App::TRUE_VALUE) {
192-
$value = true;
210+
if ($this->isBooleanParam($offset)) {
211+
if ($value === App::FALSE_VALUE) {
212+
$value = false;
213+
} elseif ($value === App::TRUE_VALUE) {
214+
$value = true;
215+
}
193216
}
194217

195218
$this->data[$offset] = $value;

0 commit comments

Comments
 (0)