]> _ Git - psq.git/commitdiff
verify email on register + recaptcha
authorLouis Jeckel <louis.jeckel@outlook.cm>
Thu, 27 Aug 2020 09:45:02 +0000 (11:45 +0200)
committerLouis Jeckel <louis.jeckel@outlook.cm>
Thu, 27 Aug 2020 09:45:02 +0000 (11:45 +0200)
15 files changed:
.idea/lettre-pharma.iml
.idea/php.xml
app/Http/Controllers/AccountController.php
app/Http/Controllers/Auth/RegisterController.php
app/Http/Controllers/FlowpaperController.php
app/User.php
composer.json
composer.lock
config/recaptcha.php [new file with mode: 0644]
resources/lang/fr.json
resources/lang/fr/validation.php
resources/views/auth/register.blade.php
resources/views/home/index.blade.php
resources/views/layouts/app.blade.php
routes/web.php

index 9e477f9abfe2d02de088ef830bf7679b08b94aec..3f516412cde1f4c002548397a8dea5fc7a0eb1ce 100644 (file)
@@ -12,6 +12,7 @@
       <excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-debugbar" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-ide-helper" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/reflection-docblock" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/biscolab/laravel-recaptcha" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/caouecs/laravel-lang" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/clue/stream-filter" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/coderello/laravel-nova-lang" />
index e5244e66bc86b8d31edcc7df457ab437f90e1b4e..6332590a6f08bfcc6939de5f1df2186f178cde18 100644 (file)
       <path value="$PROJECT_DIR$/vendor/jean85/pretty-package-versions" />
       <path value="$PROJECT_DIR$/vendor/sentry/sentry" />
       <path value="$PROJECT_DIR$/vendor/sentry/sentry-laravel" />
+      <path value="$PROJECT_DIR$/vendor/biscolab/laravel-recaptcha" />
     </include_path>
   </component>
   <component name="PhpInterpreters">
index d6c2ef90a01aedbd6d99f2c96608e6cb8d2abc5a..a7344790cf1b875d4cbe9c573dabbfb1b8f3ab2c 100644 (file)
@@ -62,9 +62,11 @@ class AccountController extends Controller
            'first_name' => $request->input('first_name'),
            'last_name' => $request->input('last_name'),
            'password' => \Hash::make($request->input('password')),
-           'reg_complete' => true
+           'reg_complete' => true,
         ]);
 
+        $user->markEmailAsVerified();
+
 
         LoginToken::where('token', $request->input('login_token'))->delete();
 
index be50aa3dea164d79eb4d6604d0249a30a57270dd..04f9afc70b7deb208829de3342ac8ce5ef032dbe 100644 (file)
@@ -65,6 +65,7 @@ class RegisterController extends Controller
                     ->where(fn(Builder $builder) => $builder->where('type', User::TYPE_USER))
             ],
             'password' => ['required', 'string', 'min:8', 'confirmed'],
+            recaptchaFieldName() => recaptchaRuleName(),
         ]);
     }
 
@@ -100,5 +101,9 @@ class RegisterController extends Controller
     }
 
 
+    protected function registered(Request $request, $user)
+    {
+        \Session::flash('message', 'Votre inscription à bien été prise en compte ! Veuillez vérifier vos emails.');
+    }
 
 }
index bfb0d163dce53cc28a004af15fdedd43090bf41f..e423d527c8adbc208c784619896751e1951600a7 100644 (file)
@@ -24,6 +24,7 @@ class FlowpaperController extends Controller
     {
         $this->authorize('view', $file);
 
+
         AccessLog::log($request, $file);
         return $file->view();
     }
index d665743cfa9c8cd6eaa895d2093b0a89b1b22e18..b8d907efb53a1ad02fef485631d0a6b1c06387e6 100644 (file)
@@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Relations\BelongsTo;
 use Illuminate\Database\Eloquent\Relations\HasMany;
 use Illuminate\Foundation\Auth\User as Authenticatable;
+use Illuminate\Foundation\Auth\VerifiesEmails;
 use Illuminate\Notifications\Notifiable;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Carbon;
@@ -33,7 +34,7 @@ use Laravel\Scout\Searchable;
  * @property bool $reg_complete
  * @property string $status
  */
-class User extends Authenticatable
+class User extends Authenticatable implements MustVerifyEmail
 {
     use Notifiable;
     use Searchable;
index 6eeb9fb6e40a474dfe48a6240c6debf2a62ffbfd..405c60bb6665ea3bce4650daac461dbf89b214c1 100644 (file)
@@ -14,6 +14,7 @@
         "algolia/algoliasearch-client-php": "^2.6",
         "anaseqal/nova-import": "^0.0.3",
         "area17/twill": "^2.0",
+        "biscolab/laravel-recaptcha": "^4.1",
         "caouecs/laravel-lang": "~6.0",
         "coderello/laravel-nova-lang": "^1.4",
         "fideloper/proxy": "^4.2",
index 3b5ee1f9933ff9afc50a94a903b4b8e2867a8ad3..f0bd77dc2c9c8902b128b0cf9c857bf275d323fa 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "619658d66882bcbce2ed61728005dc01",
+    "content-hash": "5c282ec3e2dd3c868fc7681ebeedb9f5",
     "packages": [
         {
             "name": "algolia/algoliasearch-client-php",
             "homepage": "https://github.com/Bacon/BaconQrCode",
             "time": "2018-04-25T17:53:56+00:00"
         },
+        {
+            "name": "biscolab/laravel-recaptcha",
+            "version": "4.1.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/biscolab/laravel-recaptcha.git",
+                "reference": "9bfe22ffb78efaff005659af68867d1ba52c0a00"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/biscolab/laravel-recaptcha/zipball/9bfe22ffb78efaff005659af68867d1ba52c0a00",
+                "reference": "9bfe22ffb78efaff005659af68867d1ba52c0a00",
+                "shasum": ""
+            },
+            "require": {
+                "laravel/framework": "^5.5|^6.0|^7.0",
+                "php": "^7.1"
+            },
+            "require-dev": {
+                "orchestra/testbench": "~3.0",
+                "phpunit/phpunit": "6.*|7.*"
+            },
+            "suggest": {
+                "biscolab/laravel-authlog": "Allows logged-in users management and forced log-out"
+            },
+            "type": "library",
+            "extra": {
+                "laravel": {
+                    "providers": [
+                        "Biscolab\\ReCaptcha\\ReCaptchaServiceProvider"
+                    ],
+                    "aliases": {
+                        "ReCaptcha": "Biscolab\\ReCaptcha\\Facades\\ReCaptcha"
+                    }
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Biscolab\\ReCaptcha\\": "src/"
+                },
+                "files": [
+                    "src/helpers.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Roberto Belotti",
+                    "email": "roby.belotti@gmail.com",
+                    "homepage": "https://biscolab.com",
+                    "role": "Developer"
+                }
+            ],
+            "description": "Simple and painless Google reCAPTCHA package for Laravel 5, 6 and 7",
+            "homepage": "https://biscolab.com/laravel-recaptcha",
+            "keywords": [
+                "captcha",
+                "laravel",
+                "recaptcha",
+                "validation"
+            ],
+            "time": "2020-03-06T23:25:41+00:00"
+        },
         {
             "name": "brick/math",
             "version": "0.8.14",
diff --git a/config/recaptcha.php b/config/recaptcha.php
new file mode 100644 (file)
index 0000000..8817b5d
--- /dev/null
@@ -0,0 +1,148 @@
+<?php
+/**
+ * Copyright (c) 2017 - present
+ * LaravelGoogleRecaptcha - recaptcha.php
+ * author: Roberto Belotti - roby.belotti@gmail.com
+ * web : robertobelotti.com, github.com/biscolab
+ * Initial version created on: 12/9/2018
+ * MIT license: https://github.com/biscolab/laravel-recaptcha/blob/master/LICENSE
+ */
+
+/**
+ * To configure correctly please visit https://developers.google.com/recaptcha/docs/start
+ */
+return [
+
+    /**
+     *
+     * The site key
+     * get site key @ www.google.com/recaptcha/admin
+     *
+     */
+    'api_site_key'                 => env('RECAPTCHA_SITE_KEY', ''),
+
+    /**
+     *
+     * The secret key
+     * get secret key @ www.google.com/recaptcha/admin
+     *
+     */
+    'api_secret_key'               => env('RECAPTCHA_SECRET_KEY', ''),
+
+    /**
+     *
+     * ReCATCHA version
+     * Supported: "v2", "invisible", "v3",
+     *
+     * get more info @ https://developers.google.com/recaptcha/docs/versions
+     *
+     */
+    'version'                      => 'v2',
+
+    /**
+     *
+     * The curl timout in seconds to validate a recaptcha token
+     * @since v3.5.0
+     *
+     */
+    'curl_timeout'                 => 10,
+
+    /**
+     *
+     * IP addresses for which validation will be skipped
+     *
+     */
+    'skip_ip'                      => [],
+
+    /**
+     *
+     * Default route called to check the Google reCAPTCHA token
+     * @since v3.2.0
+     *
+     */
+    'default_validation_route'     => 'recaptcha/validate',
+
+    /**
+     *
+     * The name of the parameter used to send Google reCAPTCHA token to verify route
+     * @since v3.2.0
+     *
+     */
+    'default_token_parameter_name' => 'token',
+
+    /**
+     *
+     * The default Google reCAPTCHA language code
+     * It has no effect with v3
+     * @see   https://developers.google.com/recaptcha/docs/language
+     * @since v3.6.0
+     *
+     */
+    'default_language'             => 'fr',
+
+    /**
+     *
+     * The default form ID. Only for "invisible" reCAPTCHA
+     * @since v4.0.0
+     *
+     */
+    'default_form_id'              => 'recaptcha-invisible-form',
+
+    /**
+     *
+     * Deferring the render can be achieved by specifying your onload callback function and adding parameters to the JavaScript resource.
+     * It has no effect with v3 and invisible
+     * @see   https://developers.google.com/recaptcha/docs/display#explicit_render
+     * @since v4.0.0
+     * Supported true, false
+     *
+     */
+    'explicit'                     => false,
+
+    /**
+     *
+     * g-recaptcha tag attributes and grecaptcha.render parameters (v2 only)
+     * @see   https://developers.google.com/recaptcha/docs/display#render_param
+     * @since v4.0.0
+     */
+    'tag_attributes'               => [
+
+        /**
+         * The color theme of the widget.
+         * Supported "light", "dark"
+         */
+        'theme'            => 'light',
+
+        /**
+         * The size of the widget.
+         * Supported "normal", "compact"
+         */
+        'size'             => 'normal',
+
+        /**
+         * The tabindex of the widget and challenge.
+         * If other elements in your page use tabindex, it should be set to make user navigation easier.
+         */
+        'tabindex'         => 0,
+
+        /**
+         * The name of your callback function, executed when the user submits a successful response.
+         * The g-recaptcha-response token is passed to your callback.
+         * DO NOT SET "biscolabOnloadCallback"
+         */
+        'callback'         => null,
+
+        /**
+         * The name of your callback function, executed when the reCAPTCHA response expires and the user needs to re-verify.
+         * DO NOT SET "biscolabOnloadCallback"
+         */
+        'expired-callback' => null,
+
+        /**
+         * The name of your callback function, executed when reCAPTCHA encounters an error (usually network connectivity) and cannot continue until connectivity is restored.
+         * If you specify a function here, you are responsible for informing the user that they should retry.
+         * DO NOT SET "biscolabOnloadCallback"
+         */
+        'error-callback'   => null,
+    ]
+];
index ecb1ced8c7a7542ce4a814426d668ec93ca9867c..6e6c009210e2e3b8198be94d53461c4bbd15f891 100644 (file)
@@ -2,7 +2,7 @@
     "A fresh verification link has been sent to your email address.": "Un nouveau lien de vérification a été envoyé à votre adresse email.",
     "All rights reserved.": "Tous droits réservés.",
     "Before proceeding, please check your email for a verification link.": "Avant de continuer, veuillez vérifier votre courrier électronique pour un lien de vérification.",
-    "click here to request another": "cliquer ici pour faire une autre demande",
+    "click here to request another": "cliquez ici pour faire une autre demande",
     "Confirm Password": "Confirmez le mot de passe",
     "E-Mail Address": "Adresse email",
     "Error": "Erreur",
index 44f9397344e7f4ca6b7391b7aa1bc74e6993f49d..30b20fc946f85867632fd1b8537674e4b614cce2 100644 (file)
@@ -134,6 +134,8 @@ return [
         ],
     ],
 
+    'recaptcha' => "Merci de cocher la case 'je ne suis pas un robot'",
+
     /*
     |--------------------------------------------------------------------------
     | Custom Validation Attributes
index a3bf374e0256bb19caae6ead93a34605a7e1f328..b4332cacec9e451e120b89fb8eaab9a421517609 100644 (file)
                             </div>
                         </div>
 
+                        <div class="form-group row">
+                            <div class="col-4"></div>
+                            <div class="col-8">
+                                @error(recaptchaFieldName())
+                                    <span class="invalid-feedback" role="alert">
+                                        <strong>{{ $message }}</strong>
+                                    </span>
+                                @enderror
+                                {!! ReCaptcha::htmlFormSnippet() !!}
+                            </div>
+                        </div>
+
                         <div class="form-group row mb-0">
                             <div class="col-md-6 offset-md-4">
                                 <button type="submit" class="btn btn-primary">
index ca31f7ad1c9a82169fc7a7276d89751a341989b4..ab721c35b62479971321bf6e299a38ea0cfc5ba8 100644 (file)
     </div>
     @endif
 
+
+
+        @if (session('resent'))
+            <div class="alert alert-success" role="alert">
+                {{ __('A fresh verification link has been sent to your email address.') }}
+            </div>
+        @elseif(\Auth::check() && !\Auth::user()->hasVerifiedEmail())
+                <div class="alert alert-warning">
+                    {{ __('Before proceeding, please check your email for a verification link.') }}
+                    {{ __('If you did not receive the email') }},
+                    <form class="d-inline" method="POST" action="{{ route('verification.resend') }}">
+                        @csrf
+                        <button type="submit" class="btn btn-link p-0 m-0 align-baseline">{{ __('click here to request another') }}</button>.
+                    </form>
+                </div>
+        @endif
+
     <h1>L'actualité à la une de notre quotidien</h1>
     <div class="row justify-content-center pt-3">
         <div class="col-md-4">
index 2f13d1152115301f30fee18250e69cc0294ffef4..b2d2bc3c249d1348e7eb6818663d033afc5207f8 100644 (file)
@@ -15,6 +15,8 @@
 
     @yield('scripts')
 
+    {!! ReCaptcha::htmlScriptTagJsApi() !!}
+
     <!-- Fonts -->
     <link rel="dns-prefetch" href="//fonts.gstatic.com">
     <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
index cb31d9f08155c3c3eead9419369b4c3776ea69a6..a9769bac6f645fe3a8990a3c6045100a529644ca 100644 (file)
@@ -45,7 +45,9 @@ Route::domain(env('CLIENT_DOMAIN_NAME'))->group(function() {
     /** Flowpaper viewer */
     Route::middleware('login.token')
         ->get('/view/{file:slug}', 'FlowpaperController@view')
-        ->name('flowpaper.view');
+        ->name('flowpaper.view')
+        ->middleware('verified');
+
 
     Route::get('edition/{file:slug}', 'FileController@show');