Completed
Push — master ( 3e8868...550a3e )
by Afshin
02:14
created

AuthService::user()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: afshin
5
 * Date: 11/24/17
6
 * Time: 1:11 PM
7
 */
8
9
namespace Core\Services;
10
11
use App\DataAccess\User\UserDataAccess;
12
use Core\Interfaces\_Service;
13
14
class AuthService extends _Service
15
{
16
    public function user()
17
    {
18
        return UserDataAccess::getUserById(isset($_SESSION['userid']) ? $_SESSION['userid'] : 0);
19
20
    }
21
22
    public function check()
23
    {
24
        return isset($_SESSION['user']);
25
    }
26
27
    public function attempt(string $username,string $password)
28
    {
29
        $user = UserDataAccess::getUserLoginField($username)->first();
30
31
        if (!$user) {
32
            return false;
33
        }
34
        if (password_verify($password,$user->password)) {
0 ignored issues
show
Bug introduced by
The property password does not seem to exist on App\Model\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
35
            $_SESSION['user'] = $user->id;
36
            return true;
37
        }
38
        return false;
39
    }
40
41
    public function logout()
42
    {
43
        unset($_SESSION['user']);
44
    }
45
46
}