修改auth认证
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
<?php
|
||||
namespace catchAdmin\login\controller;
|
||||
|
||||
use app\exceptions\LoginFailedException;
|
||||
use catchAdmin\user\Auth;
|
||||
use catchAdmin\login\request\LoginRequest;
|
||||
use catchAdmin\user\model\Users;
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchAuth;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\exceptions\LoginFailedException;
|
||||
use think\captcha\Captcha;
|
||||
|
||||
class Index extends CatchController
|
||||
@@ -22,29 +24,39 @@ class Index extends CatchController
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 登陆
|
||||
*
|
||||
* @time 2019年11月28日
|
||||
* @param LoginRequest $request
|
||||
* @return bool|string
|
||||
* @throws \catcher\exceptions\LoginFailedException
|
||||
* @throws \cather\exceptions\LoginFailedException
|
||||
* @throws LoginFailedException
|
||||
*/
|
||||
public function login(LoginRequest $request)
|
||||
/**
|
||||
* 登陆
|
||||
*
|
||||
* @time 2019年11月28日
|
||||
* @param LoginRequest $request
|
||||
* @param CatchAuth $auth
|
||||
* @return bool|string
|
||||
*/
|
||||
public function login(LoginRequest $request, CatchAuth $auth)
|
||||
{
|
||||
$params = $request->param();
|
||||
$token = Auth::login($params);
|
||||
|
||||
$token = $auth->attempt($params);
|
||||
|
||||
$user = $auth->user();
|
||||
|
||||
if ($user->status == Users::DISABLE) {
|
||||
throw new LoginFailedException('该用户已被禁用');
|
||||
}
|
||||
|
||||
// 记录用户登录
|
||||
$user->last_login_ip = request()->ip();
|
||||
$user->last_login_time = time();
|
||||
$user->save();
|
||||
|
||||
// 登录事件
|
||||
$params['success'] = $token;
|
||||
|
||||
event('loginLog', $params);
|
||||
|
||||
return $token ? CatchResponse::success([
|
||||
'token' => $token,
|
||||
], '登录成功') :
|
||||
|
||||
CatchResponse::success('', '登录失败');
|
||||
], '登录成功') : CatchResponse::success('', '登录失败');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,4 +86,4 @@ class Index extends CatchController
|
||||
{
|
||||
return $captcha->create($config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,5 +19,6 @@ class LoginRequest extends CatchRequest
|
||||
{
|
||||
// TODO: Implement message() method.
|
||||
return [];
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -35,14 +35,7 @@ class Auth
|
||||
throw new LoginFailedException('登陆失败, 请检查用户名和密码');
|
||||
}
|
||||
|
||||
if ($user->status == Users::DISABLE) {
|
||||
throw new LoginFailedException('该用户已被禁用');
|
||||
}
|
||||
|
||||
// 记录用户登录
|
||||
$user->last_login_ip = request()->ip();
|
||||
$user->last_login_time = time();
|
||||
$user->save();
|
||||
|
||||
// Session::set(self::getLoginUserKey(), $user);
|
||||
|
||||
|
@@ -2,12 +2,14 @@
|
||||
namespace catchAdmin\user\controller;
|
||||
|
||||
use app\Request;
|
||||
use catchAdmin\permissions\model\Permissions;
|
||||
use catchAdmin\permissions\model\Roles;
|
||||
use catchAdmin\user\Auth;
|
||||
use catchAdmin\user\model\Users;
|
||||
use catchAdmin\user\request\CreateRequest;
|
||||
use catchAdmin\user\request\UpdateRequest;
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchAuth;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\Tree;
|
||||
use catcher\Utils;
|
||||
@@ -33,9 +35,29 @@ class User extends CatchController
|
||||
return CatchResponse::paginate($this->user->getList($request->param()));
|
||||
}
|
||||
|
||||
public function info()
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
* @time 2020年01月07日
|
||||
* @param CatchAuth $auth
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function info(CatchAuth $auth)
|
||||
{
|
||||
return CatchResponse::success(Auth::getUserInfo());
|
||||
$user = $auth->user();
|
||||
|
||||
$roles = $user->getRoles();
|
||||
|
||||
$user->permissions = Permissions::whereIn('id', $user->getPermissionsBy())
|
||||
->field(['permission_name as title', 'route', 'icon'])
|
||||
->select();
|
||||
|
||||
$user->roles = $roles;
|
||||
|
||||
return CatchResponse::success($user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user