added delete function to th application

This commit is contained in:
Patryk Hegenberg 2023-01-08 20:24:13 +01:00
parent 204e212fb8
commit a19e40f205
7 changed files with 74 additions and 10 deletions

12
controllers/delete.php Normal file
View file

@ -0,0 +1,12 @@
<?php
$heading = "Delete";
$username = "MatheApp";
$password = "password";
$config = require('config.php');
$db = new Database($config['database'], $username, $password);
session_start();
$db->query("DELETE FROM user WHERE username = :user", ["user" => $_SESSION['username']]);
session_destroy();
header("Location: /");
exit;

View file

@ -14,8 +14,11 @@ if (isset($_POST["submit"])) {
if (password_verify($_POST['password'], $stmt["password"])) {
session_start();
$_SESSION["username"] = $stmt['username'];
//require "views/profile.php";
//urlIs("/profile");
$_SESSION["level"] = $stmt['level'];
$_SESSION["xp"] = $stmt['xp'];
$_SESSION["coins"] = $stmt['coins'];
$_SESSION["lesson_count"] = $stmt['lesson_count'];
header("Location: /profile");
} else {
echo "Anmeldung fehlgeschlagen!";

View file

@ -1,8 +1,14 @@
<?php
$heading = "profile";
$username = "MatheApp";
$password = "password";
$config = require('config.php');
$db = new Database($config['database'], $username, $password);
session_start();
if(!isset($_SESSION["username"])){
header("Location: /");
exit;
}
require "views/profile.view.php";

View file

@ -16,17 +16,19 @@
//Username ist frei
//User anlegen
$hash = password_hash($_POST["Passwort"], PASSWORD_BCRYPT);
$db->query("INSERT INTO user (username, vorname, nachname, email, password, level, xp, coins) VALUES (
:username, :vorname, :nachname, :email, :password, :level, :xp, :coins )", [
$db->query("INSERT INTO user (username, vorname, nachname, email, password, lesson_count, level, xp, coins) VALUES (
:username, :vorname, :nachname, :email, :password, :lesson_count, :level, :xp, :coins )", [
'username' => $_POST['Username'],
'vorname' => $_POST['Vorname'],
'nachname' => $_POST['Nachname'],
'email' => $_POST['Email-Adresse'],
'password' => $hash,
'lesson_count' => 0,
'level' => 1,
'xp' => 0,
'coins' => 0
]);
header("Location: /login");
} else {
echo "Die Passwörter stimmen nicht überein";
}

View file

@ -8,5 +8,6 @@ return[
'/login' => 'controllers/login.php',
'/register' => 'controllers/register.php',
'/profile' => 'controllers/profile.php',
'/logout' => 'controllers/logout.php'
'/logout' => 'controllers/logout.php',
'/delete' => 'controllers/delete.php'
];

View file

@ -2,9 +2,49 @@
<?php require('partials/nav.php') ?>
<div class="flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
<div class="w-full max-w-md space-y-8 nes-container">
<h1>Dieses ist die Profile Page</h1>
<a href="/logout" class="<?= urlIs("/logout") ?> nes-btn">Abmelden</a>
</div>
<div class="flex-col">
<div class="w-1000 space-y-8 nes-container">
<section class="message-list flex-auto">
<section class="message -left flex space-x-10">
<i class="nes-bcrikko mr-10"></i>
<div class="nes-balloon from-left mx-10">
<p>Hallo <?= $_SESSION['username'] ?> schön das du da bist.</p>
</div>
</section>
</section>
<div class="nes-container flex-col justife-center items-center space-y-4">
<div class="text-center">
<h1>Was möchtest du tun?</h1>
</div>
<div class="flex justify-evenly items-center">
<a href="/learn" class="<?= urlIs("/learn") ?> nes-btn">Lernen</a>
<a href="/game" class="<?= urlIs("/game") ?> nes-btn">Üben</a>
</div>
</div>
</div>
<div class="nes-container with-title flex-col mt-10 space-y-4">
<span class="title">Dein Fortschritt <?php $_SESSION['xp'] ?> </span>
<span>Du bist aktuell Level: <?php echo $_SESSION['level'] ?> </span>
<br>
<span>Deine Erfahrungspunkte</span>
<progress class="nes-progress is-primary" value="<?php echo $_SESSION['xp'] ?>" max="150">Erfahrung</progress>
<span>Dein aktueller Lernfortschritt</span>
<progress class="nes-progress is-success" value="<?php echo $_SESSION['lesson_count'] ?>" max="10">Absolvierte Lektionen</progress>
<div class="flex flex-rows justify-center">
<div>
<span><i class="nes-icon coin is-medium"></i></span>
</div>
<div>
<p><?php echo $_SESSION['coins'] ?></p>
</div>
</div>
</div>
<div class="nes-container mt-10">
<div>
<a href="/delete" class="nes-btn is-error">Account löschen</a>
</div>
</div>
</div>
</div>
<?php require('partials/footer.php') ?>

View file

@ -2,7 +2,7 @@
<?php require('partials/nav.php') ?>
<div class="flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
<div class="w-full max-w-md space-y-8 nes-container">
<form action="/login" method="POST">
<form action="/register" method="POST">
<div class="nes-field">
<label for="username">Username</label>