UserUtils::logout()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Alvo\User;
4
5
/**
6
 *  Utils functions
7
 */
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()
15
    {
16 1
        return $this->di->get("session")->has('user');
0 ignored issues
show
Bug Best Practice introduced by
The property di does not exist on Alvo\User\UserUtils. Did you maybe forget to declare it?
Loading history...
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
0 ignored issues
show
Bug Best Practice introduced by
The property db does not exist on Alvo\User\UserUtils. Did you maybe forget to declare it?
Loading history...
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);
0 ignored issues
show
Bug introduced by
The function password_verify was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        $passCheck = /** @scrutinizer ignore-call */ password_verify($pass, $user->password);
Loading history...
48
49 1
        if ($passCheck) {
50 1
            $this->di->get("session")->set("user", $user->email);
0 ignored issues
show
Bug Best Practice introduced by
The property di does not exist on Alvo\User\UserUtils. Did you maybe forget to declare it?
Loading history...
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()
66
    {
67
        $this->di->get("session")->destroy();
0 ignored issues
show
Bug Best Practice introduced by
The property di does not exist on Alvo\User\UserUtils. Did you maybe forget to declare it?
Loading history...
68
    }
69
}
70