Total Complexity | 6 |
Total Lines | 60 |
Duplicated Lines | 0 % |
Coverage | 77.27% |
Changes | 0 |
1 | <?php |
||
8 | trait UserUtils |
||
9 | { |
||
10 | /** |
||
11 | * Checks if user is logged in |
||
12 | * @return boolean false if not logged in |
||
13 | */ |
||
14 | 1 | public function isLoggedIn() |
|
17 | } |
||
18 | |||
19 | |||
20 | |||
21 | /** |
||
22 | * Login |
||
23 | * |
||
24 | * @param string $email Email adress from form |
||
25 | * @param string $pass Unhashed string |
||
26 | * |
||
27 | * @return bool true if ok, else false |
||
28 | */ |
||
29 | 1 | public function login($email, $pass) |
|
30 | { |
||
31 | 1 | if ($this->isLoggedIn()) { |
|
32 | return; |
||
33 | } |
||
34 | |||
35 | 1 | $user = $this->db |
|
36 | 1 | ->connect() |
|
37 | 1 | ->select("email, id, password") |
|
38 | 1 | ->from("User") |
|
39 | 1 | ->where("email='$email'") |
|
40 | 1 | ->execute() |
|
41 | 1 | ->fetch(); |
|
42 | |||
43 | 1 | if (!$user) { |
|
44 | return false; |
||
45 | } |
||
46 | |||
47 | 1 | $passCheck = password_verify($pass, $user->password); |
|
48 | |||
49 | 1 | if ($passCheck) { |
|
50 | 1 | $this->di->get("session")->set("user", $user->email); |
|
51 | 1 | $this->di->get("session")->set("userId", $user->id); |
|
52 | 1 | return true; |
|
53 | } |
||
54 | |||
55 | // var_dump($this->di->get("session")->get("user")); |
||
56 | return false; |
||
57 | } |
||
58 | |||
59 | |||
60 | |||
61 | /** |
||
62 | * Destroys the session |
||
63 | * @return void |
||
64 | */ |
||
65 | public function logout() |
||
68 | } |
||
69 | } |
||
70 |