commit 786bf96946c4fd1c6f8174e9f8cb3449ca2b6ee2
parent 9ac3a7588d1e4046a19f6ba321ff95dd08183dee
Author: Gerco van Woudenbergh <[email protected]>
Date: Tue, 13 Jun 2023 14:21:38 +0200
sorta permissions
Diffstat:
6 files changed, 67 insertions(+), 43 deletions(-)
diff --git a/Controller/login/login_post.php b/Controller/login/login_post.php
@@ -52,9 +52,10 @@ class Login_handler
}
}
//get permissions form db and set sessions_permissions
- $p = $db->all_where(Model\Permission_user::class, [login, $u->{login}]);
+ $p = $db->all_where(Model\Permission_user::class, [login => $u->{login}]);
+ $user_permissions = [];
foreach($p as $permission){
- $user_permissions[] = $permission->id;
+ $user_permissions[] = $permission->id_permission;
}
$_SESSION['user_permissions'] = $user_permissions;
}
diff --git a/Model/Login_handler.php b/Model/Login_handler.php
@@ -35,12 +35,8 @@ class Login_handler
$_SESSION['first_name'] = $u->fname;
$_SESSION['last_name'] = $u->lname;
- //get permissions form db and set sessions_permissions
- $p = $db->all_where(Model\Permission_user::class, array('email' => $u->email));
- foreach($p as $permission){
- $user_permissions[] = $permission->id;
- }
- $_SESSION['user_permissions'] = $user_permissions;
+
+ $_SESSION['user_permissions'] = "iets";
}
}
?>
\ No newline at end of file
diff --git a/Model/Permission.php b/Model/Permission.php
@@ -0,0 +1,15 @@
+<?php
+namespace Model{
+ Class Permission extends \Lollipop\DatabaseObject
+ {
+ static function get_table(): string
+ {
+ return "permission";
+ }
+
+ static function get_primary(): string
+ {
+ return 'id';
+ }
+ }
+}
+\ No newline at end of file
diff --git a/index.php b/index.php
@@ -19,41 +19,41 @@ $router->addRoute(["POST", "GET"], "/logout", function($vars){
logout();
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("password");
-
- foreach($res as $key => $data){
- $vars[$key] = $data;
- }
-
- return "views/add_user.html";
-});
-
-//dashboard
-$router->addRoute(["GET"], "/dashboard", function(&$vars){
- session_start();
- $vars = ["key" => "poepie"];
- foreach($_SESSION as $key => $data){
+session_start();
+if(isset($_SESSION['user_permissions']) && in_array(1,$_SESSION['user_permissions'])){
+ //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("password");
+
+ foreach($res as $key => $data){
$vars[$key] = $data;
}
- return "views/dashboard.html";
-});
-
-$router->addRoute(["GET"], "/map", "views/map.html");
-$router->addRoute(["GET"], "/hdata", function(&$vars){
- include"Controller/hdata/hdata.php";
- $vars["table"] = make_table();
- return "views/hdata.html";
-});
-$router->addRoute(["GET"], "/api/:data", function($vars) {
- $key = new Key;
- $key->retrieveData($vars);
-});
-$router->addRoute(['GET'], '/css/dashboard.css', "css/dashboard.css");
+ 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->addRoute(["GET"], "/map", "views/map.html");
+ $router->addRoute(["GET"], "/hdata", function(&$vars){
+ include"Controller/hdata/hdata.php";
+ $vars["table"] = make_table();
+ return "views/hdata.html";
+ });
+ $router->addRoute(["GET"], "/api/:data", function($vars) {
+ $key = new Key;
+ $key->retrieveData($vars);
+ });
+ $router->addRoute(['GET'], '/css/dashboard.css', "css/dashboard.css");
+}
$router->route();
\ No newline at end of file
diff --git a/views/add_permissions.html b/views/add_permissions.html
@@ -0,0 +1,11 @@
+<html>
+ <head>
+
+ </head>
+ <body>
+ <form action="/user/add/permissions" method="POST">
+ {{$radials}}
+ <button type="submit" name="submit">Add permission</button>
+ </form>
+ </body>
+</html>
+\ No newline at end of file
diff --git a/views/dashboard.html b/views/dashboard.html
@@ -24,7 +24,6 @@
<!-- HEADER -->
<h1>Welcome {{ $first_name }}</h1>
-
<!-- DATA BLOCKS -->
<div class="block1">
<div class="content">