Browse Source

:construction: Ajoute les nouvelles pages

Shikiryu 11 months ago
parent
commit
8c48c8daa3

+ 0
- 10
app/Http/Controllers/Controller.php View File

@@ -1,10 +0,0 @@
1
-<?php
2
-
3
-namespace App\Http\Controllers;
4
-
5
-use Laravel\Lumen\Routing\Controller as BaseController;
6
-
7
-class Controller extends BaseController
8
-{
9
-    //
10
-}

+ 0
- 18
app/Http/Controllers/ExampleController.php View File

@@ -1,18 +0,0 @@
1
-<?php
2
-
3
-namespace App\Http\Controllers;
4
-
5
-class ExampleController extends Controller
6
-{
7
-    /**
8
-     * Create a new controller instance.
9
-     *
10
-     * @return void
11
-     */
12
-    public function __construct()
13
-    {
14
-        //
15
-    }
16
-
17
-    //
18
-}

+ 39
- 2
app/Http/Controllers/HomeController.php View File

@@ -3,12 +3,49 @@
3 3
 namespace App\Http\Controllers;
4 4
 
5 5
 
6
+use App\User;
6 7
 use Illuminate\Http\Request;
8
+use Illuminate\Validation\ValidationException;
9
+use Laravel\Lumen\Routing\Controller as BaseController;
7 10
 
8
-class HomeController extends Controller
11
+class HomeController extends BaseController
9 12
 {
10 13
     public function home(Request $request)
11 14
     {
12 15
         return view('home');
13 16
     }
14
-}
17
+
18
+    public function iframe(Request $request)
19
+    {
20
+        $user = null;
21
+
22
+        try {
23
+            $errors = [];
24
+            $data = $this->validate($request, [
25
+                'email' => 'required|email|unique:users'
26
+            ]);
27
+
28
+            $token = bin2hex(random_bytes(72));
29
+
30
+            $user = new User(['email' => $data['email']]);
31
+            $user->token = $token;
32
+            $user->save();
33
+
34
+            return view('registered', [
35
+                'user' => $user,
36
+            ]);
37
+
38
+        } catch (ValidationException $e) {
39
+            $errors = $e->errors();
40
+            $data = [];
41
+        } catch (\Exception $e) {
42
+            $errors = ['email' => 'Impossible de générer le token'];
43
+            $data = [];
44
+        }
45
+
46
+        return view('registration', [
47
+            'data' => $data,
48
+            'errors' => $errors
49
+        ]);
50
+    }
51
+}

+ 1
- 9
resources/views/home.blade.php View File

@@ -1,13 +1,5 @@
1 1
 @extends('layouts.app')
2 2
 
3
-@section('title', 'Page Title')
4
-
5
-@section('sidebar')
6
-    @parent
7
-
8
-    <p>This is appended to the master sidebar.</p>
9
-@endsection
10
-
11 3
 @section('content')
12
-    <p>This is my body content.</p>
4
+    @include('registration')
13 5
 @endsection

+ 99
- 14
resources/views/layouts/app.blade.php
File diff suppressed because it is too large
View File


+ 10
- 0
resources/views/registered.blade.php
File diff suppressed because it is too large
View File


+ 6
- 0
resources/views/registration.blade.php View File

@@ -0,0 +1,6 @@
1
+<form name="bookmarkletGenerator" action="<?php echo url('/register'); ?>" method="POST">
2
+    <input type="email" name="email" id="email" value="<?php echo $data['email'] ?? ''; ?>" placeholder="email@example.com" />
3
+    <?php echo isset($errors) && array_key_exists('email', $errors) ? implode(' | ', $errors['email']) : ''; ?>
4
+    <input type="checkbox" id="html" value="on" name="html" /><label for="html">Clip web page (experimental)</label>
5
+    <input type="submit" value="Generate!" id="submit"/>
6
+</form>

+ 3
- 1
routes/web.php View File

@@ -10,9 +10,11 @@
10 10
 | and give it the Closure to call when that URI is requested.
11 11
 |
12 12
 */
13
-
13
+/** @var \Laravel\Lumen\Routing\Router $router */
14 14
 $router->get('/', 'HomeController@home');
15 15
 
16
+$router->post('/register', 'HomeController@iframe');
17
+
16 18
 $router->post('/api/{token}', function($token) {
17 19
 
18 20
 });

Loading…
Cancel
Save