2020-04-29 17:37:45 +08:00
|
|
|
<?php
|
|
|
|
namespace catchAdmin\login\controller;
|
|
|
|
|
|
|
|
use catchAdmin\login\request\LoginRequest;
|
|
|
|
use catchAdmin\permissions\model\Users;
|
|
|
|
use catcher\base\CatchController;
|
|
|
|
use catcher\CatchAuth;
|
|
|
|
use catcher\CatchResponse;
|
2020-09-04 19:01:57 +08:00
|
|
|
use catcher\Code;
|
2020-04-29 17:37:45 +08:00
|
|
|
use catcher\exceptions\LoginFailedException;
|
2020-05-18 13:41:46 +08:00
|
|
|
use thans\jwt\facade\JWTAuth;
|
2020-04-29 17:37:45 +08:00
|
|
|
|
|
|
|
class Index extends CatchController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 登陆
|
|
|
|
*
|
|
|
|
* @time 2019年11月28日
|
|
|
|
* @param LoginRequest $request
|
|
|
|
* @param CatchAuth $auth
|
|
|
|
* @return bool|string
|
|
|
|
*/
|
|
|
|
public function login(LoginRequest $request, CatchAuth $auth)
|
|
|
|
{
|
2020-09-09 10:40:44 +08:00
|
|
|
try {
|
|
|
|
$params = $request->param();
|
|
|
|
$token = $auth->attempt($params);
|
|
|
|
return CatchResponse::success([
|
|
|
|
'token' => $token,
|
|
|
|
], '登录成功');
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
return CatchResponse::fail('登录失败', $exception->getCode());
|
2020-04-29 17:37:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 登出
|
|
|
|
*
|
|
|
|
* @time 2019年11月28日
|
|
|
|
* @return \think\response\Json
|
|
|
|
*/
|
2020-05-18 10:12:33 +08:00
|
|
|
public function logout(): \think\response\Json
|
2020-04-29 17:37:45 +08:00
|
|
|
{
|
2020-05-18 10:12:33 +08:00
|
|
|
return CatchResponse::success();
|
2020-04-29 17:37:45 +08:00
|
|
|
}
|
2020-05-18 13:41:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* refresh token
|
|
|
|
*
|
|
|
|
* @author JaguarJack
|
|
|
|
* @email njphper@gmail.com
|
|
|
|
* @time 2020/5/18
|
|
|
|
* @return \think\response\Json
|
|
|
|
*/
|
|
|
|
public function refreshToken()
|
|
|
|
{
|
|
|
|
return CatchResponse::success([
|
|
|
|
'token' => JWTAuth::refresh()
|
|
|
|
]);
|
|
|
|
}
|
2020-04-29 17:37:45 +08:00
|
|
|
}
|