Parcourir la source

Added captcha to forms

Samson Mutunga il y a 2 ans
Parent
commit
5949736d2a

+ 11 - 7
.env.example

@@ -1,19 +1,19 @@
-APP_NAME=Laravel
+APP_NAME="Snyder Hemband"
 APP_ENV=local
 APP_KEY=
 APP_DEBUG=true
-APP_URL=http://localhost
+APP_URL=https://snyderhemband.org
 
 LOG_CHANNEL=stack
 LOG_DEPRECATIONS_CHANNEL=null
 LOG_LEVEL=debug
 
-DB_CONNECTION=mysql
+DB_CONNECTION=pgsql
 DB_HOST=127.0.0.1
-DB_PORT=3306
-DB_DATABASE=laravel
-DB_USERNAME=root
-DB_PASSWORD=
+DB_PORT=5432
+DB_DATABASE=hemband
+DB_USERNAME=postgres
+DB_PASSWORD=pass
 
 BROADCAST_DRIVER=log
 CACHE_DRIVER=file
@@ -50,3 +50,7 @@ PUSHER_APP_CLUSTER=mt1
 
 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
 MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
+
+RECAPTCHA_SITE_KEY=6LcdDw8jAAAAAK53nmSD1kU_qr66Yes2XvnGEaSW
+RECAPTCHA_SECRET_KEY=6LcdDw8jAAAAAGf_hRQsoqwuXP46FuNkSektuobv
+RECAPTCHA_SITE=https://www.google.com/recaptcha/admin/

+ 4 - 2
app/Http/Controllers/AppController.php

@@ -46,7 +46,8 @@ class AppController extends Controller
         'name_last' => 'required|string',
         'email' => 'required|email',
         'phone' => 'required|string',
-        'zip' => 'required|string'
+        'zip' => 'required|string',
+        'g-recaptcha-response' => 'required|recaptcha'
       ]);
       
       $record = new PatientFindAClinicRequest;
@@ -70,7 +71,8 @@ class AppController extends Controller
         'phone' => '',
         'zip' => '',
         'subject' => '',
-        'message' => 'required|string'
+        'message' => 'required|string',
+        'g-recaptcha-response' => 'required|recaptcha'
       ]);
       
       $record = new PatientContactMessage;

+ 3 - 0
app/Http/Controllers/PhysiciansController.php

@@ -71,6 +71,7 @@ class PhysiciansController extends Controller
         'zip' => 'required|string',
         'training_type' => 'required|string',
         'training_format' => 'required|string',
+        'g-recaptcha-response' => 'required|recaptcha'
       ]);
 
       $record = new PhysicianTrainingRequest;
@@ -129,6 +130,7 @@ class PhysiciansController extends Controller
         'phone' => 'required|string',
         'zip' => 'required|string',
         'comment' => 'required|string',
+        'g-recaptcha-response' => 'required|recaptcha'
       ]);
 
       $record = new PhysicianDirectoryListingRequest;
@@ -157,6 +159,7 @@ class PhysiciansController extends Controller
         'phone' => 'required|string',
         'zip' => 'required|string',
         'comment' => 'required|string',
+        'g-recaptcha-response' => 'required|recaptcha'
       ]);
 
       $record = new PhysicianMarketingMaterialsRequest;

+ 1 - 0
composer.json

@@ -6,6 +6,7 @@
     "license": "MIT",
     "require": {
         "php": "^7.3|^8.0",
+        "biscolab/laravel-recaptcha": "^5.4",
         "fruitcake/laravel-cors": "^2.0",
         "guzzlehttp/guzzle": "^7.0.1",
         "laravel/framework": "^8.75",

+ 73 - 2
composer.lock

@@ -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": "c61ff82cbf0142a401a48a8161e1595a",
+    "content-hash": "d994c8882a79491311ca56c8b9d912d4",
     "packages": [
         {
             "name": "asm89/stack-cors",
@@ -62,6 +62,77 @@
             },
             "time": "2022-01-18T09:12:03+00:00"
         },
+        {
+            "name": "biscolab/laravel-recaptcha",
+            "version": "v5.4.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/biscolab/laravel-recaptcha.git",
+                "reference": "1bab726402d5376553a439b88a0faa07e84488fd"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/biscolab/laravel-recaptcha/zipball/1bab726402d5376553a439b88a0faa07e84488fd",
+                "reference": "1bab726402d5376553a439b88a0faa07e84488fd",
+                "shasum": ""
+            },
+            "require": {
+                "illuminate/routing": "^7.0|^8.0|^9.0",
+                "illuminate/support": "^7.0|^8.0|^9.0",
+                "php": "^7.3|^8.0"
+            },
+            "require-dev": {
+                "orchestra/testbench": "5.*|6.*|^7.0",
+                "phpunit/phpunit": "^9.1"
+            },
+            "suggest": {
+                "biscolab/laravel-authlog": "It allows to handle logged-in users and force log-out if needed"
+            },
+            "type": "library",
+            "extra": {
+                "laravel": {
+                    "providers": [
+                        "Biscolab\\ReCaptcha\\ReCaptchaServiceProvider"
+                    ],
+                    "aliases": {
+                        "ReCaptcha": "Biscolab\\ReCaptcha\\Facades\\ReCaptcha"
+                    }
+                }
+            },
+            "autoload": {
+                "files": [
+                    "src/helpers.php"
+                ],
+                "psr-4": {
+                    "Biscolab\\ReCaptcha\\": "src/"
+                }
+            },
+            "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 framework",
+            "homepage": "https://biscolab.com/laravel-recaptcha",
+            "keywords": [
+                "captcha",
+                "laravel",
+                "recaptcha",
+                "validation"
+            ],
+            "support": {
+                "issues": "https://github.com/biscolab/laravel-recaptcha/issues",
+                "source": "https://github.com/biscolab/laravel-recaptcha/tree/v5.4.0"
+            },
+            "time": "2022-05-07T12:52:46+00:00"
+        },
         {
             "name": "brick/math",
             "version": "0.9.3",
@@ -7706,5 +7777,5 @@
         "php": "^7.3|^8.0"
     },
     "platform-dev": [],
-    "plugin-api-version": "2.0.0"
+    "plugin-api-version": "2.3.0"
 }

+ 3 - 0
config/app.php

@@ -15,6 +15,9 @@ return [
 
     'name' => env('APP_NAME', 'Laravel'),
 
+    'recaptchaSiteKey' => env('RECAPTCHA_SITE_KEY', ''),
+    'recaptchaSecretKey' => env('RECAPTCHA_SECRET_KEY', ''),
+
     /*
     |--------------------------------------------------------------------------
     | Application Environment

+ 179 - 0
config/recaptcha.php

@@ -0,0 +1,179 @@
+<?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
+     * IP/CIDR netmask eg. 127.0.0.0/24, also 127.0.0.1 is accepted and /32 assumed
+     *
+     */
+    'skip_ip'                      => env('RECAPTCHA_SKIP_IP', []),
+
+    /**
+     *
+     * Default route called to check the Google reCAPTCHA token
+     * @since v3.2.0
+     *
+     */
+    'default_validation_route'     => 'biscolab-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'             => null,
+
+    /**
+     *
+     * The default form ID. Only for "invisible" reCAPTCHA
+     * @since v4.0.0
+     *
+     */
+    'default_form_id'              => 'biscolab-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,
+
+    /**
+     *
+     * Set API domain. You can use "www.recaptcha.net" in case "www.google.com" is not accessible.
+     * (no check will be made on the entered value)
+     * @see   https://developers.google.com/recaptcha/docs/faq#can-i-use-recaptcha-globally
+     * @since v4.3.0
+     * Default 'www.google.com' (ReCaptchaBuilder::DEFAULT_RECAPTCHA_API_DOMAIN)
+     *
+     */
+    'api_domain'                   => 'www.google.com',
+
+    /**
+     *
+     * Set `true` when the error message must be null
+     * @since v5.1.0
+     * Default false
+     *
+     */
+    'empty_message' => false,
+
+    /**
+     *
+     * Set either the error message or the errom message translation key
+     * @since v5.1.0
+     * Default 'validation.recaptcha'
+     *
+     */
+    'error_message_key' => 'validation.recaptcha',
+
+    /**
+     *
+     * 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,
+    ]
+];

+ 6 - 0
resources/views/app/contact.blade.php

@@ -76,6 +76,12 @@
               <small class="text-warning">{{$message}}</small>
             @enderror
         </div>
+        <div class="form-group mb-4">
+            {!! htmlFormSnippet() !!}
+            @error('g-recaptcha-response')
+              <small class="text-danger"><i class="fas fa-exclamation-triangle mr-2"></i>Invalid</small>
+            @enderror
+          </div>
         <button type="submit" class="btn btn-pry w-100 py-3">Submit message</button>
       </form>
     </div>

+ 17 - 9
resources/views/app/find-a-clinic.blade.php

@@ -51,6 +51,18 @@
       <form class="" action="{{ route('submit-find-a-clinic') }}" method="post">
         @csrf
         <div class="row">
+          <div class="col-12">
+            @if($errors->any())
+            <div class="alert alert-danger fade show" role="alert">
+                There were errors found!
+            </div>
+            @endif
+            @if(session('success'))
+            <div class="alert alert-success fade show" role="alert">
+                {{session('success')}}
+            </div>
+            @endif
+          </div>
           <div class="col-lg-6 form-group mb-4">
             <input type="text" class="form-control rounded-0 py-3" name="name_first" placeholder="First Name" value="{{ old('name_first') }}" />
             @error('name_first')
@@ -82,16 +94,12 @@
               <small class="text-warning">{{$message}}</small>
             @enderror
         </div>
-        @if($errors->any())
-        <div class="alert alert-danger fade show" role="alert">
-            There were errors found!
-        </div>
-        @endif
-        @if(session('success'))
-        <div class="alert alert-success fade show" role="alert">
-            {{session('success')}}
+        <div class="form-group mb-4">
+          {!! htmlFormSnippet() !!}
+          @error('g-recaptcha-response')
+            <small class="text-danger"><i class="fas fa-exclamation-triangle mr-2"></i>Invalid</small>
+          @enderror
         </div>
-        @endif
         <button type="submit" class="btn btn-pry w-100 py-3">Submit</button>
       </form>
     </div>

+ 6 - 0
resources/views/app/physicians/contact-us.blade.php

@@ -107,6 +107,12 @@
                 <small class="text-warning">{{$message}}</small>
               @enderror
           </div>
+          <div class="form-group mb-4">
+            {!! htmlFormSnippet() !!}
+            @error('g-recaptcha-response')
+              <small class="text-danger"><i class="fas fa-exclamation-triangle mr-2"></i>Invalid</small>
+            @enderror
+          </div>
           <button type="submit" class="btn btn-pry w-100 py-3">SUBMIT</button>
         </form>
       </div>

+ 6 - 0
resources/views/app/physicians/get-trained.blade.php

@@ -138,6 +138,12 @@
               <small class="text-warning">{{$message}}</small>
             @enderror
         </div>
+        <div class="form-group mb-4">
+            {!! htmlFormSnippet() !!}
+            @error('g-recaptcha-response')
+              <small class="text-danger"><i class="fas fa-exclamation-triangle mr-2"></i>Invalid</small>
+            @enderror
+          </div>
         <button type="submit" class="btn btn-pry w-100 py-3">Submit</button>
       </form>
     </div>

+ 6 - 0
resources/views/app/physicians/order-products/marketing.blade.php

@@ -117,6 +117,12 @@
                 <small class="text-warning">{{$message}}</small>
               @enderror
           </div>
+          <div class="form-group mb-4">
+            {!! htmlFormSnippet() !!}
+            @error('g-recaptcha-response')
+              <small class="text-danger"><i class="fas fa-exclamation-triangle mr-2"></i>Invalid</small>
+            @enderror
+          </div>
           <button type="submit" class="btn btn-pry w-100 py-3">SUBMIT</button>
         </form>
       </div>

+ 6 - 0
resources/views/app/physicians/practice-support/directory-listing.blade.php

@@ -103,6 +103,12 @@
                 <small class="text-warning">{{$message}}</small>
               @enderror
           </div>
+          <div class="form-group mb-4">
+            {!! htmlFormSnippet() !!}
+            @error('g-recaptcha-response')
+              <small class="text-danger"><i class="fas fa-exclamation-triangle mr-2"></i>Invalid</small>
+            @enderror
+          </div>
           <button type="submit" class="btn btn-pry w-100 py-3">SUBMIT</button>
         </form>
       </div>

+ 6 - 0
resources/views/app/physicians/practice-support/training.blade.php

@@ -129,6 +129,12 @@
                 <small class="text-warning">{{$message}}</small>
               @enderror
           </div>
+          <div class="form-group mb-4">
+            {!! htmlFormSnippet() !!}
+            @error('g-recaptcha-response')
+              <small class="text-danger"><i class="fas fa-exclamation-triangle mr-2"></i>Invalid</small>
+            @enderror
+          </div>
           <button type="submit" class="btn btn-pry w-100 py-3">SUBMIT</button>
         </form>
 

+ 1 - 0
resources/views/layouts/base.blade.php

@@ -19,6 +19,7 @@
         $('.phone').mask('(000) 000-0000');
       })
     </script>
+    {!! ReCaptcha::htmlScriptTagJsApi() !!}
 </head>
 
 <body>