Issues (40)

Http/Controllers/Admin/Auth/LoginController.php (3 issues)

1
<?php
2
/**
3
 * Date: 2019/2/25 Time: 10:37
4
 *
5
 * @author  Eddy <[email protected]>
6
 * @version v1.0.0
7
 */
8
9
namespace App\Http\Controllers\Admin\Auth;
10
11
use App\Http\Controllers\Controller;
12
use App\Model\Admin\AdminUser;
13
use Illuminate\Foundation\Auth\AuthenticatesUsers;
14
use Auth;
15
use Illuminate\Http\Request;
16
use App\Http\Requests\Admin\AdminLoginRequest;
17
18
class LoginController extends Controller
19
{
20
    /*
21
    |--------------------------------------------------------------------------
22
    | Login Controller
23
    |--------------------------------------------------------------------------
24
    |
25
    | This controller handles authenticating users for the application and
26
    | redirecting them to your home screen. The controller uses a trait
27
    | to conveniently provide its functionality to your applications.
28
    |
29
    */
30
31
    use AuthenticatesUsers;
0 ignored issues
show
The trait Illuminate\Foundation\Auth\AuthenticatesUsers requires some properties which are not provided by App\Http\Controllers\Admin\Auth\LoginController: $redirectTo, $maxAttempts, $decayMinutes
Loading history...
32
33
    protected $guard = 'admin';
34
35
    /**
36
     * Create a new controller instance.
37
     *
38
     * @return void
39
     */
40
    public function __construct()
41
    {
42
        $this->middleware('guest:' . $this->guard)->except('logout');
43
    }
44
45
    /**
46
     * 基础功能-用户登录页面
47
     */
48
    public function showLogin()
49
    {
50
        return view('admin.auth.login');
51
    }
52
53
    /**
54
     * 基础功能-用户登录
55
     */
56
    public function login(AdminLoginRequest $request)
57
    {
58
        // If the class is using the ThrottlesLogins trait, we can automatically throttle
59
        // the login attempts for this application. We'll key this by the username and
60
        // the IP address of the client making these requests into this application.
61
        if ($this->hasTooManyLoginAttempts($request)) {
62
            $this->fireLockoutEvent($request);
63
64
            return $this->sendLockoutResponse($request);
65
        }
66
67
        // 检查用户是否已被禁用
68
        $user = $this->guard()->getProvider()->retrieveByCredentials($this->credentials($request));
69
        if ($user && $user->status == AdminUser::STATUS_DISABLE) {
70
            return [
71
                'code' => 1,
72
                'msg' => '用户被禁用'
73
            ];
74
        }
75
76
        if ($this->attemptLogin($request)) {
77
            return $this->sendLoginResponse($request);
78
        }
79
80
        // If the login attempt was unsuccessful we will increment the number of attempts
81
        // to login and redirect the user back to the login form. Of course, when this
82
        // user surpasses their maximum number of attempts they will get locked out.
83
        $this->incrementLoginAttempts($request);
84
85
        return $this->sendFailedLoginResponse($request);
86
    }
87
88
    /**
89
     * 基础功能-退出登录
90
     */
91
    public function logout(Request $request)
92
    {
93
        $this->guard()->logout();
94
95
        $request->session()->invalidate();
96
97
        return redirect(route('admin::login.show'));
98
    }
99
100
    public function guard()
101
    {
102
        return Auth::guard($this->guard);
103
    }
104
105
    public function username()
106
    {
107
        return 'name';
108
    }
109
110
    protected function authenticated(Request $request, $user)
0 ignored issues
show
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

110
    protected function authenticated(/** @scrutinizer ignore-unused */ Request $request, $user)

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

Loading history...
The parameter $user is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

110
    protected function authenticated(Request $request, /** @scrutinizer ignore-unused */ $user)

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

Loading history...
111
    {
112
        return [
113
            'code' => 0,
114
            'msg' => '登陆成功',
115
            'redirect' => true
116
        ];
117
    }
118
}
119