52 lines
1.2 KiB
PHP
52 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
use App\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Laravel\Lumen\Routing\Controller as BaseController;
|
|
|
|
class HomeController extends BaseController
|
|
{
|
|
public function home(Request $request)
|
|
{
|
|
return view('home');
|
|
}
|
|
|
|
public function iframe(Request $request)
|
|
{
|
|
$user = null;
|
|
|
|
try {
|
|
$errors = [];
|
|
$data = $this->validate($request, [
|
|
'email' => 'required|email|unique:users'
|
|
]);
|
|
|
|
$token = bin2hex(random_bytes(72));
|
|
|
|
$user = new User(['email' => $data['email']]);
|
|
$user->token = $token;
|
|
$user->save();
|
|
|
|
return view('registered', [
|
|
'user' => $user,
|
|
]);
|
|
|
|
} catch (ValidationException $e) {
|
|
$errors = $e->errors();
|
|
$data = [];
|
|
} catch (\Exception $e) {
|
|
$errors = ['email' => 'Impossible de générer le token'];
|
|
$data = [];
|
|
}
|
|
|
|
return view('registration', [
|
|
'data' => $data,
|
|
'errors' => $errors
|
|
]);
|
|
}
|
|
}
|