From a8a6c6382e097bc29ba7a9f332795a0ca157e385 Mon Sep 17 00:00:00 2001 From: Tokumeikoi Date: Thu, 13 Aug 2020 21:36:59 +0800 Subject: [PATCH] update --- .../Controllers/Passport/AuthController.php | 27 ++++++++++++------- app/Http/Routes/PassportRoute.php | 3 +-- app/Utils/CacheKey.php | 3 ++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/Passport/AuthController.php b/app/Http/Controllers/Passport/AuthController.php index c4717e6a..3de5a855 100644 --- a/app/Http/Controllers/Passport/AuthController.php +++ b/app/Http/Controllers/Passport/AuthController.php @@ -136,17 +136,11 @@ class AuthController extends Controller ]); } + // 准备废弃 public function token2Login(Request $request) { if ($request->input('token')) { - $user = User::where('token', $request->input('token'))->first(); - 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'); + $redirect = '/#/login?verify=' . $request->input('token') . '&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard'); if (config('v2board.app_url')) { $location = config('v2board.app_url') . $redirect; } else { @@ -156,7 +150,7 @@ class AuthController extends Controller } if ($request->input('verify')) { - $key = 'token2Login_' . $request->input('verify'); + $key = CacheKey::get('TEMP_TOKEN', $request->input('verify')); $userId = Cache::get($key); if (!$userId) { 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) { $data = [ diff --git a/app/Http/Routes/PassportRoute.php b/app/Http/Routes/PassportRoute.php index af1b338a..c61afe1c 100644 --- a/app/Http/Routes/PassportRoute.php +++ b/app/Http/Routes/PassportRoute.php @@ -10,14 +10,13 @@ class PassportRoute $router->group([ 'prefix' => 'passport' ], function ($router) { - // TODO: 1.1.1 abolish - $router->post('/login', 'Passport\\AuthController@login'); // Auth $router->post('/auth/register', 'Passport\\AuthController@register'); $router->post('/auth/login', 'Passport\\AuthController@login'); $router->get ('/auth/token2Login', 'Passport\\AuthController@token2Login'); $router->get ('/auth/check', 'Passport\\AuthController@check'); $router->post('/auth/forget', 'Passport\\AuthController@forget'); + $router->post('/auth/getTempToken', 'Passport\\AuthController@getTempToken'); // Comm $router->get ('/comm/config', 'Passport\\CommController@config'); $router->post('/comm/sendEmailVerify', 'Passport\\CommController@sendEmailVerify'); diff --git a/app/Utils/CacheKey.php b/app/Utils/CacheKey.php index 496dca90..9085002a 100644 --- a/app/Utils/CacheKey.php +++ b/app/Utils/CacheKey.php @@ -10,7 +10,8 @@ class CacheKey 'SERVER_V2RAY_ONLINE_USER' => '节点在线用户', 'SERVER_V2RAY_LAST_CHECK_AT' => '节点最后检查时间', '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)