提交代码
This commit is contained in:
83
app/Agent/Controllers/AuthController.php
Normal file
83
app/Agent/Controllers/AuthController.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
namespace App\Agent\Controllers;
|
||||
|
||||
use Auth;
|
||||
use Illuminate\Auth\Events\Login;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Validator;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth.agent')->except(['login']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录 *
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-11-07T13:47:02+0800
|
||||
* @param Request $request
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
$user = Auth::guard('agent')->user();
|
||||
if ($user) {
|
||||
if ($user->identity_id < 2) {
|
||||
return redirect()->route('Agent.logout');
|
||||
}
|
||||
return redirect()->route('Agent.index');
|
||||
|
||||
}
|
||||
if ($request->isMethod('POST')) {
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'username' => 'required|mobile|exists:users',
|
||||
'password' => 'required|between:6,32',
|
||||
], [
|
||||
'username.required' => '手机号码必须填写',
|
||||
'username.mobile' => '手机号码格式不正确',
|
||||
'username.exists' => '手机号码不存在',
|
||||
'password.required' => '登录密码必须填写',
|
||||
'password.between' => '登录密码应在:min-:max位之间',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
|
||||
$cert = [
|
||||
'username' => $request->username,
|
||||
'password' => $request->password,
|
||||
];
|
||||
|
||||
if (Auth::guard('agent')->attempt($cert, true)) {
|
||||
$user = Auth::guard('agent')->user();
|
||||
if ($user->identity_id < 2) {
|
||||
return $this->success('您没有登录权限', route('Agent.logout'));
|
||||
}
|
||||
return $this->success('登录成功', route('Agent.index'));
|
||||
} else {
|
||||
return $this->error('用户名或密码不存在');
|
||||
}
|
||||
} else {
|
||||
return view('Agent::auth.login');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-11-07T13:46:45+0800
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
Auth::guard('agent')->logout();
|
||||
session()->flush();
|
||||
return redirect()->route('Agent.login');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user