Compare commits

...

3 Commits

6 changed files with 71 additions and 25 deletions

View File

@ -38,7 +38,7 @@ h2 {
} }
main { main {
margin-top: 135px; margin-top: 190px;
padding: 10px; padding: 10px;
} }
@ -104,10 +104,6 @@ label.errorMsg {
color: orange; color: orange;
} }
input {
width: 300px;
}
input[type="submit"] { input[type="submit"] {
width: 100px; width: 100px;
margin-left: 330px; margin-left: 330px;

View File

@ -9,7 +9,6 @@ class UserController{
private $db; private $db;
private $validData = array(); private $validData = array();
private $errors = array(); private $errors = array();
private $labels = array("name" => "Name", "email" => "E-Mail-Adresse", "content" => "Nachricht");
public function __construct($view){ public function __construct($view){
$this->db = new UserModel(); $this->db = new UserModel();
@ -20,8 +19,21 @@ class UserController{
} }
public function showUserConfirmation(){
}
public function showUserLoginForm(){
}
public function register(){ public function register(){
$this->db->createUser($this->labels); $this->db->createUser($_POST);
$this->view->setDoMethodName("showUserConfirmation");
$this->showUserConfirmation();
}
public function login(){
} }
} }

View File

@ -11,31 +11,30 @@ class UserModel extends Database
/** /**
* @throws RandomException * @throws RandomException
*/ */
public function createUser($values) public function createUser($values){
{
$salt = bin2hex(random_bytes(16)); $salt = bin2hex(random_bytes(16));
$hash = hash('sha256', $values["password"] . $salt); $hash = hash('sha256', $values["password"] . $salt);
$guid = $this->createUUID(); $guid = rand(0, 500);
$pdo = $this->linkDB(); $pdo = $this->linkDB();
$sql = "INSERT INTO users (`id`,`vorname`,`name`,`email`,`passwort`,`salt`,`role`) $sql = "INSERT INTO user (`id`, `name`,`vorname`,`email`,`passwort`,`salt`,`role`)
VALUES (:guid, :name, :lastname, :email, :password, :salt, :role)"; VALUES (:guid, :name, :firstname, :email, :password, :salt, :role)";
try { try {
$sth = $pdo->prepare($sql); $sth = $pdo->prepare($sql);
$sth->execute(array $sth->execute([
(":guid" => $guid, ":guid" => $guid,
(":name") => $values["name"], ":name" => $values["name"],
":lastname" => $values["lastname"], ":firstname" => $values["lastname"],
":email" => $values["email"], ":email" => $values["email"],
":password" => $hash, ":password" => $hash,
":salt" => $salt, ":salt" => $salt,
":role" => $values["role"] ":role" => $values["role"]
)); ]);
} catch (PDOException $e) { } catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Schreiben der Daten.", $e); new \Blog\Library\ErrorMsg("Fehler beim Schreiben der Daten.", $e);
die; die;

View File

@ -0,0 +1,11 @@
<?php
include dirname(__DIR__).'/header.phtml';
?>
<h1>Sie haben sich erfolgreich registriert</h1>
<?php
include dirname(__DIR__).'/footer.phtml';
?>

View File

@ -2,9 +2,9 @@
include dirname(__DIR__).'/header.phtml'; include dirname(__DIR__).'/header.phtml';
?> ?>
<h1>Benutzer</h1> <h1>Benutzer erstellen</h1>
<form method="post" action="register"> <form method="post">
<h2>Registrieren</h2> <h2>Registrieren</h2>
<label for="reg_name">Vorname:</label> <label for="reg_name">Vorname:</label>
@ -14,21 +14,26 @@
<input type="text" name="lastname" id="reg_lastname" required> <input type="text" name="lastname" id="reg_lastname" required>
<label for="reg_email">Email:</label> <label for="reg_email">Email:</label>
<input type="text" name="email" id="reg_email" required> <input type="email" name="email" id="reg_email" required>
<label for="reg_password">Passwort:</label> <label for="reg_password">Passwort:</label>
<input type="text" name="password" id="reg_password" required> <input type="password" name="password" id="reg_password" required>
<p>Wähle deine Rolle:</p> <p>Wähle deine Rolle:</p>
<label> <label>
<input type="radio" name="role" value="course_instructor" required> Student <input type="radio" name="role" value="user" required> User
</label> </label>
<label> <label>
<input type="radio" name="role" value="member"> Lehrer <input type="radio" name="role" value="leiter"> Leiter
</label> </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> </form>
<a href="?controller=User&do=showUserLoginForm">Haben Sie schon ein Benutzer Konto?</a>
<?php <?php
include dirname(__DIR__).'/footer.phtml'; include dirname(__DIR__).'/footer.phtml';
?> ?>

View 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="register">
<button type="submit" style="display: block">Login</button>
</form>
<?php
include dirname(__DIR__).'/footer.phtml';
?>