2021-02-12 12:46:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2021-02-16 20:37:53 +01:00
|
|
|
use App\Models\User;
|
|
|
|
|
use Carbon\Carbon;
|
2021-02-12 12:46:28 +01:00
|
|
|
use Illuminate\Http\Request;
|
2021-02-16 20:37:53 +01:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
2021-02-12 12:46:28 +01:00
|
|
|
|
|
|
|
|
class UsersController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2021-02-16 20:37:53 +01:00
|
|
|
$users = User::get();
|
|
|
|
|
return view('bo.users.index',compact('users'));
|
2021-02-12 12:46:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function create()
|
|
|
|
|
{
|
2021-02-16 20:37:53 +01:00
|
|
|
return view('bo.users.create');
|
2021-02-12 12:46:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function store(Request $request)
|
|
|
|
|
{
|
2021-02-16 20:37:53 +01:00
|
|
|
$request->validate([
|
|
|
|
|
'lastname' => 'required|string|max:255',
|
|
|
|
|
'firstname' => 'required|string|max:255',
|
|
|
|
|
'birth_date' => 'max:10',
|
|
|
|
|
'email' => 'required|string|email|max:255|unique:users',
|
|
|
|
|
'password' => 'required|string|min:8',
|
|
|
|
|
'address' => 'max:255',
|
|
|
|
|
'address2' => 'max:255',
|
|
|
|
|
'town' => 'max:255',
|
|
|
|
|
'postal_code' => 'max:255',
|
|
|
|
|
'country' => 'max:255'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$civility = $request->civility;
|
|
|
|
|
$lastname = filter_var($request->lastname, FILTER_SANITIZE_STRING);
|
|
|
|
|
$firstname = filter_var($request->firstname, FILTER_SANITIZE_STRING);
|
|
|
|
|
$birthDate = $request->birth_date;
|
|
|
|
|
$email = filter_var($request->email, FILTER_SANITIZE_EMAIL);
|
|
|
|
|
$password = $request->password;
|
|
|
|
|
$address = filter_var($request->address, FILTER_SANITIZE_STRING);
|
|
|
|
|
$address2 = $request->address2 !== null ? filter_var($request->address2, FILTER_SANITIZE_STRING) : null;
|
|
|
|
|
$town = filter_var($request->town, FILTER_SANITIZE_STRING);
|
|
|
|
|
$postalCode = filter_var($request->postal_code, FILTER_SANITIZE_STRING);
|
|
|
|
|
$country = filter_var($request->country, FILTER_SANITIZE_STRING);
|
|
|
|
|
$tokenMail = Str::uuid();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->isSQLDate($birthDate)){
|
|
|
|
|
$d = Carbon::createFromFormat('Y-m-d', $birthDate);
|
|
|
|
|
}elseif ($this->isFormDate($birthDate)){
|
|
|
|
|
$d = Carbon::createFromFormat('d/m/Y', $birthDate);
|
|
|
|
|
$birthDate = $d->toDateString();
|
|
|
|
|
}else{
|
|
|
|
|
if(!empty($birthDate)){
|
|
|
|
|
return back()
|
|
|
|
|
->withInput($request->except('password'))
|
|
|
|
|
->withErrors("Erreur sur le champs : date de naissance.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$crmId = null;
|
|
|
|
|
|
|
|
|
|
$user = new User();
|
|
|
|
|
$user->crm_id = $crmId;
|
|
|
|
|
$user->civility = $civility;
|
|
|
|
|
$user->firstname = $firstname;
|
|
|
|
|
$user->lastname = $lastname;
|
|
|
|
|
$user->birth_date = $birthDate;
|
|
|
|
|
$user->email = $email;
|
|
|
|
|
$user->password = Hash::make($password);
|
|
|
|
|
$user->address = $address;
|
|
|
|
|
$user->address2 = $address2;
|
|
|
|
|
$user->town = $town;
|
|
|
|
|
$user->postal_code = $postalCode;
|
|
|
|
|
$user->country = ucfirst($country);
|
|
|
|
|
$user->email_verify_token = $tokenMail;
|
|
|
|
|
$success = $user->save();
|
|
|
|
|
var_dump($success);
|
|
|
|
|
|
|
|
|
|
return redirect()->route('bo.users.index')
|
|
|
|
|
->with('success', "utilisateur créé.");
|
2021-02-12 12:46:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function show($id)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function edit($id)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function destroy($id)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
2021-02-16 20:37:53 +01:00
|
|
|
|
|
|
|
|
private function isSQLDate($date){
|
|
|
|
|
if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $date))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function isFormDate($date){
|
|
|
|
|
if (preg_match("/^(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/[0-9]{4}$/", $date))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-02-12 12:46:28 +01:00
|
|
|
}
|