Merge branch 'main' of https://git.bib.de/PBBFA23AHR/kurs-app
This commit is contained in:
commit
6083a3f1c4
@ -1,3 +1,7 @@
|
||||
main a{
|
||||
color: var(--brand-white)
|
||||
}
|
||||
|
||||
.form-flex {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@ -59,3 +63,4 @@ input, textarea {
|
||||
font-size: 1rem;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ h2 {
|
||||
}
|
||||
|
||||
main {
|
||||
margin-top: 135px;
|
||||
margin-top: 190px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
|
@ -9,19 +9,47 @@ class UserController{
|
||||
private $db;
|
||||
private $validData = array();
|
||||
private $errors = array();
|
||||
private $labels = array("name" => "Name", "email" => "E-Mail-Adresse", "content" => "Nachricht");
|
||||
|
||||
public function __construct($view){
|
||||
$this->db = new UserModel();
|
||||
$this->view = $view;
|
||||
}
|
||||
|
||||
public function showUserForm(){
|
||||
public function showUserRegisterForm(){
|
||||
|
||||
}
|
||||
|
||||
public function showUserConfirmation(){
|
||||
|
||||
}
|
||||
|
||||
public function showUserLoginForm(){
|
||||
|
||||
}
|
||||
|
||||
public function register(){
|
||||
$this->db->createUser($this->labels);
|
||||
$this->db->createUser($_POST);
|
||||
$this->view->setDoMethodName("showUserConfirmation");
|
||||
$this->showUserConfirmation();
|
||||
}
|
||||
|
||||
public function login(){
|
||||
$user = $this->db->getUserByEmail($_POST["email"]);
|
||||
|
||||
if(!$user){
|
||||
echo "Benutzer nicht gefunden";
|
||||
}
|
||||
|
||||
$hash = hash('sha256', $_POST["password"] . $user["salt"]);
|
||||
|
||||
if($hash == $user["passwort"]){
|
||||
$_SESSION["user_id"] = $user["id"];
|
||||
$_SESSION["user_role"] = $user["role"];
|
||||
echo "Login ergolgreich";
|
||||
}else{
|
||||
echo "Falsches Passwort";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -11,31 +11,30 @@ class UserModel extends Database
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public function createUser($values)
|
||||
{
|
||||
public function createUser($values){
|
||||
|
||||
$salt = bin2hex(random_bytes(16));
|
||||
|
||||
$hash = hash('sha256', $values["password"] . $salt);
|
||||
|
||||
$guid = $this->createUUID();
|
||||
$guid = rand(0, 500);
|
||||
|
||||
$pdo = $this->linkDB();
|
||||
|
||||
$sql = "INSERT INTO users (`id`,`vorname`,`name`,`email`,`passwort`,`salt`,`role`)
|
||||
VALUES (:guid, :name, :lastname, :email, :password, :salt, :role)";
|
||||
$sql = "INSERT INTO user (`id`, `name`,`vorname`,`email`,`passwort`,`salt`,`role`)
|
||||
VALUES (:guid, :name, :firstname, :email, :password, :salt, :role)";
|
||||
|
||||
try {
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute(array
|
||||
(":guid" => $guid,
|
||||
(":name") => $values["name"],
|
||||
":lastname" => $values["lastname"],
|
||||
$sth->execute([
|
||||
":guid" => $guid,
|
||||
":name" => $values["name"],
|
||||
":firstname" => $values["lastname"],
|
||||
":email" => $values["email"],
|
||||
":password" => $hash,
|
||||
":salt" => $salt,
|
||||
":role" => $values["role"]
|
||||
));
|
||||
]);
|
||||
} catch (PDOException $e) {
|
||||
new \Blog\Library\ErrorMsg("Fehler beim Schreiben der Daten.", $e);
|
||||
die;
|
||||
@ -44,4 +43,12 @@ class UserModel extends Database
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getUserByEmail($email){
|
||||
$pdo = $this->linkDB();
|
||||
$sql = "SELECT * FROM user WHERE email = :email";
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute([":email" => $email]);
|
||||
return $sth->fetch();
|
||||
}
|
||||
|
||||
}
|
11
Views/User/showUserConfirmation.phtml
Normal file
11
Views/User/showUserConfirmation.phtml
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
include dirname(__DIR__).'/header.phtml';
|
||||
?>
|
||||
|
||||
<h1>Sie haben sich erfolgreich registriert</h1>
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
include dirname(__DIR__).'/footer.phtml';
|
||||
?>
|
@ -1,34 +0,0 @@
|
||||
<?php
|
||||
include dirname(__DIR__).'/header.phtml';
|
||||
?>
|
||||
|
||||
<h1>Benutzer</h1>
|
||||
|
||||
<form method="post" action="register">
|
||||
<h2>Registrieren</h2>
|
||||
|
||||
<label for="reg_name">Vorname:</label>
|
||||
<input type="text" name="name" id="reg_name" required>
|
||||
|
||||
<label for="reg_lastname">Nachname:</label>
|
||||
<input type="text" name="lastname" id="reg_lastname" required>
|
||||
|
||||
<label for="reg_email">Email:</label>
|
||||
<input type="text" name="email" id="reg_email" required>
|
||||
|
||||
<label for="reg_password">Passwort:</label>
|
||||
<input type="text" name="password" id="reg_password" required>
|
||||
|
||||
<p>Wähle deine Rolle:</p>
|
||||
<label>
|
||||
<input type="radio" name="role" value="course_instructor" required> Student
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" name="role" value="member"> Lehrer
|
||||
</label>
|
||||
|
||||
</form>
|
||||
|
||||
<?php
|
||||
include dirname(__DIR__).'/footer.phtml';
|
||||
?>
|
23
Views/User/showUserLoginForm.phtml
Normal file
23
Views/User/showUserLoginForm.phtml
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
include dirname(__DIR__).'/header.phtml';
|
||||
?>
|
||||
|
||||
<h1>Als Benutzer anmelden</h1>
|
||||
|
||||
<form method="post">
|
||||
|
||||
<label for="reg_email">Email:</label>
|
||||
<input type="email" name="email" id="reg_email" required>
|
||||
|
||||
<label for="reg_password">Passwort:</label>
|
||||
<input type="password" name="password" id="reg_password" required>
|
||||
|
||||
<input type="hidden" name="controller" value="user">
|
||||
<input type="hidden" name="do" value="login">
|
||||
<button type="submit" class="btn" style="display: block">Login</button>
|
||||
</form>
|
||||
|
||||
|
||||
<?php
|
||||
include dirname(__DIR__).'/footer.phtml';
|
||||
?>
|
39
Views/User/showUserRegisterForm.phtml
Normal file
39
Views/User/showUserRegisterForm.phtml
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
include dirname(__DIR__).'/header.phtml';
|
||||
?>
|
||||
|
||||
<h1>Benutzer erstellen</h1>
|
||||
|
||||
<form method="post">
|
||||
<h2>Registrieren</h2>
|
||||
|
||||
<label for="reg_name">Vorname:</label>
|
||||
<input type="text" name="name" id="reg_name" required>
|
||||
|
||||
<label for="reg_lastname">Nachname:</label>
|
||||
<input type="text" name="lastname" id="reg_lastname" required>
|
||||
|
||||
<label for="reg_email">Email:</label>
|
||||
<input type="email" name="email" id="reg_email" required>
|
||||
|
||||
<label for="reg_password">Passwort:</label>
|
||||
<input type="password" name="password" id="reg_password" required>
|
||||
|
||||
<p>Wähle deine Rolle:</p>
|
||||
<label>
|
||||
<input type="radio" name="role" value="user" required> User
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" name="role" value="leiter"> Leiter
|
||||
</label>
|
||||
|
||||
<input type="hidden" name="controller" value="user">
|
||||
<input type="hidden" name="do" value="register">
|
||||
<button type="submit" class="btn" style="display: block">Registrieren</button>
|
||||
</form>
|
||||
|
||||
<a href="?controller=User&do=showUserLoginForm">Haben Sie schon ein Benutzer Konto?</a>
|
||||
|
||||
<?php
|
||||
include dirname(__DIR__).'/footer.phtml';
|
||||
?>
|
@ -20,7 +20,7 @@
|
||||
<h3 class="logo">bib<span>course</span></h3>
|
||||
<div id="metanavi">
|
||||
<a class="btn btn-user" href="?controller=Admin&do=showForm"><span class="material-icons">person</span></a>
|
||||
<a class="btn btn-register" href="?controller=User&do=showUserForm">Registration</a>
|
||||
<a class="btn btn-register" href="?controller=User&do=showUserRegisterForm">Registration</a>
|
||||
</div>
|
||||
</div>
|
||||
<nav>
|
||||
|
Loading…
x
Reference in New Issue
Block a user