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