From 214fb2a2bfcafb682623426e075bacc1e3a8c99a Mon Sep 17 00:00:00 2001 From: Tokumeikoi Date: Sun, 9 Feb 2020 18:01:06 +0800 Subject: [PATCH] add email whitelist config --- .../Controllers/Admin/ConfigController.php | 3 ++- .../Controllers/Passport/AuthController.php | 10 ++++++++++ .../Controllers/Passport/CommController.php | 8 ++++++++ app/Http/Routes/PassportRoute.php | 1 + app/Utils/Dict.php | 18 ++++++++++++++++++ app/Utils/Helper.php | 8 ++++++++ 6 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 app/Utils/Dict.php diff --git a/app/Http/Controllers/Admin/ConfigController.php b/app/Http/Controllers/Admin/ConfigController.php index e3db029a..013bbb5a 100755 --- a/app/Http/Controllers/Admin/ConfigController.php +++ b/app/Http/Controllers/Admin/ConfigController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\Admin\ConfigSave; use Illuminate\Http\Request; +use App\Utils\Dict; use App\Http\Controllers\Controller; class ConfigController extends Controller @@ -30,7 +31,7 @@ class ConfigController extends Controller 'try_out_plan_id' => (int)config('v2board.try_out_plan_id', 0), 'try_out_hour' => (int)config('v2board.try_out_hour', 1), 'email_whitelist_enable' => (int)config('v2board.email_whitelist_enable', 0), - 'email_whitelist_suffix' => config('v2board.email_whitelist_suffix') + 'email_whitelist_suffix' => config('v2board.email_whitelist_suffix', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT) ], 'pay' => [ // alipay diff --git a/app/Http/Controllers/Passport/AuthController.php b/app/Http/Controllers/Passport/AuthController.php index a43f74f8..1a23fcfc 100644 --- a/app/Http/Controllers/Passport/AuthController.php +++ b/app/Http/Controllers/Passport/AuthController.php @@ -12,11 +12,20 @@ use App\Models\Plan; use App\Models\User; use App\Models\InviteCode; use App\Utils\Helper; +use App\Utils\Dict; class AuthController extends Controller { public function register(AuthRegister $request) { + if ((int)config('v2board.email_suffix_enable', 0)) { + if (!Helper::emailSuffixVerify( + $request->input('email'), + config('v2board.email_suffix_whitelist', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT)) + ) { + abort(500, '邮箱后缀不处于白名单中'); + } + } if ((int)config('v2board.stop_register', 0)) { abort(500, '本站已关闭注册'); } @@ -189,4 +198,5 @@ class AuthController extends Controller 'data' => true ]); } + } diff --git a/app/Http/Controllers/Passport/CommController.php b/app/Http/Controllers/Passport/CommController.php index 411887fc..c7f144d0 100644 --- a/app/Http/Controllers/Passport/CommController.php +++ b/app/Http/Controllers/Passport/CommController.php @@ -11,6 +11,7 @@ use App\Utils\Helper; use Illuminate\Support\Facades\Cache; use App\Jobs\SendEmail; use App\Models\InviteCode; +use App\Utils\Dict; class CommController extends Controller { @@ -58,6 +59,13 @@ class CommController extends Controller ]); } + public function getEmailSuffix() + { + return response([ + 'data' => config('v2board.email_suffix_whitelist', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT) + ]); + } + public function pv(Request $request) { $inviteCode = InviteCode::where('code', $request->input('invite_code'))->first(); diff --git a/app/Http/Routes/PassportRoute.php b/app/Http/Routes/PassportRoute.php index 63ac4b43..0d6588d4 100644 --- a/app/Http/Routes/PassportRoute.php +++ b/app/Http/Routes/PassportRoute.php @@ -19,6 +19,7 @@ class PassportRoute // Comm $router->get ('/comm/config', 'Passport\\CommController@config'); $router->post('/comm/sendEmailVerify', 'Passport\\CommController@sendEmailVerify'); + $router->get ('/comm/getEmailSuffix', 'Passport\\CommController@getEmailSuffix'); }); } } diff --git a/app/Utils/Dict.php b/app/Utils/Dict.php new file mode 100644 index 00000000..236c6360 --- /dev/null +++ b/app/Utils/Dict.php @@ -0,0 +1,18 @@ +