Completed
Push — master ( dbc3bd...6bde35 )
by Mahmoud
03:28
created

WebAuthenticationService::login()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
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)
37
    {
38
        $correct = $this->auth->attempt(['email' => $email, 'password' => $password]);
39
40
        if(!$correct){
41
            throw new AuthenticationFailedException();
42
        }
43
44
        return $this->auth->user();
45
    }
46
47
48
}
49