added user id to generated tans

This commit is contained in:
Marcel Schwarz 2018-06-17 23:05:13 +02:00
parent 41829bbbf0
commit c4c5fc1fb8
6 changed files with 26 additions and 28 deletions

View File

@ -13,6 +13,11 @@
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<script>
var PHPSESSIONUSER = '<?php echo $_SESSION['user']; ?>';
console.log(PHPSESSIONUSER);
</script>
</head>
@ -64,6 +69,9 @@
<div id="content">
<br><span> Session User: <?php echo $_SESSION['user']; ?> </span>
<br>
</div>
<!-- Include the footer-->

View File

@ -1,12 +1,18 @@
window.addEventListener('load', async () => {
console.log("Seite geladen");
//getNewUniqueLink();
document.getElementById('btnCreateTan').addEventListener('click' , async (event) => getNewUniqueLink());
})
async function getNewUniqueLink() {
const phpSessionForm = new FormData();
phpSessionForm.append("phpSession", PHPSESSIONUSER);
try {
var firstFetch = await fetch('php/generateLink.php');
var firstFetch = await fetch('php/generateLink.php', {
method: 'post',
body: phpSessionForm
});
var jsonFirstFetch = await firstFetch.json();
var content = document.getElementById('content');
content.innerHTML = `${jsonFirstFetch.html}`;
@ -32,3 +38,8 @@ document.getElementById('btnCreate').addEventListener("click" , async (event) =>
console.log("Abschicken der Daten fehlerhaft!");
}
})
function getCookieValue(a) {
var b = document.cookie.match('(^|;)\\s*' + a + '\\s*=\\s*([^;]+)');
return b ? b.pop() : '';
}

View File

@ -10,7 +10,7 @@
$resultStr = getTanID($uniqueID);
$HTMLJSON = array('html' => $resultStr);
$HTMLJSON = array('html' => $resultStr , 'userid' => $_POST['phpSession']);
echo json_encode($HTMLJSON);
function insertTan($tan) {
@ -19,7 +19,9 @@
$stmt = $database->prepare("INSERT INTO tans (tan, userID, used) VALUES (?, ?, ?)");
$used = false;
$userid = 1;
$userid = $_POST['phpSession'];
//$userid = $_SESSION['user'];
//$userid = $_POST['userid'];
$stmt->bind_param("ssi", $tan, $userid, $used);
try {

1
php/getSession.php Normal file
View File

@ -0,0 +1 @@
<?php echo json_encode($_SESSION['user']) ?>

View File

@ -1,24 +0,0 @@
<?php
//<!--Login-->
if(isset($_POST['login-form'])){
session_start();
require('dbConnect.php');
$name = ($_POST['loginName']);
$pswd = ($_POST['loginPassword']);
$pswd = md5($pswd);
$stmt = $database->prepare("SELECT id FROM user WHERE '$name'=user AND password='$pswd'");
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 1) {
$object = $result->fetch_object();
$_SESSION['user'] = $object->id;
echo "Einloggen erfolgreich";
} else {
echo "Einloggen fehlgeschlagen";
}
}
?>

View File

@ -14,7 +14,7 @@ if( (isset($_POST['loginName'])) && isset($_POST['loginPassword'])){
$object = $result->fetch_object();
$_SESSION['user'] = $object->id;
echo "Einloggen erfolgreich";
header("refresh:2;");
header("refresh:1;");
} else {
echo "Einloggen fehlgeschlagen";
}