PHP_SMART_HOME_V3/app/controllers/settingController.php

51 lines
1.8 KiB
PHP
Raw Normal View History

2020-05-16 15:18:27 +00:00
<?php
if (isset($_POST) && !empty($_POST)){
$userManager = new UserManager();
$roomManager = new RoomManager();
2020-05-16 15:18:27 +00:00
if (isset($_POST['submitPasswordChange']) && $_POST['submitPasswordChange'] != "") {
$oldPassword = $_POST['oldPassword'];
$newPassword = $_POST['newPassword1'];
$newPassword2 = $_POST['newPassword2'];
$userManager->changePassword($oldPassword, $newPassword, $newPassword2);
2020-05-16 15:18:27 +00:00
header('Location: ' . BASEURL . 'logout');
die();
} else if (isset($_POST['submitCreateUser']) && $_POST['submitCreateUser'] != "") {
$userName = $_POST['userName'];
$password = $_POST['userPassword'];
$email = $_POST['userEmail'];
$userManager->createUser($userName, $password, $email);
2020-05-16 15:18:27 +00:00
header('Location: ' . BASEURL . 'setting');
die();
} else if (isset($_POST['submitEnableOta']) && $_POST['submitEnableOta'] != "") {
2020-05-16 23:27:06 +00:00
$otaCode = $_POST['otaCode'];
$otaSecret = $_POST['otaSecret'];
2020-05-16 15:18:27 +00:00
$ga = new PHPGangsta_GoogleAuthenticator();
$checkResult = $ga->verifyCode($otaSecret, $otaCode, 2); // 2 = 2*30sec clock tolerance
2020-12-23 14:57:12 +00:00
if ($checkResult) {
$userManager->setOta($otaCode, $otaSecret);
}
2020-05-16 15:18:27 +00:00
header('Location: ' . BASEURL . 'setting');
die();
} else if (isset ($_POST['userPermission']) && !empty ($_POST['userID'])) {
$userManager->setUserDataAdmin("permission", $_POST['userPermission'], $_POST['userID']);
2020-12-23 14:57:12 +00:00
header('Location: ' . BASEURL . 'setting');
die();
} if (isset ($_POST['roomName']) && !empty ($_POST['roomId'])) {
$roomManager->edit($_POST['roomId'], array("name" => $_POST['roomName']));
header('Location: ' . BASEURL . 'setting');
die();
2020-12-23 14:57:12 +00:00
} 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');
die();
2020-05-16 15:18:27 +00:00
}
}