add email whitelist config

This commit is contained in:
Tokumeikoi 2020-02-09 18:01:06 +08:00
parent f61e37aeaf
commit 214fb2a2bf
6 changed files with 47 additions and 1 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\ConfigSave; use App\Http\Requests\Admin\ConfigSave;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Utils\Dict;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
class ConfigController extends 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_plan_id' => (int)config('v2board.try_out_plan_id', 0),
'try_out_hour' => (int)config('v2board.try_out_hour', 1), 'try_out_hour' => (int)config('v2board.try_out_hour', 1),
'email_whitelist_enable' => (int)config('v2board.email_whitelist_enable', 0), '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' => [ 'pay' => [
// alipay // alipay

View File

@ -12,11 +12,20 @@ use App\Models\Plan;
use App\Models\User; use App\Models\User;
use App\Models\InviteCode; use App\Models\InviteCode;
use App\Utils\Helper; use App\Utils\Helper;
use App\Utils\Dict;
class AuthController extends Controller class AuthController extends Controller
{ {
public function register(AuthRegister $request) 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)) { if ((int)config('v2board.stop_register', 0)) {
abort(500, '本站已关闭注册'); abort(500, '本站已关闭注册');
} }
@ -189,4 +198,5 @@ class AuthController extends Controller
'data' => true 'data' => true
]); ]);
} }
} }

View File

@ -11,6 +11,7 @@ use App\Utils\Helper;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use App\Jobs\SendEmail; use App\Jobs\SendEmail;
use App\Models\InviteCode; use App\Models\InviteCode;
use App\Utils\Dict;
class CommController extends Controller 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) public function pv(Request $request)
{ {
$inviteCode = InviteCode::where('code', $request->input('invite_code'))->first(); $inviteCode = InviteCode::where('code', $request->input('invite_code'))->first();

View File

@ -19,6 +19,7 @@ class PassportRoute
// 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');
$router->get ('/comm/getEmailSuffix', 'Passport\\CommController@getEmailSuffix');
}); });
} }
} }

18
app/Utils/Dict.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace App\Utils;
class Dict
{
CONST EMAIL_WHITELIST_SUFFIX_DEFAULT = [
'gmail.com',
'qq.com',
'163.com',
'yahoo.com',
'sina.com',
'126.com',
'outlook.com',
'yeah.net',
'foxmail.com'
];
}

View File

@ -84,4 +84,12 @@ class Helper
default: return password_verify($password, $hash); default: return password_verify($password, $hash);
} }
} }
public static function emailSuffixVerify($email, $suffixs)
{
$suffix = preg_split('@', $email)[1];
if (!$suffix) return false;
if (!in_array($suffix, $suffixs)) return false;
return true;
}
} }