webapp/app/Http/Controllers/HomeController.php

52 lines
1.2 KiB
PHP
Raw Normal View History

2018-04-09 21:38:31 +02:00
<?php
namespace App\Http\Controllers;
use App\User;
2018-04-09 21:38:31 +02:00
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Laravel\Lumen\Routing\Controller as BaseController;
2018-04-09 21:38:31 +02:00
class HomeController extends BaseController
2018-04-09 21:38:31 +02:00
{
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
]);
}
}