added login, logout and registration sites and functionality as well as an protected profile page
This commit is contained in:
parent
cbebac47fa
commit
5b3f5a1123
12 changed files with 163 additions and 28 deletions
|
|
@ -1,3 +1,28 @@
|
|||
<?php
|
||||
$heading = "Login";
|
||||
require "views/login.view.php";
|
||||
$heading = "Login";
|
||||
$username = "MatheApp";
|
||||
$password = "password";
|
||||
$config = require('config.php');
|
||||
$db = new Database($config['database'], $username, $password);
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
$stmt = $db->query("SELECT * FROM user WHERE username = :user", ['user' => $_POST["username"]])->get();
|
||||
$count = sizeof($stmt);
|
||||
if ($count == 1) {
|
||||
$stmt = $stmt[0];;
|
||||
|
||||
if (password_verify($_POST['password'], $stmt["password"])) {
|
||||
session_start();
|
||||
$_SESSION["username"] = $stmt['username'];
|
||||
//require "views/profile.php";
|
||||
//urlIs("/profile");
|
||||
header("Location: /profile");
|
||||
} else {
|
||||
echo "Anmeldung fehlgeschlagen!";
|
||||
}
|
||||
} else {
|
||||
echo "Anmeldung fehlgeschlagen!";
|
||||
}
|
||||
}
|
||||
|
||||
require "views/login.view.php";
|
||||
|
|
|
|||
4
controllers/logout.php
Normal file
4
controllers/logout.php
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
session_start();
|
||||
session_destroy();
|
||||
header("Location: /");
|
||||
8
controllers/profile.php
Normal file
8
controllers/profile.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
$heading = "profile";
|
||||
session_start();
|
||||
if(!isset($_SESSION["username"])){
|
||||
header("Location: /");
|
||||
exit;
|
||||
}
|
||||
require "views/profile.view.php";
|
||||
39
controllers/register.php
Normal file
39
controllers/register.php
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
$heading = "Register";
|
||||
require 'Validator.php';
|
||||
$username = 'MatheApp';
|
||||
$password = 'password';
|
||||
$config = require('config.php');
|
||||
$db = new Database($config['database'], $username, $password);
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
$stmt = $db->query("SELECT * FROM user WHERE username = :user", ['user' => $_POST['Username']])->get();
|
||||
$count = sizeof($stmt);
|
||||
if($count == 0 && Validator::string($_POST['Username'], 1, 255)){
|
||||
$checkEmail = $db->query("SELECT * FROM user WHERE email = :email", ['email' => $_POST['Email-Adresse']])->find();
|
||||
if(!$checkEmail && Validator::string($_POST['Email-Adresse'], 1, 255)) {
|
||||
if($_POST["Passwort"] == $_POST["pw2"] && Validator::string($_POST['Passwort'], 8, 255)) {
|
||||
//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 )", [
|
||||
'username' => $_POST['Username'],
|
||||
'vorname' => $_POST['Vorname'],
|
||||
'nachname' => $_POST['Nachname'],
|
||||
'email' => $_POST['Email-Adresse'],
|
||||
'password' => $hash,
|
||||
'level' => 1,
|
||||
'xp' => 0,
|
||||
'coins' => 0
|
||||
]);
|
||||
} else {
|
||||
echo "Die Passwörter stimmen nicht überein";
|
||||
}
|
||||
} else {
|
||||
echo "Der Username ist bereits vergeben";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
require "views/register.view.php";
|
||||
Loading…
Add table
Add a link
Reference in a new issue