lollipop

A PHP-framework
Log | Files | Refs

commit 68d09d6b020154eec6c06b06f87f729bb55efd22
parent 8c4fc7abb809e282def7b039e1d4586ea77395a2
Author: MoiBaguette <[email protected]>
Date:   Wed, 21 Jun 2023 15:28:01 +0200

login, logout and add user

Diffstat:
DController/login/login_get.php | 4----
DController/login/login_post.php | 74--------------------------------------------------------------------------
DController/logout/logout.php | 12------------
DController/user/add_get.php | 5-----
DController/user/add_post.php | 37-------------------------------------
ALollipop/Utils.php | 38++++++++++++++++++++++++++++++++++++++
MModel/User.php | 105++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
DModel/Utils.php | 36------------------------------------
Mindex.php | 112++++++++++++++++++++++++++++++++-----------------------------------------------
Dlogic/dashboard.php | 16----------------
Dlogic/login.php | 19-------------------
Dlogic/logout.php | 9---------
Dlogic/navbar.php | 43-------------------------------------------
Dlogic/user/add_get.php | 18------------------
Dlogic/user/add_post.php | 87-------------------------------------------------------------------------------
Mviews/add_user.html | 55++++++++++++++++++++++++-------------------------------
Aviews/css/add_user.css | 47+++++++++++++++++++++++++++++++++++++++++++++++
Mviews/dashboard.html | 6+++---
Dviews/dashboard.php | 9---------
Mviews/login.html | 10++++------
Dviews/login.php | 57---------------------------------------------------------
Dviews/navbar.php | 37-------------------------------------
22 files changed, 265 insertions(+), 571 deletions(-)

diff --git a/Controller/login/login_get.php b/Controller/login/login_get.php @@ -1,3 +0,0 @@ -<?php - $templater = new Lollipop\Template(); - echo $templater->template("views/login.html", ["msg" => ""]); -\ No newline at end of file diff --git a/Controller/login/login_post.php b/Controller/login/login_post.php @@ -1,73 +0,0 @@ -<?php -const login = "email"; -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){ - return ($this->authenticate($post_arr)); - }else{ - return false; - } - - } - function authenticate(array $post) : bool - //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", "lollipop"); - //create a Database object class, with the table User - $u = $db->get(Model\User::class); - - //check if the email exists in db - if(!$u->load($post[login])){ - //email does not exist - return false; - }else{ - if(password_verify($post[pwd], $u->{pwd})){ - //authenticated -> set $_SESSION variables - $this->set_globals($u, $db); - return true; - } else { - //password did not match - return false; - } - } - } - - private function set_globals(Lollipop\DatabaseObject $u, Lollipop\SQLDatabase $db) - //this function sets Session variables which incluse - //email, first_name, last_name and array user_permissions - { - //start session and set - session_start(); - $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(Model\Permission_user::class, [login, $u->{login}]); - foreach($p as $permission){ - $user_permissions[] = $permission->id; - } - $_SESSION['user_permissions'] = $user_permissions; - } -} -function login_handler(){ - $templater = new Lollipop\Template(); - $login = new Login_handler(); - - if( $login->login()){ - header("Location: dashboard"); - exit(); - }else{ - echo $templater->template("views/login.html", ["msg" => "<p style=\"color:red;\">Incorrect username or password.</p>"]); - } -} -?> -\ No newline at end of file diff --git a/Controller/logout/logout.php b/Controller/logout/logout.php @@ -1,11 +0,0 @@ -<?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_get.php b/Controller/user/add_get.php @@ -1,4 +0,0 @@ - <?php - $templater = new Lollipop\Template(); - $template["msg"] = ""; - echo $templater->template("views/add_user.html", $template); -\ No newline at end of file diff --git a/Controller/user/add_post.php b/Controller/user/add_post.php @@ -1,37 +0,0 @@ -<?php -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(); - $missing_fields = Utils::missing_fields($post_arr , $u->not_nullable); - - 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[$pwd_key]){ - $post_arr[$pwd_key] = password_hash($post_arr[$pwd_key], PASSWORD_DEFAULT); - } - foreach($u->column_names as $col){ - if($post_arr[$col] != ""){ - $u->$col = $post_arr[$col]; - } - } - if($u->add()) - return ["msg" => "<p style=\"color:green;\">succes</p>"]; - else - return ["msg" => "<p style=\"color:red;\">could not add user to database</p>"]; - } -} - - - diff --git a/Lollipop/Utils.php b/Lollipop/Utils.php @@ -0,0 +1,37 @@ +<?php +namespace Lollipop{ + Class Utils{ + static function post_to_array():array{ + $arr = []; + foreach ($_POST as $key => $value) { + $arr[$key] = $value; + } + return $arr; + } + + static function missing_fields($post, $not_nullable){ + $missing = []; + foreach($not_nullable as $column){ + if($post[$column] == NULL || $post[$column] == ""){ + $missing[$column] = "This field cannot be empty!"; + } + } + return $missing; + } + + function create_permission_radials():string{ + $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 = ""; + foreach($all_p as $db_permission){ + $radials .= "<div class=\"mb-3 form-check\"> + <input type=\"checkbox\" class=\"form-check-input\" name=\"permissions[]\" value=" . $db_permission->id . "\"> + <input type='hidden' value='-1' name='{$db_permission->name}'> + <label class=\"form-check-label\" for=" . $db_permission->name . ">" . $db_permission->name . "</label> + </div> "; + } + return $radials; + } + } +} +\ No newline at end of file diff --git a/Model/User.php b/Model/User.php @@ -1,5 +1,4 @@ <?php - namespace Model { class User extends \Lollipop\DatabaseObject { @@ -12,5 +11,109 @@ namespace Model { { return "email"; } + + static function get_password_field(): string{ + return "Password"; + } + function login_fields(): string{ + $html = ""; + $html .= '<input type="text" name="' . $this->get_primary(). '" placeholder="' . $this->get_primary() . '">'; + $html .= '<input type="password" name="' . $this->get_password_field() . '" placeholder="password">'; + return $html; + } + + function all_fields(): string{ + $html = ""; + foreach($this->column_names as $field){ + if($field == $this->get_password_field()){ + $html .= '<input type="password" name="' . $field . '" placeholder="' . $field . '">'; + $html .= '<div class="form-response"><p style="color:red;">{{$error-'. $field .'}}</p></div>'; + }else{ + $html .= '<input type="text" name="' . $field . '" placeholder="' . $field . '">'; + $html .= '<div class="form-response"><p style="color:red;">{{$error-'. $field .'}}</p></div>'; + } + } + return $html; + } + + function login():array{ + $post_arr = \Lollipop\Utils::post_to_array(); + $missing_fields = \Lollipop\Utils::missing_fields($post_arr , [$this->get_primary(), $this->get_password_field()]); + + if(sizeof($missing_fields) == 0){ + return $this->authenticate($post_arr); + }else{ + return $missing_fields; + } + } + function authenticate(array $post) : array + //this function return true when user is autheticated uses set_globals to set $_SESSION variables + { + //check if the email exists in db + if(!$this->load($post[$this->get_primary()])){ + //email does not exist + return ["response" => "{$this->get_primary()}: {$post[$this->get_primary()]} does not exists in db"]; + }else{ + if(password_verify($post[$this->get_password_field()], $this->{$this->get_password_field()})){ + //authenticated -> set $_SESSION variables + $this->set_globals(); + return []; + } else { + //password did not match + return ["response" => "incorrect password"]; + } + } + } + + private function set_globals() + //this function sets Session variables + { + session_start(); + $user_permissions = []; + //foreach field in database which is not password add to session + foreach($this->getData() as $key => $data){ + if($key != $this->get_password_field()){ + $_SESSION[$key] = $data; + } + } + //get permissions form db and set sessions_permissions + $p = $this->db->all_where(Permission_user::class, [$this->get_primary(), $this->{$this->get_primary()}]); + foreach($p as $permission){ + $user_permissions[] = $permission->id; + } + $_SESSION['user_permissions'] = $user_permissions; + + session_abort(); + } + + function add_user():array{ + $post_arr = \Lollipop\Utils::post_to_array(); + $missing_fields = \Lollipop\Utils::missing_fields($post_arr , $this->not_nullable); + + if(sizeof($missing_fields) == 0){ + return $this->add_data_db($post_arr); + }else{ + return $missing_fields; + } + } + + private function add_data_db(array $post_arr): array{ + if($this->load($post_arr[$this->get_primary()])){ + return ["msg" => "<p style=\"color:red;\">this email address is already taken: {$post_arr[$this->get_primary()]} </p>"]; + }else{ + if($post_arr[$this->get_password_field()]){ + $post_arr[$this->get_password_field()] = password_hash($post_arr[$this->get_password_field()], PASSWORD_DEFAULT); + } + foreach($this->column_names as $col){ + if($post_arr[$col] != ""){ + $this->$col = $post_arr[$col]; + } + } + if($this->add()) + return ["msg" => "<p style=\"color:green;\">succes</p>"]; + else + return ["msg" => "<p style=\"color:red;\">could not add user to database</p>"]; + } + } } } \ No newline at end of file diff --git a/Model/Utils.php b/Model/Utils.php @@ -1,35 +0,0 @@ -<?php -Class Utils{ - static function post_to_array():array{ - $arr = []; - foreach ($_POST as $key => $value) { - $arr[$key] = $value; - } - return $arr; - } - - static function missing_fields($post, $not_nullable){ - $missing = []; - foreach($not_nullable as $column){ - if($post[$column] == NULL || $post[$column] == ""){ - $missing[$column] = "This field cannot be empty!"; - } - } - return $missing; - } - - function create_permission_radials():string{ - $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 = ""; - foreach($all_p as $db_permission){ - $radials .= "<div class=\"mb-3 form-check\"> - <input type=\"checkbox\" class=\"form-check-input\" name=\"permissions[]\" value=" . $db_permission->id . "\"> - <input type='hidden' value='-1' name='{$db_permission->name}'> - <label class=\"form-check-label\" for=" . $db_permission->name . ">" . $db_permission->name . "</label> - </div> "; - } - return $radials; - } -} -\ No newline at end of file diff --git a/index.php b/index.php @@ -1,88 +1,66 @@ <?php -use Lollipop\Template; +use Lollipop\Utils; require_once "utils/autoloader.php"; -include "Controller/login/login_post.php"; - -$templater = new Template(); +$templater = new Lollipop\Template(); $router = new Lollipop\Router($templater); -//login -$router->addRoute(["GET"], "/", "views/login.html"); -$router->addRoute(["POST"], "/login", function($vars){ - login_handler(); -}); +$db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "lollipop"); -//logout -$router->addRoute(["POST"], "/logout", function($vars){ - include "Controller/logout/logout.php"; - logout(); +$router->addRoute(["GET"], "/", function(&$vars){ + global $db; + $vars["login-fields"] = $db->get(Model\User::class)->login_fields(); return "views/login.html"; }); -//user -//add -$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"; +$router->addRoute(["POST"], "/", function(&$vars){ + global $db; + $vars["login-fields"] = $db->get(Model\User::class)->login_fields(); + $vars["response"] = $db->get(Model\User::class)->login(); + if($vars["response"] == []){ + header("Location: dashboard"); + exit(); + }else{ + return "views/login.html"; + } }); -//dashboard -$router->addRoute(["GET"], "/dashboard", function(&$vars){ - session_start(); - foreach($_SESSION as $key => $data){ - $vars[$key] = $data; +session_start(); + +if(isset($_SESSION['user_permissions']) && in_array(1, $_SESSION['user_permissions'])){ + echo "permission dingen"; + foreach($_SESSION as $tmp){ + echo $tmp; } +} +$router->addRoute(["GET"], "/dashboard", function(&$vars){ + $vars += $_SESSION; return "views/dashboard.html"; }); -$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"], "/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){ + global $db; + $vars["all-fields"] = $db->get(Model\User::class)->all_fields(); + return "views/add_user.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", function(&$vars){ + global $db; + $vars["all-fields"] = $db->get(Model\User::class)->all_fields(); + foreach($db->get(Model\User::class)->add_user() as $err_key => $err){ + $vars[$err_key] = $err; + echo $err_key . $err . '<br>'; + } + foreach(Utils::post_to_array() as $key => $data){ + echo $key . $data . '<br>'; + } + return "views/add_user.html"; }); -$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"], "/logout", function(&$vars){ + session_unset(); + session_destroy(); + header("Location: /"); }); -$router->addRoute(["POST"], "/contol/login", login_post); -*/ +$router->route(); diff --git a/logic/dashboard.php b/logic/dashboard.php @@ -1,15 +0,0 @@ -<?php - //echo file_get_contents('http://127.0.0.1/server-status'); - session_start(); - echo "voornaam = "; - echo $_SESSION['first_name']; - echo "<br>"; - echo "achternaam = "; - echo $_SESSION['last_name']; - echo "<br>"; - echo "email = "; - echo $_SESSION['email']; - echo "<br>"; - echo "perm = "; - var_dump($_SESSION['user_permissions']); -?> -\ No newline at end of file diff --git a/logic/login.php b/logic/login.php @@ -1,18 +0,0 @@ -<?php -include "utils\autoloader.php"; - -//create login class -$login_handler = new Login_handler; -$msg = ""; -if ($_SERVER["REQUEST_METHOD"] == "POST") { - if(isset($_POST['email']) || !isset($_POST['password'])){ - // fetch data from the form pass to login_handler function - if(($login_handler->login($_POST['email'], $_POST['password']))){ - //authenticated - header('Location: /dashboard'); - }else{ - $msg = "<p style=\"color:red\">Incorrect username of password.</p>"; - } - } -} -?> -\ No newline at end of file diff --git a/logic/logout.php b/logic/logout.php @@ -1,8 +0,0 @@ -<?php -session_start(); -session_unset(); -session_destroy(); -session_abort(); -header('Location: /'); -exit; -?> -\ No newline at end of file diff --git a/logic/navbar.php b/logic/navbar.php @@ -1,42 +0,0 @@ -<?php -session_start(); -if (!isset($_SESSION['email'])) { - header('Location: /'); - exit; -} -// Get the permission level of the user - -$permission_levels = $_SESSION['user_permissions']; - -// Assume $permission_levels is an array containing the user's permission levels - -$links = array(); - -// Define the links for each type of employee -if (in_array(0, $permission_levels)) { - // Admin links - $admin_links = array( - array('url' => '/user/add', 'title' => 'Add User'), - array('url' => '/user/search', 'title' => 'Search for user'), - ); - $links[] = array('name' => 'Admin', 'links' => $admin_links); -} - -if (in_array(1, $permission_levels)) { - // Lecturer links - $lecturer_links = array( - array('url' => 'lecturer_page_1.php', 'title' => 'Lecturer Page 1'), - array('url' => 'lecturer_page_2.php', 'title' => 'Lecturer Page 2'), - array('url' => 'lecturer_page_3.php', 'title' => 'Lecturer Page 3') - ); - $links[] = array('name' => 'Lecturer', 'links' => $lecturer_links); -} - -if (in_array(2, $permission_levels)) { - // Student links - $student_links = array( - array('url' => '/course/search', 'title' => 'Courses'), - ); - $links[] = array('name' => 'Student', 'links' => $student_links); -} -?> -\ No newline at end of file diff --git a/logic/user/add_get.php b/logic/user/add_get.php @@ -1,17 +0,0 @@ -<?php -include "utils/autoloader.php"; -//select the available permissions from the database -function database_permissions():array{ - $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "lollipop"); - $all_p = $db->all(Model\Permission::class); - $html = ""; - foreach ($all_p as $db_permission) { - $html .= "<div class=\"mb-3 form-check\"> - <input type=\"checkbox\" class=\"form-check-input\" name=\"permissions[]\" value=" . $db_permission->id . "\"> - <label class=\"form-check-label\" for=" . $db_permission->name . ">" . $db_permission->name . "</label> - </div>"; - } - return ["permission_radials" => $html]; -} -?> - -\ No newline at end of file diff --git a/logic/user/add_post.php b/logic/user/add_post.php @@ -1,86 +0,0 @@ -<?php - if ($_SERVER["REQUEST_METHOD"] == "POST") { - $errors = array(); // initialize an empty array to store errors - - // Check if voornaam is set and not empty - if (isset($_POST['voornaam']) && !empty($_POST['voornaam'])) { - $fname = $_POST['voornaam']; - } else { - $errors[] = "Voornaam is required"; - } - - // Check if achternaam is set and not empty - if (isset($_POST['achternaam']) && !empty($_POST['achternaam'])) { - $lname = $_POST['achternaam']; - } else { - $errors[] = "Achternaam is required"; - } - - // Check if email is set and not empty - if (isset($_POST['email']) && !empty($_POST['email'])) { - $email = $_POST['email']; - } else { - $errors[] = "E-mail is required"; - } - - // Check if password is set and not empty - if (isset($_POST['password']) && !empty($_POST['password'])) { - $password = $_POST['password']; - } else { - $errors[] = "Wachtwoord is required"; - } - - // Check if permissions is set - if (isset($_POST['permissions'])) { - $permissions = $_POST['permissions']; - } else { - $errors[] = "Permissies zijn vereist"; - } - - // Check if there are any errors - if (count($errors) > 0) { - // Print out the errors - foreach ($errors as $error) { - echo $error . "<br>"; - } - } else { - // Pass the password through a hashing function - $hashed_pwd = password_hash($password, PASSWORD_DEFAULT); - - //create a database object with table user - $u = $db->get(Model\User::class); - - //check if email already exists - if ($u->load($email)) { - echo "this email address is taken: " . $email; - } else { - $succes = false; - //set new user data - $u->email = $email; - $u->fname = $fname; - $u->lname = $lname; - $u->pwd = $hashed_pwd; - - //add user with the add function - if ($u->insert()) { - $succes = true; - } - - - //create a database object with table permission for each permission - //set the data and execute the add function - foreach ($permissions as $permission) { - $p = $db->get(Model\PermissionUser::class); - $p->email = $email; - $p->id = (int) $permission; - if ($p->insert()) { - $succes = true; - } - } - if ($succes) { - echo "succes!"; - } - } - } - } - ?> -\ No newline at end of file diff --git a/views/add_user.html b/views/add_user.html @@ -1,35 +1,27 @@ <!DOCTYPE html> <html lang="eng"> - <head> - <title>Add user</title> - <!-- Bootstrap CSS --> - <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> - <link rel="stylesheet" type="text/css" href="/css/homepage.css"> - </head> - <body> - <div class="container"> - <h1>Add user</h1> + <title>Add User</title> + <link rel="stylesheet" href="/views/css/add_user.css"> + <link rel="stylesheet" href="/views/css/input.css"> + <meta name="viewport" content="width=device-width, initial-scale=1" /> +</head> +<body> + <div class="header"> + <h1>Lollipop</h1> + </div> + <div class="flex-row"> + <div class="flex-side"></div> - <form action="/user/add" method="post"> - <div class="mb-3"> - <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="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_error "%%" "Email" !format_if}}" value="{{$email "%%" "" !format_if}}"> - </div> - <div class="mb-3"> - <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}} + <div class="flex-middle"> + <div class="form-title"><h2>Enter credentials:</h1></div> + <form method="POST" action="/user/add"> + {{$all-fields}} + + <input type="submit" value="Submit"> + </form> </div> - </body> -</html> + + <div class="flex-side"></div> + </div> +</body> +</html> +\ No newline at end of file diff --git a/views/css/add_user.css b/views/css/add_user.css @@ -0,0 +1,46 @@ +* { + box-sizing: border-box; + font-family: Verdana,sans-serif; + font-size: 15px; + line-height: 1.5; + + } + + body{ + padding: 0; + margin: 0; + background: #1abc9c; + } + + .header{ + padding: 40px; + background: #1abc9c; + text-align: center; + } + + h1{ + color: white; + font-size: 50px; + } + .flex-row{ + display: flex; + align-items: stretch; + } + + .flex-middle{ + margin:1em; + padding: 25px; + flex-grow: 8; + max-width:350px; + background-color: #f1f1f1; + border-radius: 35px; + } + + .flex-side{ + flex-grow: 1; + } + + .form-label{ + position: center; + } + +\ No newline at end of file diff --git a/views/dashboard.html b/views/dashboard.html @@ -1,11 +1,11 @@ <html> <head> - + <link rel="stylesheet" href="views/css/input.css"> </head> <body> <form method="post" action="/logout"> - <button type="submit">Logout</button> - </form> + <input type="submit" value="Logout"> + </form> {{$email}} </body> </html> \ No newline at end of file diff --git a/views/dashboard.php b/views/dashboard.php @@ -1,8 +0,0 @@ -<html> - <head> - <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"> - </head> - <body> - {{email}} - </body> -</html> -\ No newline at end of file diff --git a/views/login.html b/views/login.html @@ -2,8 +2,8 @@ <html> <head> <title>Login Page</title> - <link rel="stylesheet" href="css/login.css"> - <link rel="stylesheet" href="css/input.css"> + <link rel="stylesheet" href="views/css/login.css"> + <link rel="stylesheet" href="views/css/input.css"> <meta name="viewport" content="width=device-width, initial-scale=1" /> </head> <body> @@ -15,10 +15,8 @@ <div class="flex-middle"> <div class="form-title"><h2>Enter credentials:</h1></div> - <form method="POST" action="/login"> - <input type="text" name="credentials" placeholder="{{$credential_type}}"> - - <input type="password" name="password" placeholder="Password"> + <form method="POST" action="/"> + {{$login-fields}} <div class="form-response"><p style="color:red;">{{$response}}</p></div> diff --git a/views/login.php b/views/login.php @@ -1,56 +0,0 @@ -<!DOCTYPE html> -<?php - session_start(); - if (isset($_SESSION['email'])) { - header('Location: /dashboard'); - } - include "logic/login.php"; -?> -<html> -<head> - <title>Login Page</title> - <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" - integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> -</head> -<body> - <div class="container mx-auto text-center"> - <div class="row"> - <div class="col-md-12 title"> - <h1>Welcome to Lollipop</h1> - <h4>Please log in</h4> - </div> - </div> - </div> - <div class="container mt-5"> - <div class="row justify-content-center"> - <div class="col-md-6"> - <div class="card"> - <div class="card-header">Login</div> - <div class="card-body"> - <form method="POST" action="/"> - <div class="form-group"> - <label for="email">Email:</label> - <input type="email" class="form-control" id="email" name="email" - 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"> - </div> - <button type="submit" name='login_btn' class="btn btn-primary">Login</button> - </form> - </div> - <div class="row justify-content-center"> - <?php - //display login $msg - echo $msg; - ?> - </div> - </div> - </div> - </div> - </div> -</body> - -</html> -\ No newline at end of file diff --git a/views/navbar.php b/views/navbar.php @@ -1,36 +0,0 @@ -<?php -include "logic/navbar.php"; -?> -<nav class="navbar navbar-expand-lg navbar-light bg-light"> - <a class="navbar-brand" href="/dashboard">Dashboard</a> - <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" - aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation"> - <span class="navbar-toggler-icon"></span> - </button> - <div class="collapse navbar-collapse" id="navbarNavDropdown"> - <ul class="navbar-nav"> - <?php foreach ($links as $employee_links) { ?> - <li class="nav-item dropdown"> - <a class="nav-link dropdown-toggle" href="#" - id="navbarDropdownMenuLink<?php echo $employee_links['name']; ?>" role="button" - data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> - <?php echo $employee_links['name']; ?> - </a> - <ul class="dropdown-menu" - aria-labelledby="navbarDropdownMenuLink<?php echo $employee_links['name']; ?>"> - <?php foreach ($employee_links['links'] as $link) { ?> - <li><a class="dropdown-item" href="<?php echo $link['url']; ?>"><?php echo $link['title']; ?></a> - </li> - <?php } ?> - </ul> - </li> - <?php } ?> - </ul> - <form method="post" action="/logout"> - <button type="submit" name='logout' class="btn btn-primary">log out</button> - </form> - </div> -</nav> -<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> -<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script> -<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script> -\ No newline at end of file