Settings Save Mechanism an few fixes
This commit is contained in:
parent
464f229a16
commit
daa0e0a2c5
@ -21,13 +21,24 @@ if (isset($_POST) && !empty($_POST)){
|
|||||||
|
|
||||||
$ga = new PHPGangsta_GoogleAuthenticator();
|
$ga = new PHPGangsta_GoogleAuthenticator();
|
||||||
$checkResult = $ga->verifyCode($otaSecret, $otaCode, 2); // 2 = 2*30sec clock tolerance
|
$checkResult = $ga->verifyCode($otaSecret, $otaCode, 2); // 2 = 2*30sec clock tolerance
|
||||||
if ($checkResult) {
|
if ($checkResult) {
|
||||||
$userManager->setOta($otaCode, $otaSecret);
|
$userManager->setOta($otaCode, $otaSecret);
|
||||||
}
|
}
|
||||||
header('Location: ' . BASEURL . 'setting');
|
header('Location: ' . BASEURL . 'setting');
|
||||||
die();
|
die();
|
||||||
} else if (isset ($_POST['userPermission']) && !empty ($_POST['userID'])) {
|
} else if (isset ($_POST['userPermission']) && !empty ($_POST['userID'])) {
|
||||||
$userManager->setUserDataAdmin("permission", $_POST['userPermission'], $_POST['userID']);
|
$userManager->setUserDataAdmin("permission", $_POST['userPermission'], $_POST['userID']);
|
||||||
|
header('Location: ' . BASEURL . 'setting');
|
||||||
|
die();
|
||||||
|
} else {
|
||||||
|
foreach ($_POST as $key => $value) {
|
||||||
|
if ($key == 'submit') continue;
|
||||||
|
$settingMng = new SettingsManager();
|
||||||
|
if ($settingMng->getByName($key)) {
|
||||||
|
$settingMng->update($key, $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
header('Location: ' . BASEURL . 'setting');
|
header('Location: ' . BASEURL . 'setting');
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
@ -14,21 +14,23 @@ class SettingsManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function create ($name, $value, $type = '') {
|
public static function create ($name, $value, $type = '') {
|
||||||
$setting = array (
|
if (!self::getByName($name)){
|
||||||
'name' => $name,
|
$setting = array (
|
||||||
'value' => $value,
|
'name' => $name,
|
||||||
'type' => $type,
|
'value' => $value,
|
||||||
);
|
'type' => $type,
|
||||||
try {
|
);
|
||||||
Db::add ('settings', $setting);
|
try {
|
||||||
} catch(PDOException $error) {
|
Db::add ('settings', $setting);
|
||||||
echo $error->getMessage();
|
} catch(PDOException $error) {
|
||||||
die();
|
echo $error->getMessage();
|
||||||
|
die();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function update ($name, $value, $type = '') {
|
public static function update ($name, $value, $type = '') {
|
||||||
if (self::getByName($name)){
|
if (!self::getByName($name)){
|
||||||
self::create($name, $value, $type);
|
self::create($name, $value, $type);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
@ -9,6 +9,14 @@ class AirQuality extends VirtualDeviceManager
|
|||||||
|
|
||||||
function make()
|
function make()
|
||||||
{
|
{
|
||||||
|
//Register the settings
|
||||||
|
$settingMng = new SettingsManager();
|
||||||
|
if (!($settingField = $settingMng->getByName("airquality"))) {
|
||||||
|
$settingMng->create("token", "", "airquality");
|
||||||
|
} else {
|
||||||
|
$app_id = $settingField['value'];
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (DeviceManager::registeret($this->virtual_device_name)) {
|
if (DeviceManager::registeret($this->virtual_device_name)) {
|
||||||
$deviceId = DeviceManager::getDeviceByToken($this->virtual_device_name)['device_id'];
|
$deviceId = DeviceManager::getDeviceByToken($this->virtual_device_name)['device_id'];
|
||||||
|
@ -210,7 +210,7 @@ $partial = new Partial('head');
|
|||||||
<?php foreach ($pluginSeting['settings'] as $key => $pluginSetingField) { ?>
|
<?php foreach ($pluginSeting['settings'] as $key => $pluginSetingField) { ?>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="label"><?php echo $pluginSetingField['name'] ?>:</div>
|
<div class="label"><?php echo $pluginSetingField['name'] ?>:</div>
|
||||||
<input type="text" class="input" name="roomName" value="<?php echo $pluginSetingField['value'] ?>">
|
<input type="text" class="input" name="<?php echo $pluginSetingField['name'] ?>" value="<?php echo $pluginSetingField['value'] ?>">
|
||||||
</div>
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
Loading…
Reference in New Issue
Block a user