feature: google recaptcha

This commit is contained in:
Tokumeikoi 2020-10-09 23:27:36 +08:00
parent 3d26fda064
commit 54ab44c3fd
7 changed files with 30 additions and 4 deletions

View File

@ -60,7 +60,10 @@ class ConfigController extends Controller
'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', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT),
'email_gmail_limit_enable' => config('v2board.email_gmail_limit_enable', 0)
'email_gmail_limit_enable' => config('v2board.email_gmail_limit_enable', 0),
'recaptcha_enable' => (int)config('v2board.recaptcha_enable', 0),
'recaptcha_key' => config('v2board.recaptcha_key'),
'recaptcha_site_key' => config('v2board.recaptcha_site_key')
],
'subscribe' => [
'plan_change_enable' => (int)config('v2board.plan_change_enable', 1),

View File

@ -12,7 +12,8 @@ class CouponController extends Controller
{
public function fetch(Request $request)
{
$coupons = Coupon::all();
$coupon = Coupon::orderBy('created_at', 'desc');
$coupons = $coupon->get();
foreach ($coupons as $k => $v) {
if ($coupons[$k]['limit_plan_ids']) $coupons[$k]['limit_plan_ids'] = json_decode($coupons[$k]['limit_plan_ids']);
}

View File

@ -14,11 +14,19 @@ use App\Models\InviteCode;
use App\Utils\Helper;
use App\Utils\Dict;
use App\Utils\CacheKey;
use ReCaptcha\ReCaptcha;
class AuthController extends Controller
{
public function register(AuthRegister $request)
{
if ((int)config('v2board.recaptcha_enable', 0)) {
$recaptcha = new ReCaptcha(config('v2board.recaptcha_key'));
$recaptchaResp = $recaptcha->verify($request->input('recaptcha_data'));
if (!$recaptchaResp->isSuccess()) {
abort(500, '验证码有误');
}
}
if ((int)config('v2board.email_whitelist_enable', 0)) {
if (!Helper::emailSuffixVerify(
$request->input('email'),

View File

@ -13,6 +13,7 @@ use App\Jobs\SendEmailJob;
use App\Models\InviteCode;
use App\Utils\Dict;
use App\Utils\CacheKey;
use ReCaptcha\ReCaptcha;
class CommController extends Controller
{
@ -24,7 +25,9 @@ class CommController extends Controller
'isInviteForce' => (int)config('v2board.invite_force', 0) ? 1 : 0,
'emailWhitelistSuffix' => (int)config('v2board.email_whitelist_enable', 0)
? $this->getEmailSuffix()
: 0
: 0,
'isRecaptcha' => (int)config('v2board.recaptcha_enable', 0) ? 1 : 0,
'recaptchaSiteKey' => config('v2board.recaptcha_site_key')
]
]);
}
@ -38,6 +41,13 @@ class CommController extends Controller
public function sendEmailVerify(CommSendEmailVerify $request)
{
if ((int)config('v2board.recaptcha_enable', 0)) {
$recaptcha = new ReCaptcha(config('v2board.recaptcha_key'));
$recaptchaResp = $recaptcha->verify($request->input('recaptcha_data'));
if (!$recaptchaResp->isSuccess()) {
abort(500, '验证码有误');
}
}
$email = $request->input('email');
if (Cache::get(CacheKey::get('LAST_SEND_EMAIL_VERIFY_TIMESTAMP', $email))) {
abort(500, '验证码已发送,请过一会再请求');

View File

@ -35,6 +35,9 @@ class ConfigSave extends FormRequest
'email_whitelist_enable' => 'in:0,1',
'email_whitelist_suffix' => '',
'email_gmail_limit_enable' => 'in:0,1',
'recaptcha_enable' => 'in:0,1',
'recaptcha_key' => '',
'recaptcha_site_key' => '',
// subscribe
'plan_change_enable' => 'in:0,1',
'reset_traffic_method' => 'in:0,1',

View File

@ -11,6 +11,7 @@
"require": {
"php": "^7.2",
"fideloper/proxy": "^4.0",
"google/recaptcha": "^1.2",
"laravel/framework": "^6.0",
"laravel/tinker": "^1.0",
"lokielse/omnipay-alipay": "3.0.6",

File diff suppressed because one or more lines are too long