Completed
Push — master ( fcc0ff...8f456d )
by Mahmoud
03:36
created

WebAuthenticationTask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 52
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A login() 0 15 3
A logout() 0 6 1
1
<?php
2
3
namespace App\Containers\Authentication\Tasks;
4
5
use App\Containers\Authentication\Exceptions\AuthenticationFailedException;
6
use Illuminate\Auth\AuthManager as Auth;
7
8
/**
9
 * Class WebAuthenticationTask.
10
 *
11
 * @author Mahmoud Zalt <[email protected]>
12
 */
13
class WebAuthenticationTask
14
{
15
16
    /**
17
     * @var  \Illuminate\Auth\AuthManager
18
     */
19
    private $auth;
20
21
    /**
22
     * AuthenticationTask constructor.
23
     *
24
     * @param \Illuminate\Auth\AuthManager $auth
25
     */
26
    public function __construct(Auth $auth)
27
    {
28
        $this->auth = $auth;
29
    }
30
31
    /**
32
     * @param $email
33
     * @param $password
34
     *
35
     * @return mixed
36
     */
37
    public function login($email, $password, $remember = false)
38
    {
39
        if($remember){
40
            $remember = true;
41
        }
42
43
        $correct = $this->auth->attempt(['email' => $email, 'password' => $password], $remember);
44
45
        if(!$correct){
46
            // TODO: this has to be Web Exception
47
            throw new AuthenticationFailedException();
48
        }
49
50
        return $this->auth->user();
51
    }
52
53
    /**
54
     * @return  bool
55
     */
56
    public function logout()
57
    {
58
        $this->auth->logout();
59
60
        return true;
61
    }
62
63
64
}
65