91 lines
3 KiB
PHP
91 lines
3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Providers\RouteServiceProvider;
|
|
use App\Models\User;
|
|
use Illuminate\Auth\Events\Registered;
|
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Session;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class RegisterController extends Controller
|
|
{
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Register Controller
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| This controller handles the registration of new users as well as their
|
|
| validation and creation. By default this controller uses a trait to
|
|
| provide this functionality without requiring any additional code.
|
|
|
|
|
*/
|
|
use RegistersUsers;
|
|
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->middleware('guest');
|
|
}
|
|
|
|
private function redirectTo()
|
|
{
|
|
return route('verification.notice');
|
|
}
|
|
|
|
/**
|
|
* Get a validator for an incoming registration request.
|
|
*
|
|
* @param array $data
|
|
* @return \Illuminate\Contracts\Validation\Validator
|
|
*/
|
|
protected function validator(array $data)
|
|
{
|
|
return Validator::make($data, [
|
|
'firstname' => ['required', 'string', 'min: 2', 'max:255'],
|
|
'lastname' => ['required', 'string','min: 2', 'max:255'],
|
|
'birthdate' => ['required', 'date_format:Y-m-d', 'before:' . Carbon::now()->subYears(18)->format('d-m-Y')],
|
|
'address' => ['required','min: 5', 'string', 'max:255'],
|
|
'address2' => ['sometimes', 'max:255'],
|
|
'phone' => ['required', 'string', 'min:10', 'max:13'],
|
|
'city' => ['required', 'string','min: 2', 'max:255'],
|
|
'postcode' => ['required', 'digits:5'],
|
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
|
], [
|
|
'birthdate.date_format' => trans('Le format de la date doit être du type 1992-01-01'),
|
|
'birthdate.before' => trans('Vous devez être majeur pour pouvoir participer au jeu.')
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Create a new user instance after a valid registration.
|
|
*
|
|
* @param array $data
|
|
* @return \App\Models\User
|
|
*/
|
|
protected function create(array $data)
|
|
{
|
|
return User::create([
|
|
'firstname' => $data['firstname'],
|
|
'lastname' => $data['lastname'],
|
|
'birthdate' => $data['birthdate'],
|
|
'address' => $data['address'],
|
|
'address2' => $data['address2'] ?? '',
|
|
'phone' => $data['phone'] ?? '',
|
|
'city' => $data['city'] ?? '',
|
|
'postcode' => $data['postcode'] ?? '',
|
|
'email' => $data['email'],
|
|
'password' => Hash::make($data['password']),
|
|
]);
|
|
}
|
|
}
|