add login php code

This commit is contained in:
Christopher 2020-10-23 23:26:23 +02:00
parent f7f8954435
commit 29ef76759c
1 changed files with 30 additions and 40 deletions

View File

@ -1,47 +1,37 @@
<?php
if(isset($_POST['do-login']))
{
if(isset($_POST['containername']) || isset($_POST['accesskey']))
{
$dockerClient = new Docker();
$allContainers = $dockerClient->getAllContainers();
$container = NULL;
foreach($allContainers as $thisContainer)
{
$apiKey = calcAPIKey($thisContainer);
if($apiKey == $_POST['accesskey'])
$container = $thisContainer;
}
if($container != NULL)
{
$_SESSION['LOGIN'] = "true";
$_SESSION['CONTAINER'] = $container['Name'];
include "./pages/dashboard.php";
die();
}
}
}
$HTML = new HTML();
$HTML->setHTMLTitle("Login");
$HTML->importHTML("style/default/login.html");
if(isset($_POST['login']))
{
if(!isset($_POST['username']) || !isset($_POST['password']))
{
$HTML->ReplaceLayoutInhalt("%%LOGINMESSAGE%%", "Bitte gebe Benutzername und Passwort an.");
}else{
$statement = $RUNTIME['PDO']->prepare("SELECT * FROM users WHERE username = ? LIMIT 1");
$statement->execute(array(trim($_POST['username'])));
while($row = $statement->fetch())
{
if(md5($_POST['password']) == $row['password'])
{
$_SESSION['USERNAME'] = $row['username'];
$_SESSION['DISPLAYNAME'] = strtoupper($row['username']);
$_SESSION['PREAUTH'] = 'true';
//$_SESSION['LOGIN'] = 'true';
include "pages/2faktor-login.php";
die();
}
}
$HTML->ReplaceLayoutInhalt("%%LOGINMESSAGE%%", "Benutzername oder Passwort falsch.");
}
}
if(isset($_REQUEST['2fakey']))
{
include "pages/2faktor-login.php";
die();
}
if(file_exists("./pages/".@$_REQUEST['page'].".php"))
$HTML->ReplaceLayoutInhalt("%%PAGENAME%%", @$_REQUEST['page']);
$HTML->ReplaceLayoutInhalt("%%LOGINMESSAGE%%", "");
$HTML->build();
echo $HTML->ausgabe();
?>