lollipop

A PHP-framework
Log | Files | Refs

commit f5946c0dcedb7330fc3e283d0cf425bba734f536
parent e10101b54dcc4b25a7b8bc34605f0e9e89733dad
Author: Gerco van Woudenbergh <[email protected]>
Date:   Mon, 12 Jun 2023 15:26:29 +0200

login and add user work just permissions left

Diffstat:
MController/login/login_post.php | 20++++++++++----------
AController/logout/logout.php | 12++++++++++++
MController/user/add_post.php | 32++++++++++++++------------------
MLollipop/DatabaseObject.php | 2+-
MLollipop/Router.php | 8+++++---
MModel/Utils.php | 2+-
Mindex.php | 37+++++++++++++++++++++++++++++++++----
Dindex_BACKUP_17187.php | 70----------------------------------------------------------------------
Dindex_BACKUP_17395.php | 70----------------------------------------------------------------------
Dindex_BASE_17187.php | 29-----------------------------
Dindex_BASE_17395.php | 29-----------------------------
Dindex_LOCAL_17187.php | 48------------------------------------------------
Dindex_LOCAL_17395.php | 48------------------------------------------------
Dindex_REMOTE_17187.php | 41-----------------------------------------
Dindex_REMOTE_17395.php | 41-----------------------------------------
Mviews/add_user.html | 14+++++++-------
Aviews/dashboard.html | 12++++++++++++
Mviews/login.html | 8++++----
18 files changed, 99 insertions(+), 424 deletions(-)

diff --git a/Controller/login/login_post.php b/Controller/login/login_post.php @@ -1,13 +1,13 @@ <?php const login = "email"; -const pwd = "password"; +const pwd = "pwd"; class Login_handler { function login():bool{ $post_arr = Utils::post_to_array();; $missing_fields = Utils::missing_fields($post_arr , [login, pwd]); - if(sizeof($missing_fields) > 0){ + if(sizeof($missing_fields) == 0){ return ($this->authenticate($post_arr)); }else{ return false; @@ -18,16 +18,16 @@ class Login_handler //this function return true when user is autheticated uses set_globals to set $_SESSION variables { //create a SQLDatabase class - $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "panda"); + $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "lollipop"); //create a Database object class, with the table User - $u = $db->get(User::class); + $u = $db->get(Model\User::class); //check if the email exists in db - if(!$u->where($post[login])){ + if(!$u->load($post[login])){ //email does not exist return false; }else{ - if(password_verify($post[pwd], $u->password)){ + if(password_verify($post[pwd], $u->{pwd})){ //authenticated -> set $_SESSION variables $this->set_globals($u, $db); return true; @@ -44,16 +44,15 @@ class Login_handler { //start session and set session_start(); - $u->load($u->primary); + $u->load($u->get_primary()); foreach($u->getData() as $key => $data){ if($key != pwd){ $_SESSION[$key] = $data; } } - //get permissions form db and set sessions_permissions - $p = $db->all_where(Permission_user::class, array('id_user' => $u->id)); + $p = $db->all_where(Model\Permission_user::class, [login, $u->{login}]); foreach($p as $permission){ $user_permissions[] = $permission->id; } @@ -65,7 +64,8 @@ function login_handler(){ $login = new Login_handler(); if( $login->login()){ - echo $templater->template("views/dashboard.html", ["email" => $_SESSION["email"]]); + header("Location: dashboard"); + exit(); }else{ echo $templater->template("views/login.html", ["msg" => "<p style=\"color:red;\">Incorrect username or password.</p>"]); } diff --git a/Controller/logout/logout.php b/Controller/logout/logout.php @@ -0,0 +1,11 @@ +<?php +function logout(){ + // Start the session + session_start(); + + // Unset all session variables + $_SESSION = array(); + + // Destroy the session + session_destroy(); +} +\ No newline at end of file diff --git a/Controller/user/add_post.php b/Controller/user/add_post.php @@ -1,19 +1,25 @@ <?php -function add_user(){ - $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "panda"); - $u = $db->get(User::class); +function add_user(string $pwd_key){ + $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "lollipop"); + $u = $db->get(Model\User::class); - $post_arr = Utils::post_to_array();; + $post_arr = Utils::post_to_array(); $missing_fields = Utils::missing_fields($post_arr , $u->not_nullable); - if(sizeof($missing_fields) > 0) - return $missing_fields; + if(sizeof($missing_fields) > 0){ + foreach($missing_fields as $key => $data){ + if($post_arr[$key] == "") + $key .= "_error"; + $post_arr[$key] = $data; + } + return $post_arr; + } if($u->load($post_arr[$u->get_primary()])){ return ["msg" => "<p style=\"color:red;\">this email address is already taken: {$post_arr[$u->get_primary()]} </p>"]; }else{ - if($post_arr["password"]){ - $post_arr["password"] = password_hash($post_arr["password"], PASSWORD_DEFAULT); + if($post_arr[$pwd_key]){ + $post_arr[$pwd_key] = password_hash($post_arr[$pwd_key], PASSWORD_DEFAULT); } foreach($u->column_names as $col){ if($post_arr[$col] != ""){ @@ -28,14 +34,4 @@ function add_user(){ } -$templater = new Lollipop\Template(); -$response = add_user(); - -if(!array_key_exists("msg", $response)){ - $newArray = ["msg" => ""]; - array_push($newArray, $response); -} - -echo $templater->template("views/add_user.html", $response); - diff --git a/Lollipop/DatabaseObject.php b/Lollipop/DatabaseObject.php @@ -173,7 +173,7 @@ namespace Lollipop { $sql = " SELECT column_name, is_nullable, extra FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{$this->table}' - AND TABLE_SCHEMA = 'panda'"; + AND TABLE_SCHEMA = 'lollipop'"; $stmt = $this->db->conn->prepare($sql); $stmt->execute(); $result = $stmt->get_result(); diff --git a/Lollipop/Router.php b/Lollipop/Router.php @@ -5,16 +5,16 @@ namespace Lollipop { { protected array $routes = []; protected string $path; - protected final Template $temp; + protected Template $temp; - public function __contruct($temp) { + public function __construct($temp) { $this->temp = $temp; } protected function match(string $match, array &$route_vars): bool { $route_split = explode('/', trim($this->path, '/ ')); - $match_split = explode('/', trim($match, '/ '); + $match_split = explode('/', trim($match, '/ ')); if (sizeof($route_split) != sizeof($match_split)) { return false; @@ -71,8 +71,10 @@ namespace Lollipop { $fil = $route["func"]($vars); if (!is_null($fil)) echo $this->temp->template($fil, $vars); + return; } else { echo $this->temp->template($route["func"], $vars); + return; } } } diff --git a/Model/Utils.php b/Model/Utils.php @@ -19,7 +19,7 @@ Class Utils{ } function create_permission_radials():string{ - $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "panda"); + $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "lollipop"); //select the available permissions from the database $all_p = $db->all(Permissions::class); $radials = ""; diff --git a/index.php b/index.php @@ -1,19 +1,48 @@ <?php +use Lollipop\Template; require_once "utils/autoloader.php"; include "Controller/login/login_post.php"; -$router = new Lollipop\Router(); +$templater = new Template(); +$router = new Lollipop\Router($templater); //login -$router->addRoute(["GET"], "/", "Controller/login/login_get.php"); +$router->addRoute(["GET"], "/", "views/login.html"); $router->addRoute(["POST"], "/login", function($vars){ login_handler(); }); +//logout +$router->addRoute(["POST"], "/logout", function($vars){ + include "Controller/logout/logout.php"; + logout(); + return "views/login.html"; +}); + //user //add -$router->addRoute(["GET"], "/user/add", "Controller/user/add_get.php"); -$router->addRoute(["POST"], "/user/add", "Controller/user/add_post.php"); +$router->addRoute(["GET"], "/user/add", "views/add_user.html"); +$router->addRoute(["POST"], "/user/add", function(&$vars){ + include "Controller/user/add_post.php"; + $res = add_user("pwd"); + + foreach($res as $key => $data){ + $vars[$key] = $data; + } + + return "views/add_user.html"; +}); + +//dashboard +$router->addRoute(["GET"], "/dashboard", function(&$vars){ + session_start(); + foreach($_SESSION as $key => $data){ + $vars[$key] = $data; + } + + return "views/dashboard.html"; +}); + $router->route(); /* diff --git a/index_BACKUP_17187.php b/index_BACKUP_17187.php @@ -1,70 +0,0 @@ -<?php - -require_once "utils/autoloader.php"; -include "Controller/login/login_post.php"; - -<<<<<<< HEAD -$templater = new Lollipop\Template(); -$router = new Lollipop\Router($templater); - -$router->addRoute(["GET"], "/user/:email/update", "views/alter_user.php"); -$router->addRoute(["POST"], "/user/:email/update", user_add); -======= -$router = new Lollipop\Router(); -//login -$router->addRoute(["GET"], "/", "Controller/login/login_get.php"); -$router->addRoute(["POST"], "/login", function($vars){ - login_handler(); -}); - -//user -//add -$router->addRoute(["GET"], "/user/add", "Controller/user/add_get.php"); -$router->addRoute(["POST"], "/user/add", "Controller/user/add_post.php"); -$router->route(); - -/* -$router->addRoute(["GET", "POST"], "/user/:email/update", "views/alter_user.php"); ->>>>>>> 3e71e110537592f5d6e5c3f90f168dbbf3b5349f -$router->addRoute(["GET", "POST"], "/user/:email/crud", "views/crud_user.php"); -$router->addRoute(["GET", "POST"], "/user/search", "views/search_user.php"); -$router->addRoute(["GET", "POST"], "/dashboard", "views/dashboard.php"); -$router->addRoute(["GET", "POST"], "/", "views/login.php"); -$router->addRoute(["GET", "POST"], "/logout", "logic/logout.php"); -$router->addRoute(["GET", "POST"], "/course/search", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:enroll/enroll", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:unsubscribe/unsubscribe", "views/search_course.php"); -$router->addRoute(["GET"], "/api/:token/weatherdata.json", get_datadata_json); -$router->addRoute(["GET"], "/api/:token/weatherdata.xml", get_datadata_xml); - -$router->addRoute(["GET"], "/test/template/:hello", function(&$vars){ - $vars["xxx"] = "email"; - return "views/template_test.html"; -}); - -$router->addRoute(["GET"], "/user/add", function($vars) { - include "logic/user/add_get.php"; - $vars = database_permissions(); - $t = new Lollipop\Template(); - echo $t->template("views/add_user.html", $vars); -}); -$router->addRoute(["POST"], "/user/add", "logic/add_user_post.php"); -<<<<<<< HEAD - -$router->route(); - - - - -$router->addRoute(["GET"], "/login", function() { - if (is_login()) { - return "/views/"; - } else { - return "/views/" - } -}); - -$router->addRoute(["POST"], "/contol/login", login_post); -======= -*/ ->>>>>>> 3e71e110537592f5d6e5c3f90f168dbbf3b5349f diff --git a/index_BACKUP_17395.php b/index_BACKUP_17395.php @@ -1,70 +0,0 @@ -<?php - -require_once "utils/autoloader.php"; -include "Controller/login/login_post.php"; - -<<<<<<< HEAD -$templater = new Lollipop\Template(); -$router = new Lollipop\Router($templater); - -$router->addRoute(["GET"], "/user/:email/update", "views/alter_user.php"); -$router->addRoute(["POST"], "/user/:email/update", user_add); -======= -$router = new Lollipop\Router(); -//login -$router->addRoute(["GET"], "/", "Controller/login/login_get.php"); -$router->addRoute(["POST"], "/login", function($vars){ - login_handler(); -}); - -//user -//add -$router->addRoute(["GET"], "/user/add", "Controller/user/add_get.php"); -$router->addRoute(["POST"], "/user/add", "Controller/user/add_post.php"); -$router->route(); - -/* -$router->addRoute(["GET", "POST"], "/user/:email/update", "views/alter_user.php"); ->>>>>>> 3e71e110537592f5d6e5c3f90f168dbbf3b5349f -$router->addRoute(["GET", "POST"], "/user/:email/crud", "views/crud_user.php"); -$router->addRoute(["GET", "POST"], "/user/search", "views/search_user.php"); -$router->addRoute(["GET", "POST"], "/dashboard", "views/dashboard.php"); -$router->addRoute(["GET", "POST"], "/", "views/login.php"); -$router->addRoute(["GET", "POST"], "/logout", "logic/logout.php"); -$router->addRoute(["GET", "POST"], "/course/search", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:enroll/enroll", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:unsubscribe/unsubscribe", "views/search_course.php"); -$router->addRoute(["GET"], "/api/:token/weatherdata.json", get_datadata_json); -$router->addRoute(["GET"], "/api/:token/weatherdata.xml", get_datadata_xml); - -$router->addRoute(["GET"], "/test/template/:hello", function(&$vars){ - $vars["xxx"] = "email"; - return "views/template_test.html"; -}); - -$router->addRoute(["GET"], "/user/add", function($vars) { - include "logic/user/add_get.php"; - $vars = database_permissions(); - $t = new Lollipop\Template(); - echo $t->template("views/add_user.html", $vars); -}); -$router->addRoute(["POST"], "/user/add", "logic/add_user_post.php"); -<<<<<<< HEAD - -$router->route(); - - - - -$router->addRoute(["GET"], "/login", function() { - if (is_login()) { - return "/views/"; - } else { - return "/views/" - } -}); - -$router->addRoute(["POST"], "/contol/login", login_post); -======= -*/ ->>>>>>> 3e71e110537592f5d6e5c3f90f168dbbf3b5349f diff --git a/index_BASE_17187.php b/index_BASE_17187.php @@ -1,28 +0,0 @@ -<?php - -require_once "utils/autoloader.php"; - -$router = new Lollipop\Router(); - -$router->addRoute(["GET", "POST"], "/user/:email/update", "views/alter_user.php"); -$router->addRoute(["GET", "POST"], "/user/:email/crud", "views/crud_user.php"); -$router->addRoute(["GET", "POST"], "/user/search", "views/search_user.php"); -$router->addRoute(["GET", "POST"], "/dashboard", "views/dashboard.php"); -$router->addRoute(["GET", "POST"], "/", "views/login.php"); -$router->addRoute(["GET", "POST"], "/logout", "logic/logout.php"); -$router->addRoute(["GET", "POST"], "/course/search", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:enroll/enroll", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:unsubscribe/unsubscribe", "views/search_course.php"); -$router->addRoute(["GET"], "/test/template/:hello", function($vars) { - $t = new Lollipop\Template(); - echo $t->template("template_test.html", $vars); -}); -$router->addRoute(["GET"], "/user/add", function($vars) { - include "logic/user/add_get.php"; - $vars = database_permissions(); - $t = new Lollipop\Template(); - echo $t->template("views/add_user.html", $vars); -}); -$router->addRoute(["POST"], "/user/add", "logic/add_user_post.php"); - -$router->route(); -\ No newline at end of file diff --git a/index_BASE_17395.php b/index_BASE_17395.php @@ -1,28 +0,0 @@ -<?php - -require_once "utils/autoloader.php"; - -$router = new Lollipop\Router(); - -$router->addRoute(["GET", "POST"], "/user/:email/update", "views/alter_user.php"); -$router->addRoute(["GET", "POST"], "/user/:email/crud", "views/crud_user.php"); -$router->addRoute(["GET", "POST"], "/user/search", "views/search_user.php"); -$router->addRoute(["GET", "POST"], "/dashboard", "views/dashboard.php"); -$router->addRoute(["GET", "POST"], "/", "views/login.php"); -$router->addRoute(["GET", "POST"], "/logout", "logic/logout.php"); -$router->addRoute(["GET", "POST"], "/course/search", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:enroll/enroll", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:unsubscribe/unsubscribe", "views/search_course.php"); -$router->addRoute(["GET"], "/test/template/:hello", function($vars) { - $t = new Lollipop\Template(); - echo $t->template("template_test.html", $vars); -}); -$router->addRoute(["GET"], "/user/add", function($vars) { - include "logic/user/add_get.php"; - $vars = database_permissions(); - $t = new Lollipop\Template(); - echo $t->template("views/add_user.html", $vars); -}); -$router->addRoute(["POST"], "/user/add", "logic/add_user_post.php"); - -$router->route(); -\ No newline at end of file diff --git a/index_LOCAL_17187.php b/index_LOCAL_17187.php @@ -1,47 +0,0 @@ -<?php - -require_once "utils/autoloader.php"; - -$templater = new Lollipop\Template(); -$router = new Lollipop\Router($templater); - -$router->addRoute(["GET"], "/user/:email/update", "views/alter_user.php"); -$router->addRoute(["POST"], "/user/:email/update", user_add); -$router->addRoute(["GET", "POST"], "/user/:email/crud", "views/crud_user.php"); -$router->addRoute(["GET", "POST"], "/user/search", "views/search_user.php"); -$router->addRoute(["GET", "POST"], "/dashboard", "views/dashboard.php"); -$router->addRoute(["GET", "POST"], "/", "views/login.php"); -$router->addRoute(["GET", "POST"], "/logout", "logic/logout.php"); -$router->addRoute(["GET", "POST"], "/course/search", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:enroll/enroll", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:unsubscribe/unsubscribe", "views/search_course.php"); -$router->addRoute(["GET"], "/api/:token/weatherdata.json", get_datadata_json); -$router->addRoute(["GET"], "/api/:token/weatherdata.xml", get_datadata_xml); - -$router->addRoute(["GET"], "/test/template/:hello", function(&$vars){ - $vars["xxx"] = "email"; - return "views/template_test.html"; -}); - -$router->addRoute(["GET"], "/user/add", function($vars) { - include "logic/user/add_get.php"; - $vars = database_permissions(); - $t = new Lollipop\Template(); - echo $t->template("views/add_user.html", $vars); -}); -$router->addRoute(["POST"], "/user/add", "logic/add_user_post.php"); - -$router->route(); - - - - -$router->addRoute(["GET"], "/login", function() { - if (is_login()) { - return "/views/"; - } else { - return "/views/" - } -}); - -$router->addRoute(["POST"], "/contol/login", login_post); -\ No newline at end of file diff --git a/index_LOCAL_17395.php b/index_LOCAL_17395.php @@ -1,47 +0,0 @@ -<?php - -require_once "utils/autoloader.php"; - -$templater = new Lollipop\Template(); -$router = new Lollipop\Router($templater); - -$router->addRoute(["GET"], "/user/:email/update", "views/alter_user.php"); -$router->addRoute(["POST"], "/user/:email/update", user_add); -$router->addRoute(["GET", "POST"], "/user/:email/crud", "views/crud_user.php"); -$router->addRoute(["GET", "POST"], "/user/search", "views/search_user.php"); -$router->addRoute(["GET", "POST"], "/dashboard", "views/dashboard.php"); -$router->addRoute(["GET", "POST"], "/", "views/login.php"); -$router->addRoute(["GET", "POST"], "/logout", "logic/logout.php"); -$router->addRoute(["GET", "POST"], "/course/search", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:enroll/enroll", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:unsubscribe/unsubscribe", "views/search_course.php"); -$router->addRoute(["GET"], "/api/:token/weatherdata.json", get_datadata_json); -$router->addRoute(["GET"], "/api/:token/weatherdata.xml", get_datadata_xml); - -$router->addRoute(["GET"], "/test/template/:hello", function(&$vars){ - $vars["xxx"] = "email"; - return "views/template_test.html"; -}); - -$router->addRoute(["GET"], "/user/add", function($vars) { - include "logic/user/add_get.php"; - $vars = database_permissions(); - $t = new Lollipop\Template(); - echo $t->template("views/add_user.html", $vars); -}); -$router->addRoute(["POST"], "/user/add", "logic/add_user_post.php"); - -$router->route(); - - - - -$router->addRoute(["GET"], "/login", function() { - if (is_login()) { - return "/views/"; - } else { - return "/views/" - } -}); - -$router->addRoute(["POST"], "/contol/login", login_post); -\ No newline at end of file diff --git a/index_REMOTE_17187.php b/index_REMOTE_17187.php @@ -1,40 +0,0 @@ -<?php - -require_once "utils/autoloader.php"; -include "Controller/login/login_post.php"; - -$router = new Lollipop\Router(); -//login -$router->addRoute(["GET"], "/", "Controller/login/login_get.php"); -$router->addRoute(["POST"], "/login", function($vars){ - login_handler(); -}); - -//user -//add -$router->addRoute(["GET"], "/user/add", "Controller/user/add_get.php"); -$router->addRoute(["POST"], "/user/add", "Controller/user/add_post.php"); -$router->route(); - -/* -$router->addRoute(["GET", "POST"], "/user/:email/update", "views/alter_user.php"); -$router->addRoute(["GET", "POST"], "/user/:email/crud", "views/crud_user.php"); -$router->addRoute(["GET", "POST"], "/user/search", "views/search_user.php"); -$router->addRoute(["GET", "POST"], "/dashboard", "views/dashboard.php"); -$router->addRoute(["GET", "POST"], "/", "views/login.php"); -$router->addRoute(["GET", "POST"], "/logout", "logic/logout.php"); -$router->addRoute(["GET", "POST"], "/course/search", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:enroll/enroll", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:unsubscribe/unsubscribe", "views/search_course.php"); -$router->addRoute(["GET"], "/test/template/:hello", function($vars) { - $t = new Lollipop\Template(); - echo $t->template("template_test.html", $vars); -}); -$router->addRoute(["GET"], "/user/add", function($vars) { - include "logic/user/add_get.php"; - $vars = database_permissions(); - $t = new Lollipop\Template(); - echo $t->template("views/add_user.html", $vars); -}); -$router->addRoute(["POST"], "/user/add", "logic/add_user_post.php"); -*/ -\ No newline at end of file diff --git a/index_REMOTE_17395.php b/index_REMOTE_17395.php @@ -1,40 +0,0 @@ -<?php - -require_once "utils/autoloader.php"; -include "Controller/login/login_post.php"; - -$router = new Lollipop\Router(); -//login -$router->addRoute(["GET"], "/", "Controller/login/login_get.php"); -$router->addRoute(["POST"], "/login", function($vars){ - login_handler(); -}); - -//user -//add -$router->addRoute(["GET"], "/user/add", "Controller/user/add_get.php"); -$router->addRoute(["POST"], "/user/add", "Controller/user/add_post.php"); -$router->route(); - -/* -$router->addRoute(["GET", "POST"], "/user/:email/update", "views/alter_user.php"); -$router->addRoute(["GET", "POST"], "/user/:email/crud", "views/crud_user.php"); -$router->addRoute(["GET", "POST"], "/user/search", "views/search_user.php"); -$router->addRoute(["GET", "POST"], "/dashboard", "views/dashboard.php"); -$router->addRoute(["GET", "POST"], "/", "views/login.php"); -$router->addRoute(["GET", "POST"], "/logout", "logic/logout.php"); -$router->addRoute(["GET", "POST"], "/course/search", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:enroll/enroll", "views/search_course.php"); -$router->addRoute(["GET", "POST"], "/course/:unsubscribe/unsubscribe", "views/search_course.php"); -$router->addRoute(["GET"], "/test/template/:hello", function($vars) { - $t = new Lollipop\Template(); - echo $t->template("template_test.html", $vars); -}); -$router->addRoute(["GET"], "/user/add", function($vars) { - include "logic/user/add_get.php"; - $vars = database_permissions(); - $t = new Lollipop\Template(); - echo $t->template("views/add_user.html", $vars); -}); -$router->addRoute(["POST"], "/user/add", "logic/add_user_post.php"); -*/ -\ No newline at end of file diff --git a/views/add_user.html b/views/add_user.html @@ -12,24 +12,24 @@ <form action="/user/add" method="post"> <div class="mb-3"> - <label for="first_name" class="form-label"><b>Voornaam:</b></label> - <input type="text" class="form-control" name="first_name" id="first_name" placeholder="{{first_name}}"> + <label for="fname" class="form-label"><b>Voornaam:</b></label> + <input type="text" class="form-control" name="fname" id="fname" placeholder="{{$fname_error "%%" "First name" !format_if }}" value="{{$fname "%%" "" !format_if }}"> </div> <div class="mb-3"> <label for="achternaam" class="form-label"><b>Achternaam:</b></label> - <input type="text" class="form-control" name="last_name" id="achternaam" placeholder="{{last_name}}"> + <input type="text" class="form-control" name="lname" id="lname" placeholder="{{$lname_error "%%" "Last name" !format_if}}" value="{{$lname "%%" "" !format_if }}"> </div> <div class="mb-3"> <label for="email" class="form-label"><b>Email:</b></label> - <input type="text" class="form-control" name="email" id="email" placeholder="{{email}}"> + <input type="text" class="form-control" name="email" id="email" placeholder="{{$email_error "%%" "Email" !format_if}}" value="{{$email "%%" "" !format_if}}"> </div> <div class="mb-3"> - <label for="password" class="form-label"><b>Wachtwoord:</b></label> - <input type="password" class="form-control" name="password" id="password" placeholder="{{password}}"> + <label for="pwd" class="form-label"><b>Wachtwoord:</b></label> + <input type="password" class="form-control" name="pwd" id="pwd" placeholder="{{$email_error "%%" "******" !format_if}}"> </div> <button type="submit" class="btn btn-primary" name="submit">Add user</button> </form> - {{msg}} + {{$msg}} </div> </body> </html> diff --git a/views/dashboard.html b/views/dashboard.html @@ -0,0 +1,11 @@ +<html> + <head> + + </head> + <body> + <form method="post" action="/logout"> + <button type="submit">Logout</button> + </form> + {{$email}} + </body> +</html> +\ No newline at end of file diff --git a/views/login.html b/views/login.html @@ -27,15 +27,15 @@ placeholder="Enter email"> </div> <div class="form-group"> - <label for="password">Password:</label> - <input type="password" class="form-control" id="password" name="password" - placeholder="Enter password"> + <label for="pwd">pwd:</label> + <input type="pwd" class="form-control" id="pwd" name="pwd" + placeholder="Enter pwd"> </div> <button type="submit" name='login_btn' class="btn btn-primary">Login</button> </form> </div> <div class="row justify-content-center"> - {{msg}} + {{$msg}} </div> </div> </div>