CleanUp After Docker Try
This commit is contained in:
14
app/controllers/ExampleController.php
Normal file
14
app/controllers/ExampleController.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
class ExampleController extends Controller{
|
||||
|
||||
public function index(){
|
||||
$this->view->title = 'Example title';
|
||||
$this->view->render('example.phtml');
|
||||
}
|
||||
|
||||
public function subpage(){
|
||||
echo 'subpage';
|
||||
}
|
||||
|
||||
}
|
77
app/controllers/automationController.php
Normal file
77
app/controllers/automationController.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
if (isset($_POST) && !empty($_POST)){
|
||||
if (isset($_POST['modalFinal']) && $_POST['action'] == "add") {
|
||||
$doCode = json_encode($_POST['device'], JSON_PRETTY_PRINT);
|
||||
|
||||
$value = $_POST['atSelector'];
|
||||
if ($_POST['atSelector'] == 'time'){
|
||||
$value = $_POST['atSelectorValue'];
|
||||
} else if ($_POST['atSelector'] == 'atDeviceValue') {
|
||||
$value = json_decode($_POST['atSelectorValue']);
|
||||
} else if ($_POST['atSelector'] == 'inHome' || $_POST['atSelector'] == 'outHome') {
|
||||
$value = UserManager::getUserData('user_id');
|
||||
}
|
||||
|
||||
|
||||
$ifCode = json_encode([
|
||||
"type" => $_POST['atSelector'],
|
||||
"value" => $value,
|
||||
], JSON_PRETTY_PRINT);
|
||||
$onDays = $_POST['atDays'];
|
||||
|
||||
//Debug
|
||||
// if (DEBUGMOD == 1) {
|
||||
// echo '<pre>';
|
||||
// echo $permissionsInJson;
|
||||
// echo $deviceId;
|
||||
// var_dump(json_decode ($permissionsInJson));
|
||||
// echo '</pre>';
|
||||
// echo '<a href="' . BASEDIR .'">CONTINUE</a>';
|
||||
// die();
|
||||
// }
|
||||
|
||||
AutomationManager::create($_POST['name'], $onDays, $doCode, $ifCode);
|
||||
|
||||
header('Location: ' . BASEURL . strtolower(basename(__FILE__, '.php')));
|
||||
die();
|
||||
} else if (isset($_POST['modalFinal']) && $_POST['action'] == "edit") {
|
||||
$doCode = json_encode($_POST['device'], JSON_PRETTY_PRINT);
|
||||
|
||||
if (isset ($_POST['atDeviceValue'])) {
|
||||
$subDeviceId = $_POST['atDeviceValue'];
|
||||
$subDeviceValue = $_POST['atDeviceValueInt'];
|
||||
$subDevice = SubDeviceManager::getSubDevice($subDeviceId);
|
||||
$subDeviceMaster = SubDeviceManager::getSubDeviceMaster($subDeviceId,$subDevice['type']);
|
||||
|
||||
$device = [
|
||||
'deviceID' => $subDeviceMaster['device_id'],
|
||||
'type'=> $subDevice['type'],
|
||||
'value'=> $subDeviceValue,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
$value = $_POST['atSelector'];
|
||||
if (isset($_POST['atTime'])){
|
||||
$value = $_POST['atTime'];
|
||||
} else if (isset($_POST['atDeviceValue'])) {
|
||||
$value = $device;
|
||||
} else if ($_POST['atSelector'] == 'inHome' || $_POST['atSelector'] == 'outHome') {
|
||||
//TODO: opravit edit aby vkládal id původního uživatele
|
||||
$value = UserManager::getUserData('user_id');
|
||||
}
|
||||
|
||||
$value = (isset($_POST['atTime']) ? $_POST['atTime'] : (isset($_POST['atDeviceValue']) ? $device : $_POST['atSelector']));
|
||||
$ifCode = json_encode([
|
||||
"type" => $_POST['atSelector'],
|
||||
"value" => $value,
|
||||
], JSON_PRETTY_PRINT);
|
||||
$onDays = ($_POST['day'] != '' ? json_encode($_POST['day']) : '');
|
||||
|
||||
AutomationManager::create($_POST['name'], $onDays, $doCode, $ifCode, (isset ($_POST['automation_id']) ? $_POST['automation_id'] : ""));
|
||||
|
||||
header('Location: ' . BASEURL . strtolower(basename(__FILE__, '.php')));
|
||||
die();
|
||||
}
|
||||
}
|
||||
?>
|
51
app/controllers/loginController.php
Normal file
51
app/controllers/loginController.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
global $userManager;
|
||||
|
||||
|
||||
if (
|
||||
isset($_POST['username']) &&
|
||||
$_POST['username'] != '' &&
|
||||
isset($_POST['password']) &&
|
||||
$_POST['password'] != ''
|
||||
){
|
||||
$ota = false;
|
||||
$userName = $_POST['username'];
|
||||
$userPassword = $_POST['password'];
|
||||
$rememberMe = (isset ($_POST['remember']) ? $_POST['remember'] : "");
|
||||
$ota = $userManager->haveOtaEnabled($userName);
|
||||
if ($ota == "") {
|
||||
$landingPage = $userManager->login($userName, $userPassword, $rememberMe);
|
||||
header('Location: ' . BASEURL . $landingPage);
|
||||
die();
|
||||
}
|
||||
|
||||
$_SESSION['USERNAME'] = $userName;
|
||||
$_SESSION['PASSWORD'] = $userPassword;
|
||||
$_SESSION['REMEMBER'] = $rememberMe;
|
||||
$_SESSION['OTA'] = $ota;
|
||||
} else if (
|
||||
isset($_POST['otaCode']) &&
|
||||
$_POST['otaCode'] != ''
|
||||
) {
|
||||
|
||||
$otaCode = $_POST['otaCode'];
|
||||
$otaSecret = $_POST['otaSecret'];
|
||||
|
||||
$ga = new PHPGangsta_GoogleAuthenticator();
|
||||
$ota = $_SESSION['OTA'];
|
||||
$userName = $_SESSION['USERNAME'];
|
||||
$userPassword = $_SESSION['PASSWORD'];
|
||||
$rememberMe = $_SESSION['REMEMBER'];
|
||||
unset($_SESSION['OTA']);
|
||||
$checkResult = $ga->verifyCode($otaSecret, $otaCode, 2); // 2 = 2*30sec clock tolerance
|
||||
if ($checkResult) {
|
||||
$landingPage = $userManager->login($userName, $userPassword, $rememberMe);
|
||||
header('Location: ' . BASEURL . '/');
|
||||
echo 'OK';
|
||||
} else {
|
||||
echo 'FAILED';
|
||||
}
|
||||
//TODO: upravi a ověřit jeslti ja zabezpečené
|
||||
//TODO:
|
||||
die();
|
||||
}
|
29
app/controllers/settingController.php
Normal file
29
app/controllers/settingController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
if (isset($_POST) && !empty($_POST)){
|
||||
if (isset($_POST['submitPasswordChange']) && $_POST['submitPasswordChange'] != "") {
|
||||
$oldPassword = $_POST['oldPassword'];
|
||||
$newPassword = $_POST['newPassword1'];
|
||||
$newPassword2 = $_POST['newPassword2'];
|
||||
UserManager::changePassword($oldPassword, $newPassword, $newPassword2);
|
||||
header('Location: ' . BASEURL . 'logout');
|
||||
die();
|
||||
} else if (isset($_POST['submitCreateUser']) && $_POST['submitCreateUser'] != "") {
|
||||
$userName = $_POST['userName'];
|
||||
$password = $_POST['userPassword'];
|
||||
UserManager::createUser($userName, $password);
|
||||
header('Location: ' . BASEURL . 'setting');
|
||||
die();
|
||||
} else if (isset($_POST['submitEnableOta']) && $_POST['submitEnableOta'] != "") {
|
||||
echo $otaCode = $_POST['otaCode'];
|
||||
echo $otaSecret = $_POST['otaSecret'];
|
||||
|
||||
|
||||
$ga = new PHPGangsta_GoogleAuthenticator();
|
||||
$checkResult = $ga->verifyCode($otaSecret, $otaCode, 2); // 2 = 2*30sec clock tolerance
|
||||
if ($checkResult) {
|
||||
UserManager::setOta($otaCode, $otaSecret);
|
||||
}
|
||||
header('Location: ' . BASEURL . 'setting');
|
||||
die();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user