LoginController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 85
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A showLoginForm() 0 4 1
A __construct() 0 4 1
A username() 0 4 1
A attemptLogin() 0 10 3
A attempLoginUsingUsernameAsAnEmail() 0 7 1
1
<?php
2
3
namespace App\Http\Controllers\Auth;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Foundation\Auth\AuthenticatesUsers;
7
use Illuminate\Http\Request;
8
9
class LoginController extends Controller
10
{
11
    /*
12
    |--------------------------------------------------------------------------
13
    | Login Controller
14
    |--------------------------------------------------------------------------
15
    |
16
    | This controller handles authenticating users for the application and
17
    | redirecting them to your home screen. The controller uses a trait
18
    | to conveniently provide its functionality to your applications.
19
    |
20
    */
21
22
    use AuthenticatesUsers {
23
        attemptLogin as attemptLoginAtAuthenticatesUsers;
24
    }
25
26
    /**
27
     * Show the application's login form.
28
     *
29
     * @return \Illuminate\Http\Response
30
     */
31
    public function showLoginForm()
32
    {
33
        return view('adminlte::auth.login');
34
    }
35
36
    /**
37
     * Where to redirect users after login.
38
     *
39
     * @var string
40
     */
41
    protected $redirectTo = '/home';
42
43
    /**
44
     * Create a new controller instance.
45
     *
46
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by Sergi Tur Badenas
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
47
     */
48
    public function __construct()
49
    {
50
        $this->middleware('guest', ['except' => 'logout']);
51
    }
52
53
    /**
54
     * Returns field name to use at login.
55
     *
56
     * @return string
57
     */
58
    public function username()
59
    {
60
        return config('auth.providers.users.field', 'email');
61
    }
62
63
    /**
64
     * Attempt to log the user into the application.
65
     *
66
     * @param  \Illuminate\Http\Request  $request
67
     * @return bool
68
     */
69
    protected function attemptLogin(Request $request)
70
    {
71
        if ($this->username() === 'email') {
72
            return $this->attemptLoginAtAuthenticatesUsers($request);
73
        }
74
        if (! $this->attemptLoginAtAuthenticatesUsers($request)) {
75
            return $this->attempLoginUsingUsernameAsAnEmail($request);
76
        }
77
        return false;
78
    }
79
80
    /**
81
     * Attempt to log the user into application using username as an email.
82
     *
83
     * @param \Illuminate\Http\Request $request
84
     * @return bool
85
     */
86
    protected function attempLoginUsingUsernameAsAnEmail(Request $request)
87
    {
88
        return $this->guard()->attempt(
89
            ['email' => $request->input('username'), 'password' => $request->input('password')],
90
            $request->has('remember')
91
        );
92
    }
93
}
94