adduser call via ajax

This commit is contained in:
Tim Krehan 2018-11-10 16:52:47 +01:00
parent 2f3c8f7390
commit 8758254a0f
6 changed files with 46 additions and 28 deletions

25
bin/adduser.js Normal file
View file

@ -0,0 +1,25 @@
$(document).ready(function(){
$("#button_newuser").click(function(){
$.post("/php/edit-user.php",
{
function: "new-user",
username: $("#text_user").val(),
passwd: $("#text_passwd").val()
},
function(data){
if(data==0){
infoPopUp("Benutzer erfolgreich erstellt!");
$("#text_user").val("");
$("#text_passwd").val("");
$("#adduser-button-done").removeClass("button-disabled");
}
else {
infoPopUp("Fehler bei der Benutzeranlage!");
}
}
);
});
$("#adduser-button-done").click(function(){
window.location.href = "/";
});
});

View file

@ -1,4 +1,4 @@
# prevent access to these files while not logged in
<files "adduser.php">
Require all denied
<files "*.php">
Require all denied
</files>

View file

@ -1,14 +1,13 @@
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/style/master.css">
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0"> -->
<!-- <link rel="stylesheet" href="/style/master.css"> -->
<link rel="stylesheet" href="/style/adduser.css">
<script src="/bin/adduser.js" charset="utf-8"></script>
</head>
<h1>Benutzer hinzufügen</h1>
<form class="adduser" action="/php/edit-user.php" method="post">
<div class="adduser">
<label for="text_user">Benutzername</label><input id="text_user" type="text" name="username" placeholder="user" required>
<label for="text_passwd">Passwort</label><input id="text_passwd" type="password" name="passwd" placeholder="********" required>
<input type="text" name="function" value="new-user" hidden>
<input id="button_newuser" class="button" type="submit" name="" value="Neuer Benutzer">
</form>
<!-- TODO: ADD JQUERY CALL TO EDIT-USER.PHP WITH FEEDBACK VIA JS FUNCTION INFOPOPUP() -->
</div>
<button class="button button-disabled" id="adduser-button-done">Fertig</button>

View file

@ -2,13 +2,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/style/master.css">
<link rel="stylesheet" href="/style/adduser.css">
<script src="/bin/jquery.js" charset="utf-8"></script>
<script src="/bin/index.js" charset="utf-8"></script>
<script src="/bin/adduser.js" charset="utf-8"></script>
</head>
<h1>Benutzer hinzufügen</h1>
<form class="adduser" action="/php/edit-user.php" method="post">
<div class="adduser">
<label for="text_user">Benutzername</label><input id="text_user" type="text" name="username" placeholder="user" required>
<label for="text_passwd">Passwort</label><input id="text_passwd" type="password" name="passwd" placeholder="********" required>
<input type="text" name="function" value="new-user" hidden>
<input id="button_newuser" class="button" type="submit" name="" value="Neuer Benutzer">
</form>
</div>
<button class="button button-disabled" id="adduser-button-done">Fertig</button>
<!-- TODO: ADD JQUERY CALL TO EDIT-USER.PHP WITH FEEDBACK VIA JS FUNCTION INFOPOPUP() -->
<!-- Only here in install/adduser -->
<div id="info-popup"><font id="info-popup-text"></font></div>

View file

@ -1,15 +0,0 @@
<?php
session_start();
include $_SESSION["docroot"].'/php/connect.php';
include $_SESSION["docroot"].'/php/hash.php';
$salt = create_salt();
$password = hash_password($_POST["passwd"], $salt);
$result = $mysqli->query("INSERT INTO `users` (`username`, `password`, `salt`, `last_login`) VALUES ('".$_POST["username"]."', '".$password."', '".$salt."', CURRENT_TIMESTAMP);");
$mysqli->close();
unset($salt);
unset($password);
header("Location: /");
?>

View file

@ -13,3 +13,8 @@ label {
flex-direction: column;
width: 50%;
}
#adduser-button-done {
position: absolute;
bottom: 2em;
right: 2em;
}