Completed
Push — master ( 7b6ec9...a9f129 )
by Mahmoud
04:35
created

WebAuthenticationService::login()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 14
rs 9.4285
cc 3
eloc 7
nc 4
nop 3
1
<?php
2
3
namespace App\Containers\WebAuthentication\Services;
4
5
use App\Containers\WebAuthentication\Exceptions\AuthenticationFailedException;
6
use Illuminate\Auth\AuthManager as Auth;
7
/**
8
 * Class WebAuthenticationService.
9
 *
10
 * @author Mahmoud Zalt <[email protected]>
11
 */
12
class WebAuthenticationService
13
{
14
15
    /**
16
     * @var  \Illuminate\Auth\AuthManager
17
     */
18
    private $auth;
19
20
    /**
21
     * WebAuthenticationService 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
            throw new AuthenticationFailedException();
46
        }
47
48
        return $this->auth->user();
49
    }
50
51
    /**
52
     * @return  bool
53
     */
54
    public function logout()
55
    {
56
        $this->auth->logout();
57
58
        return true;
59
    }
60
61
62
}
63