First Commit
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Validation\MathCaptchaRule;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
public function create(): View
|
||||
{
|
||||
$this->generateMathCaptcha();
|
||||
|
||||
return view("auth.register");
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
"name" => ["required", "string", "max:255"],
|
||||
"email" => ["required", "string", "lowercase", "email", "max:255", "unique:".User::class],
|
||||
"password" => ["required", "confirmed", Rules\Password::defaults()],
|
||||
"math_captcha" => ["required", "string", new MathCaptchaRule()],
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
"name" => $request->name,
|
||||
"email" => $request->email,
|
||||
"password" => Hash::make($request->password),
|
||||
"is_approved" => false,
|
||||
]);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
return redirect(route("dashboard", absolute: false));
|
||||
}
|
||||
|
||||
private function generateMathCaptcha(): void
|
||||
{
|
||||
$num1 = random_int(1, 10);
|
||||
$num2 = random_int(1, 10);
|
||||
$answer = $num1 + $num2;
|
||||
|
||||
session([
|
||||
"math_captcha_answer" => $answer,
|
||||
"math_captcha_question" => __("What is :num1 + :num2?", ["num1" => $num1, "num2" => $num2]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user