commit 795cc725ba814a5ce99861293062fea7eca23e6c
parent 63ed78577b100fd58e3636f63d1c29a122700a29
Author: MoiBaguette <[email protected]>
Date: Sun, 25 Jun 2023 21:31:22 +0200
user info grades
Diffstat:
2 files changed, 8 insertions(+), 65 deletions(-)
diff --git a/Model/Login_handler.php b/Model/Login_handler.php
@@ -1,63 +0,0 @@
-<?php
-const login = "email";
-const pwd = "password";
-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", "panda");
- //create a Database object class, with the table User
- $u = $db->get(User::class);
-
- //check if the email exists in db
- if(!$u->where($post[login])){
- //email does not exist
- return false;
- }else{
- if(password_verify($post[pwd], $u->password)){
- //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->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));
- foreach($p as $permission){
- $user_permissions[] = $permission->id;
- }
- $_SESSION['user_permissions'] = $user_permissions;
- }
-}
-?>
-\ No newline at end of file
diff --git a/routing/user.php b/routing/user.php
@@ -90,16 +90,23 @@ $user_delete = function(&$vars){
$user_page = function(&$vars){
global $db;
$user = $db->get(Model\User::class);
+ $exam = $db->get(Model\Exam::class);
$user->load($vars['primary_key']);
$data = $user->getData();
if(in_array(3, $_SESSION['user_permissions'])){
foreach($data as $key => $d){
$vars['user_data'] .= "<p>your $key = $d<p><br>";
}
- }elseif($vars['primary'] == $_SESSION['email']){
+ }elseif($vars['primary_key'] == $_SESSION['email']){
foreach($data as $key => $d){
$vars['user_data'] .= "<p>your $key = $d<p><br>";
}
+ $vars['user_data'] .= "<h1>your grades</h1><br>";
+ foreach($db->all_where(Model\Grade::class, ['email' => $vars['primary_key']]) as $grade){
+ $exam->load($grade->exam);
+ $exam_name =$exam->name;
+ $vars['user_data'] .= "<p>your grade for $exam_name = $grade->grade </p><br>";
+ }
}
return "views/user_page.html";
};
\ No newline at end of file