lollipop

A PHP-framework
Log | Files | Refs

commit b5d74cc8ab92f8cd023a0ec0136cb7ecaf45b939
parent 0cedbc177bce864d55723eec04cfb7b70b83154f
Author: Friedel Schon <[email protected]>
Date:   Wed, 12 Apr 2023 18:14:07 +0200

namespace 'Model' for DB-models

Diffstat:
AModel/Permission.php | 17+++++++++++++++++
AModel/User.php | 17+++++++++++++++++
Dclasses/Permission.php | 15---------------
Dclasses/User.php | 15---------------
Mlogin.php | 135+++++++++++++++++++++++++++++++++++++++++++------------------------------------
5 files changed, 107 insertions(+), 92 deletions(-)

diff --git a/Model/Permission.php b/Model/Permission.php @@ -0,0 +1,16 @@ +<?php + +namespace Model { + class Permission extends \Lollipop\DatabaseObject + { + static function get_table(): string + { + return "permission_user"; + } + + static function get_primary(): string + { + return "email"; + } + } +} +\ No newline at end of file diff --git a/Model/User.php b/Model/User.php @@ -0,0 +1,16 @@ +<?php + +namespace Model { + class User extends \Lollipop\DatabaseObject + { + static function get_table(): string + { + return "user"; + } + + static function get_primary(): string + { + return "email"; + } + } +} +\ No newline at end of file diff --git a/classes/Permission.php b/classes/Permission.php @@ -1,14 +0,0 @@ -<?php -class Permission extends Lollipop\DatabaseObject -{ - static function get_table(): string - { - return "permission_user"; - } - - static function get_primary(): string - { - return "email"; - } -} -?> -\ No newline at end of file diff --git a/classes/User.php b/classes/User.php @@ -1,14 +0,0 @@ -<?php -class User extends Lollipop\DatabaseObject -{ - static function get_table(): string - { - return "user"; - } - - static function get_primary(): string - { - return "email"; - } -} -?> -\ No newline at end of file diff --git a/login.php b/login.php @@ -1,76 +1,87 @@ <!DOCTYPE html> <html> + <head> - <title>Login Page</title> - <!-- Add the Bootstrap CSS stylesheet --> - <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> + <title>Login Page</title> + <!-- Add the Bootstrap CSS stylesheet --> + <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 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="login.php"> - <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" class="btn btn-primary">Login</button> - </form> - </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="login.php"> + <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" class="btn btn-primary">Login</button> + </form> + </div> </div> + </div> </div> - <!-- Add the Bootstrap JavaScript library (optional) --> - <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> - <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> - <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> - <?php - include "utils\autoloader.php"; - //make classes - $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "lollipop"); - $u = $db->loadtable(User::class); - $p = $db->loadtable(Permission::class); + </div> + <!-- Add the Bootstrap JavaScript library (optional) --> + <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" + integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" + crossorigin="anonymous"></script> + <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" + integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" + crossorigin="anonymous"></script> + <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" + integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" + crossorigin="anonymous"></script> + <?php + include "utils/autoloader.php"; + //make classes + $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "lollipop"); + $u = $db->loadtable(Model\User::class); + $p = $db->loadtable(Model\Permission::class); - // check if a post request was sent - if ($_SERVER["REQUEST_METHOD"] == "POST") { - // fetch data from the form - if(!isset($_POST['email']) or !isset($_POST['password'])){ - echo "One of the forms was empty"; - } else { - $email = $_POST['email']; - $pwd = $_POST['password']; + // check if a post request was sent + if ($_SERVER["REQUEST_METHOD"] == "POST") { + // fetch data from the form + if (!isset($_POST['email']) or !isset($_POST['password'])) { + echo "One of the forms was empty"; + } else { + $email = $_POST['email']; + $pwd = $_POST['password']; - //excute query - $u->where(array('email' => $email)); + //excute query + $u->where(array('email' => $email)); - //verify $pwd with $u->getData()['pwd'] - if($pwd == password_verify($pwd, $u->getData()['pwd'])){ - session_start(); - $_SESSION['email'] = $u->getData()['email']; - $_SESSION['first_name'] = $u->getData()['fname']; - $_SESSION['last_name'] = $u->getData()['lname']; - - $p->all_where(array('email' => $email)); - $permissions = []; - foreach($p->getData() as $permission){ - array_push($permissions, $permission['id']); - }; - $_SESSION['permissions'] = $permissions; - header('Location: dashboard.php'); + //verify $pwd with $u->getData()['pwd'] + if ($pwd == password_verify($pwd, $u->getData()['pwd'])) { + session_start(); + $_SESSION['email'] = $u->getData()['email']; + $_SESSION['first_name'] = $u->getData()['fname']; + $_SESSION['last_name'] = $u->getData()['lname']; + + $p->all_where(array('email' => $email)); + $permissions = []; + foreach ($p->getData() as $permission) { + array_push($permissions, $permission['id']); } + ; + $_SESSION['permissions'] = $permissions; + header('Location: dashboard.php'); } } - - - - ?> - </body> + } + + + + ?> +</body> + </html> \ No newline at end of file