PHP_SMART_HOME_V3/app/controllers/settingController.php

35 lines
1.3 KiB
PHP
Raw Normal View History

2020-05-16 15:18:27 +00:00
<?php
if (isset($_POST) && !empty($_POST)){
$userManager = new UserManager();
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
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']);
header('Location: ' . BASEURL . 'setting');
die();
2020-05-16 15:18:27 +00:00
}
}