diff --git a/CSS/Element/form.css b/CSS/Element/form.css index 29410dc..3036e98 100644 --- a/CSS/Element/form.css +++ b/CSS/Element/form.css @@ -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; } + diff --git a/CSS/style.css b/CSS/style.css index ae458ab..916a53f 100644 --- a/CSS/style.css +++ b/CSS/style.css @@ -35,7 +35,7 @@ h2 { } main { - margin-top: 135px; + margin-top: 190px; padding: 10px; } diff --git a/Controller/UserController.php b/Controller/UserController.php index ed2a3c5..463c83a 100644 --- a/Controller/UserController.php +++ b/Controller/UserController.php @@ -5,23 +5,51 @@ namespace Blog\Controller; use Blog\Model\UserModel; class UserController{ - private $view; + private $view; 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"; + } + + } } \ No newline at end of file diff --git a/Model/UserModel.php b/Model/UserModel.php index 3abd03c..ed2a2de 100644 --- a/Model/UserModel.php +++ b/Model/UserModel.php @@ -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(); + } + } \ No newline at end of file diff --git a/Views/User/showUserConfirmation.phtml b/Views/User/showUserConfirmation.phtml new file mode 100644 index 0000000..2788b36 --- /dev/null +++ b/Views/User/showUserConfirmation.phtml @@ -0,0 +1,11 @@ + + +