commit 54c5b2d8a6cb7d66e8454569b9f8ce8c0117f1a7
parent 0edaa79867ca2b22036ade83c0ba1fc7764e2713
Author: Friedel Schön <[email protected]>
Date: Wed, 28 Jun 2023 20:05:43 +0200
naming convension
Diffstat:
4 files changed, 17 insertions(+), 59 deletions(-)
diff --git a/Model/Login_handler.php b/Model/Login_handler.php
@@ -1,42 +0,0 @@
-<?php
-
-class Login_handler
-{
- public function login(string $email, string $pwd): 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", "panda");
- //create a Database object class, with the table User
- $u = $db->get(Model\User::class);
-
- //check if the email exists in db
- if(!$u->where('email', $email)) {
- //email does not exist
- return false;
- } else {
- if(password_verify($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();
- $_SESSION['email'] = $u->email;
- $_SESSION['first_name'] = $u->fname;
- $_SESSION['last_name'] = $u->lname;
-
-
- $_SESSION['user_permissions'] = "iets";
- }
-}
diff --git a/Model/PermissionUser.php b/Model/PermissionUser.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Model {
+ class PermissionUser extends \Lollipop\DatabaseObject
+ {
+ public static function get_table(): string
+ {
+ return "permission_user";
+ }
+
+ public static function get_primary(): string
+ {
+ return 'email';
+ }
+ }
+}
diff --git a/Model/Permission_User.php b/Model/Permission_User.php
@@ -1,16 +0,0 @@
-<?php
-
-namespace Model {
- class Permission_User extends \Lollipop\DatabaseObject
- {
- public static function get_table(): string
- {
- return "permission_user";
- }
-
- public static function get_primary(): string
- {
- return 'email';
- }
- }
-}
diff --git a/routing/login.php b/routing/login.php
@@ -34,7 +34,7 @@ $login = function (&$vars) {
}
}
//get permissions form db and set sessions_permissions
- $p = $db->all_where(Model\Permission_user::class, [login => $u->{login}]);
+ $p = $db->all_where(Model\PermissionUser::class, [login => $u->{login}]);
$user_permissions = [];
foreach($p as $permission) {
$user_permissions[] = $permission->id_permission;