Login_handler.php (1368B) download
1<?php
2class Login_handler
3{
4 function login(string $email, string $pwd) : bool
5 //this function return true when user is autheticated uses set_globals to set $_SESSION variables
6 {
7 //create a SQLDatabase class
8 $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "panda");
9 //create a Database object class, with the table User
10 $u = $db->get(Model\User::class);
11
12 //check if the email exists in db
13 if(!$u->where('email', $email)){
14 //email does not exist
15 return false;
16 }else{
17 if(password_verify($pwd, $u->pwd)){
18 //authenticated -> set $_SESSION variables
19 $this->set_globals($u, $db);
20 return true;
21 } else {
22 //password did not match
23 return false;
24 }
25 }
26 }
27
28 private function set_globals(Lollipop\DatabaseObject $u, Lollipop\SQLDatabase $db)
29 //this function sets Session variables which incluse
30 //email, first_name, last_name and array user_permissions
31 {
32 //start session and set
33 session_start();
34 $_SESSION['email'] = $u->email;
35 $_SESSION['first_name'] = $u->fname;
36 $_SESSION['last_name'] = $u->lname;
37
38
39 $_SESSION['user_permissions'] = "iets";
40 }
41}
42?>