2018-04-09 21:38:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
2018-04-14 23:17:24 +02:00
|
|
|
use App\User;
|
2018-04-09 21:38:31 +02:00
|
|
|
use Illuminate\Http\Request;
|
2018-04-14 23:17:24 +02:00
|
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
use Laravel\Lumen\Routing\Controller as BaseController;
|
2018-04-09 21:38:31 +02:00
|
|
|
|
2018-04-14 23:17:24 +02:00
|
|
|
class HomeController extends BaseController
|
2018-04-09 21:38:31 +02:00
|
|
|
{
|
|
|
|
public function home(Request $request)
|
|
|
|
{
|
|
|
|
return view('home');
|
|
|
|
}
|
2018-04-14 23:17:24 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|