2021-02-12 12:46:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Providers\RouteServiceProvider;
|
2021-03-08 17:53:18 +01:00
|
|
|
use App\Models\User;
|
2021-02-12 12:46:28 +01:00
|
|
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Where to redirect users after registration.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $redirectTo = RouteServiceProvider::HOME;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->middleware('guest');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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, [
|
2021-03-08 17:53:18 +01:00
|
|
|
'lastname' => 'required|string|max:255',
|
|
|
|
|
'firstname' => 'required|string|max:255',
|
|
|
|
|
'phone' => 'max:50',
|
|
|
|
|
'adress' => 'required|string|max:255',
|
|
|
|
|
'postal_code' => 'required|string|max:50',
|
|
|
|
|
'town'=> 'required|string|max:255',
|
2021-02-12 12:46:28 +01:00
|
|
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
|
|
|
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
2021-03-08 17:53:18 +01:00
|
|
|
'ok_cgv' => 'accepted',
|
2021-02-12 12:46:28 +01:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new user instance after a valid registration.
|
|
|
|
|
*
|
|
|
|
|
* @param array $data
|
|
|
|
|
* @return \App\User
|
|
|
|
|
*/
|
|
|
|
|
protected function create(array $data)
|
|
|
|
|
{
|
2021-03-08 17:53:18 +01:00
|
|
|
$lastname = filter_var($data['lastname'], FILTER_SANITIZE_STRING);
|
|
|
|
|
$firstname = filter_var($data['firstname'], FILTER_SANITIZE_STRING);
|
|
|
|
|
$phone = filter_var($data['phone'], FILTER_SANITIZE_STRING);
|
|
|
|
|
$email = filter_var($data['email'], FILTER_SANITIZE_EMAIL);
|
|
|
|
|
$adress = filter_var($data['adress'], FILTER_SANITIZE_STRING);
|
|
|
|
|
$postal_code = filter_var($data['postal_code'], FILTER_SANITIZE_STRING);
|
|
|
|
|
$town = filter_var($data['town'], FILTER_SANITIZE_STRING);
|
|
|
|
|
$password = $data['password'];
|
|
|
|
|
$user_cat = $data['user_cat'];
|
|
|
|
|
$social_denomination = filter_var($data['social_denomination'], FILTER_SANITIZE_STRING);
|
|
|
|
|
$tech_commercial = filter_var($data['tech_commercial'], FILTER_SANITIZE_STRING);
|
|
|
|
|
$eleveur_volailles = isset($data['eleveur_volailles']) ? true : false;
|
|
|
|
|
$eleveur_porcs = isset($data['eleveur_porcs']) ? true : false;
|
|
|
|
|
$eleveur_bovins = isset($data['eleveur_bovins']) ? true : false;
|
|
|
|
|
$capacite_stockage = filter_var($data['capacite_stockage'], FILTER_SANITIZE_STRING);
|
|
|
|
|
$temps_chargement = filter_var($data['temps_chargement'], FILTER_SANITIZE_STRING);
|
|
|
|
|
$stockage_aplat = isset($data['stockage_aplat']) ? true : false;
|
|
|
|
|
$stockage_cellule = isset($data['stockage_cellule']) ? true : false;
|
|
|
|
|
$adress_chargement = filter_var($data['adress_chargement'], FILTER_SANITIZE_STRING);
|
|
|
|
|
$optional_contact = filter_var($data['optional_contact'], FILTER_SANITIZE_STRING);
|
|
|
|
|
$ok_cgv = \Carbon\Carbon::now();
|
|
|
|
|
|
|
|
|
|
if($user_cat == "professionnel") {
|
|
|
|
|
$role = 3;
|
|
|
|
|
} else {
|
|
|
|
|
$role = 4;
|
|
|
|
|
}
|
|
|
|
|
$userData = [
|
|
|
|
|
'lastname' => $lastname,
|
|
|
|
|
'firstname' => $firstname,
|
|
|
|
|
'phone' => $phone,
|
|
|
|
|
'email' => $email,
|
|
|
|
|
'adress' => $adress,
|
|
|
|
|
'postal_code' => $postal_code,
|
|
|
|
|
'town' => $town,
|
|
|
|
|
'password' => Hash::make($password),
|
|
|
|
|
'role' => $role,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if($role==3) {
|
|
|
|
|
$proData = [
|
|
|
|
|
'social_denomination' => $social_denomination,
|
|
|
|
|
'tech_commercial' => $tech_commercial,
|
|
|
|
|
'eleveur_volailles' => $eleveur_volailles,
|
|
|
|
|
'eleveur_porcs' => $eleveur_porcs,
|
|
|
|
|
'eleveur_bovins' => $eleveur_bovins,
|
|
|
|
|
'capacite_stockage' => $capacite_stockage,
|
|
|
|
|
'temps_chargement' => $temps_chargement,
|
|
|
|
|
'stockage_aplat' => $stockage_aplat,
|
|
|
|
|
'stockage_cellule' => $stockage_cellule,
|
|
|
|
|
'adress_chargement' => $adress_chargement,
|
|
|
|
|
'optional_contact' => $optional_contact,
|
|
|
|
|
'ok_cgv' => $ok_cgv,
|
|
|
|
|
];
|
|
|
|
|
$userData = array_merge($userData,$proData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return User::create($userData);
|
2021-02-12 12:46:28 +01:00
|
|
|
}
|
|
|
|
|
}
|