Completed
Push — master ( 0288bf...f56298 )
by Arjay
13:59
created

AuthController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 114
rs 10
c 0
b 0
f 0
wmc 9
lcom 3
cbo 3

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A showLoginForm() 0 4 1
A authenticated() 0 16 4
A username() 0 4 1
A credentials() 0 6 1
A getGuard() 0 4 1
1
<?php
2
3
namespace Yajra\CMS\Http\Controllers;
4
5
use App\User;
6
use Illuminate\Foundation\Auth\AuthenticatesUsers;
7
use Illuminate\Http\Request;
8
9
class AuthController extends Controller
10
{
11
    use AuthenticatesUsers;
12
13
    /**
14
     * Where to redirect users after login / registration.
15
     *
16
     * @var string
17
     */
18
    protected $redirectPath = '/administrator';
19
20
    /**
21
     * Authentication guard.
22
     *
23
     * @var string
24
     */
25
    protected $guard = 'administrator';
26
27
    /**
28
     * Administrator login view.
29
     *
30
     * @var string
31
     */
32
    protected $loginView = 'admin::auth.login';
33
34
    /**
35
     * Where to redirect users after logout.
36
     *
37
     * @var string
38
     */
39
    protected $redirectAfterLogout = '/administrator';
40
41
    /**
42
     * Username to use for login.
43
     *
44
     * @var string
45
     */
46
    protected $username = 'username';
47
48
    /**
49
     * Create a new authentication controller instance.
50
     */
51
    public function __construct()
52
    {
53
        $this->middleware('guest', ['except' => 'logout']);
54
    }
55
56
    /**
57
     * Show the application's login form.
58
     *
59
     * @return \Illuminate\Http\Response
60
     */
61
    public function showLoginForm()
62
    {
63
        return view($this->loginView);
64
    }
65
66
    /**
67
     * Handle event when the user was authenticated.
68
     *
69
     * @param \Illuminate\Http\Request $request
70
     * @param \App\User $user
71
     * @return \Illuminate\Http\RedirectResponse
72
     */
73
    public function authenticated(Request $request, User $user)
74
    {
75
        if ($user->blocked || ! $user->confirmed) {
76
            $request->user($this->getGuard())->logout();
77
            if ($user->blocked) {
78
                $message = 'Your account is currently banned from accessing the site!';
79
            } else {
80
                $message = 'Your account is not yet activated!';
81
            }
82
            flash()->error($message);
83
84
            return redirect()->to('administrator/login');
85
        }
86
87
        return redirect()->intended($this->redirectPath);
88
    }
89
90
    /**
91
     * Get the login username to be used by the controller.
92
     *
93
     * @return string
94
     */
95
    public function username()
96
    {
97
        return $this->username;
98
    }
99
100
    /**
101
     * Get the needed authorization credentials from the request.
102
     *
103
     * @param  \Illuminate\Http\Request $request
104
     * @return array
105
     */
106
    protected function credentials(Request $request)
107
    {
108
        return array_merge($request->only($this->username(), 'password'), [
109
            'administrator' => true,
110
        ]);
111
    }
112
113
    /**
114
     * Get auth guard.
115
     *
116
     * @return string
117
     */
118
    protected function getGuard()
119
    {
120
        return $this->guard;
121
    }
122
}
123