Completed
Push — master ( d8e2a0...679457 )
by Mahmoud
04:23
created

WebAuthenticationTask::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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