This commit is contained in:
Tokumeikoi 2020-08-13 21:36:59 +08:00
parent bd35c782f0
commit a8a6c6382e
3 changed files with 21 additions and 12 deletions

View File

@ -136,17 +136,11 @@ class AuthController extends Controller
]); ]);
} }
// 准备废弃
public function token2Login(Request $request) public function token2Login(Request $request)
{ {
if ($request->input('token')) { if ($request->input('token')) {
$user = User::where('token', $request->input('token'))->first(); $redirect = '/#/login?verify=' . $request->input('token') . '&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard');
if (!$user) {
return header('Location:' . config('v2board.app_url'));
}
$code = Helper::guid();
$key = 'token2Login_' . $code;
Cache::put($key, $user->id, 600);
$redirect = '/#/login?verify=' . $code . '&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard');
if (config('v2board.app_url')) { if (config('v2board.app_url')) {
$location = config('v2board.app_url') . $redirect; $location = config('v2board.app_url') . $redirect;
} else { } else {
@ -156,7 +150,7 @@ class AuthController extends Controller
} }
if ($request->input('verify')) { if ($request->input('verify')) {
$key = 'token2Login_' . $request->input('verify'); $key = CacheKey::get('TEMP_TOKEN', $request->input('verify'));
$userId = Cache::get($key); $userId = Cache::get($key);
if (!$userId) { if (!$userId) {
abort(500, '令牌有误'); abort(500, '令牌有误');
@ -180,6 +174,21 @@ class AuthController extends Controller
} }
} }
public function getTempToken(Request $request)
{
$user = User::where('token', $request->input('token'))->first();
if (!$user) {
abort(500, '用户不存在');
}
$code = Helper::guid();
$key = CacheKey::get('TEMP_TOKEN', $code);
Cache::put($key, $user->id, 60);
return response([
'data' => $code
]);
}
public function check(Request $request) public function check(Request $request)
{ {
$data = [ $data = [

View File

@ -10,14 +10,13 @@ class PassportRoute
$router->group([ $router->group([
'prefix' => 'passport' 'prefix' => 'passport'
], function ($router) { ], function ($router) {
// TODO: 1.1.1 abolish
$router->post('/login', 'Passport\\AuthController@login');
// Auth // Auth
$router->post('/auth/register', 'Passport\\AuthController@register'); $router->post('/auth/register', 'Passport\\AuthController@register');
$router->post('/auth/login', 'Passport\\AuthController@login'); $router->post('/auth/login', 'Passport\\AuthController@login');
$router->get ('/auth/token2Login', 'Passport\\AuthController@token2Login'); $router->get ('/auth/token2Login', 'Passport\\AuthController@token2Login');
$router->get ('/auth/check', 'Passport\\AuthController@check'); $router->get ('/auth/check', 'Passport\\AuthController@check');
$router->post('/auth/forget', 'Passport\\AuthController@forget'); $router->post('/auth/forget', 'Passport\\AuthController@forget');
$router->post('/auth/getTempToken', 'Passport\\AuthController@getTempToken');
// Comm // Comm
$router->get ('/comm/config', 'Passport\\CommController@config'); $router->get ('/comm/config', 'Passport\\CommController@config');
$router->post('/comm/sendEmailVerify', 'Passport\\CommController@sendEmailVerify'); $router->post('/comm/sendEmailVerify', 'Passport\\CommController@sendEmailVerify');

View File

@ -10,7 +10,8 @@ class CacheKey
'SERVER_V2RAY_ONLINE_USER' => '节点在线用户', 'SERVER_V2RAY_ONLINE_USER' => '节点在线用户',
'SERVER_V2RAY_LAST_CHECK_AT' => '节点最后检查时间', 'SERVER_V2RAY_LAST_CHECK_AT' => '节点最后检查时间',
'SERVER_TROJAN_ONLINE_USER' => 'trojan节点在线用户', 'SERVER_TROJAN_ONLINE_USER' => 'trojan节点在线用户',
'SERVER_TROJAN_LAST_CHECK_AT' => 'trojan节点最后检查时间' 'SERVER_TROJAN_LAST_CHECK_AT' => 'trojan节点最后检查时间',
'TEMP_TOKEN' => '临时令牌'
]; ];
public static function get(string $key, $uniqueValue) public static function get(string $key, $uniqueValue)