Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/SignupController.php
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | public function init(Request $request) | ||||
$errors['email'] = $error; | $errors['email'] = $error; | ||||
} | } | ||||
} | } | ||||
if (!empty($errors)) { | if (!empty($errors)) { | ||||
return response()->json(['status' => 'error', 'errors' => $errors], 422); | return response()->json(['status' => 'error', 'errors' => $errors], 422); | ||||
} | } | ||||
// Throttling signup requests from the same IP/Network | |||||
$limit = 3; | |||||
$minutes = 10; | |||||
$count = SignupCode::withTrashed() | |||||
->where('created_at', '>=', now()->subMinutes($minutes)->toDateTimeString()) | |||||
->where('ip_address', \App\Utils::requestIp()) | |||||
->count(); | |||||
if ($count > $limit) { | |||||
return $this->errorResponse(429, \trans('app.toomanyrequests')); | |||||
} | |||||
// Generate the verification code | // Generate the verification code | ||||
$code = SignupCode::create([ | $code = SignupCode::create([ | ||||
'data' => [ | 'data' => [ | ||||
'email' => $request->email, | 'email' => $request->email, | ||||
'first_name' => $request->first_name, | 'first_name' => $request->first_name, | ||||
'last_name' => $request->last_name, | 'last_name' => $request->last_name, | ||||
'plan' => $request->plan, | 'plan' => $request->plan, | ||||
'voucher' => $request->voucher, | 'voucher' => $request->voucher, | ||||
▲ Show 20 Lines • Show All 278 Lines • Show Last 20 Lines |