Completed
Push — master ( a19a47...15bbc5 )
by Arjay
15:59
created

AuthController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 7

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A showLoginForm() 0 4 1
A authenticated() 0 16 4
A credentials() 0 8 1
A logout() 0 10 1
A guard() 0 4 1
1
<?php
2
3
namespace Yajra\CMS\Http\Controllers;
4
5
use App\User;
6
use Auth;
7
use Illuminate\Foundation\Auth\AuthenticatesUsers;
8
use Illuminate\Http\Request;
9
10
class AuthController extends Controller
11
{
12
    use AuthenticatesUsers;
13
14
    /**
15
     * Where to redirect users after login / registration.
16
     *
17
     * @var string
18
     */
19
    protected $redirectPath = '/administrator';
20
21
    /**
22
     * Authentication guard.
23
     *
24
     * @var string
25
     */
26
    protected $guard = 'administrator';
27
28
    /**
29
     * Administrator login view.
30
     *
31
     * @var string
32
     */
33
    protected $loginView = 'admin::auth.login';
34
35
    /**
36
     * Where to redirect users after logout.
37
     *
38
     * @var string
39
     */
40
    protected $redirectAfterLogout = '/administrator';
41
42
    /**
43
     * Create a new authentication controller instance.
44
     */
45
    public function __construct()
46
    {
47
        $this->middleware('guest', ['except' => 'logout']);
48
    }
49
50
    /**
51
     * Show the application's login form.
52
     *
53
     * @return \Illuminate\Http\Response
54
     */
55
    public function showLoginForm()
56
    {
57
        return view($this->loginView);
58
    }
59
60
    /**
61
     * Handle event when the user was authenticated.
62
     *
63
     * @param \Illuminate\Http\Request $request
64
     * @param \App\User $user
65
     * @return \Illuminate\Http\RedirectResponse
66
     */
67
    public function authenticated(Request $request, User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
    {
69
        if ($user->blocked || ! $user->confirmed) {
70
            if ($user->blocked) {
71
                $message = 'Your account is currently banned from accessing the site!';
72
            } else {
73
                $message = 'Your account is not yet activated!';
74
            }
75
            auth($this->getGuard())->logout();
0 ignored issues
show
Documentation Bug introduced by
The method getGuard does not exist on object<Yajra\CMS\Http\Controllers\AuthController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
76
            flash()->error($message);
77
78
            return redirect()->route('administrator.login')->withErrors($message);
79
        }
80
81
        return redirect()->intended($this->redirectPath);
82
    }
83
84
    /**
85
     * Get the needed authorization credentials from the request.
86
     *
87
     * @param  \Illuminate\Http\Request $request
88
     * @return array
89
     */
90
    protected function credentials(Request $request)
91
    {
92
        $options = config('site.login.backend.options', [
93
            'administrator' => true,
94
        ]);
95
96
        return array_merge($request->only($this->username(), 'password'), $options);
97
    }
98
99
    /**
100
     * Log the user out of the application.
101
     *
102
     * @param  \Illuminate\Http\Request  $request
103
     * @return \Illuminate\Http\Response
104
     */
105
    public function logout(Request $request)
106
    {
107
        $this->guard()->logout();
108
109
        $request->session()->flush();
0 ignored issues
show
Bug introduced by
The method flush() does not seem to exist on object<Symfony\Component...ssion\SessionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
110
111
        $request->session()->regenerate();
0 ignored issues
show
Bug introduced by
The method regenerate() does not seem to exist on object<Symfony\Component...ssion\SessionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
112
113
        return redirect($this->redirectAfterLogout);
114
    }
115
116
    /**
117
     * Get the guard to be used during authentication.
118
     *
119
     * @return \Illuminate\Contracts\Auth\StatefulGuard
120
     */
121
    protected function guard()
122
    {
123
        return Auth::guard($this->guard);
124
    }
125
}
126