You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Auth;
|
|
|
|
class RegisterController extends Controller
|
|
{
|
|
public function show()
|
|
{
|
|
$form = flash()->display('form') ?? [];
|
|
|
|
response()->view('pages.auth.register', array_merge($form, [
|
|
'errors' => flash()->display('error') ?? [],
|
|
]));
|
|
}
|
|
|
|
public function store()
|
|
{
|
|
$credentials = request()->validate([
|
|
'name' => 'string',
|
|
'email' => 'email',
|
|
'password' => 'min:8',
|
|
'confirmPassword*' => 'matchesValueOf:password',
|
|
]);
|
|
|
|
if (!$credentials) {
|
|
return response()
|
|
->withFlash('form', request()->body())
|
|
->withFlash('error', request()->errors())
|
|
->redirect('/auth/register');
|
|
}
|
|
|
|
$success = auth()->register($credentials);
|
|
|
|
if (!$success) {
|
|
return response()
|
|
->withFlash('form', request()->body())
|
|
->withFlash('error', auth()->errors())
|
|
->redirect('/auth/register');
|
|
}
|
|
|
|
return response()->redirect('/dashboard');
|
|
}
|
|
}
|