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

AuthService   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A user() 0 3 2
A attempt() 0 12 3
A check() 0 3 1
A logout() 0 3 1
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
}