From b7bfdaf365be9602b61df269849aae1b78be7e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=94=E5=A7=AC=E6=A1=91?= <867057410@qq.com> Date: Thu, 8 Dec 2022 22:11:02 +0800 Subject: [PATCH] Fixed #243 --- app/Components/IP.php | 2 +- app/Http/Controllers/AuthController.php | 5 +- app/Http/Controllers/OAuthController.php | 38 ++++--- resources/views/auth/register.blade.php | 122 ++++++++++++----------- 4 files changed, 87 insertions(+), 80 deletions(-) diff --git a/app/Components/IP.php b/app/Components/IP.php index d79d81cb..254c1e8c 100644 --- a/app/Components/IP.php +++ b/app/Components/IP.php @@ -94,7 +94,7 @@ class IP return false; } - public static function IPIP(string $ip): array // 通过IPIP查询IP地址的详细信息 + public static function IPIP(string $ip): array // 通过IPIP离线数据查询IP地址的详细信息 { $filePath = database_path('ipipfree.ipdb'); // 来源: https://www.ipip.net/free_download/ $location = (new City($filePath))->findMap($ip, 'CN'); diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index be7aa2dd..7f4602e2 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -238,10 +238,7 @@ class AuthController extends Controller $transfer_enable = MB * ((int) sysConfig('default_traffic') + ($inviter_id ? (int) sysConfig('referral_traffic') : 0)); // 创建新用户 - $user = Helpers::addUser($data['username'], $data['password'], $transfer_enable, sysConfig('default_days'), $inviter_id, $data['nickname']); - - // 注册失败,抛出异常 - if (! $user) { + if (! $user = Helpers::addUser($data['username'], $data['password'], $transfer_enable, sysConfig('default_days'), $inviter_id, $data['nickname'])) { // 注册失败,抛出异常 return Redirect::back()->withInput()->withErrors(trans('auth.register.failed')); } diff --git a/app/Http/Controllers/OAuthController.php b/app/Http/Controllers/OAuthController.php index d75c41fe..9ca9b3a9 100644 --- a/app/Http/Controllers/OAuthController.php +++ b/app/Http/Controllers/OAuthController.php @@ -13,21 +13,6 @@ use Str; class OAuthController extends Controller { - public function route(Request $request, string $type) - { - $action = $request->input('action'); - $key = "services.{$type}.redirect"; - if ($action === 'binding') { - config([$key => route('oauth.bind', ['type' => $type])]); - } elseif ($action === 'register') { - config([$key => route('oauth.register', ['type' => $type])]); - } else { - config([$key => route('oauth.login', ['type' => $type])]); - } - - return Socialite::driver($type)->redirect(); - } - public function simple(string $type) { $info = Socialite::driver($type)->stateless()->user(); @@ -59,6 +44,21 @@ class OAuthController extends Controller return redirect()->route('profile')->with('successMsg', trans('auth.oauth.bind_success')); } + public function route(Request $request, string $type) + { + $action = $request->input('action'); + $key = "services.{$type}.redirect"; + if ($action === 'binding') { + config([$key => route('oauth.bind', ['type' => $type])]); + } elseif ($action === 'register') { + config([$key => route('oauth.register', ['type' => $type])]); + } else { + config([$key => route('oauth.login', ['type' => $type])]); + } + + return Socialite::driver($type)->redirect(); + } + private function login(string $type, $info) { $user = User::whereUsername($info->getEmail())->first(); @@ -119,6 +119,14 @@ class OAuthController extends Controller public function register($type) { + if (! sysConfig('is_register')) { + return redirect()->route('register')->withErrors(trans('auth.register.error.disable')); + } + + if ((int) sysConfig('is_invite_register') === 2) { // 必须使用邀请码 + return redirect()->route('register')->withErrors(trans('validation.required', ['attribute' => trans('auth.invite.attribute')])); + } + config(["services.{$type}.redirect" => route('oauth.register', ['type' => $type])]); $info = Socialite::driver($type)->stateless()->user(); diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index d0e10eda..53d2e2a5 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -65,7 +65,9 @@ @if(sysConfig('is_free_code')) @@ -99,7 +101,7 @@ @endif - @if(sysConfig('is_register') && sysConfig('oauth_path')) + @if(sysConfig('is_register') && sysConfig('oauth_path') && sysConfig('is_invite_register') != 2)