Adonis Recaptcha
Installation
To get the latest version of Adonis Recaptcha, simply run
npm install adonis-recaptcha --save
Once Adonis Recaptcha is installed, you need to register the service provider. Open up bootstrap/app.js and add the following to the providers key.
// bootstrap/app.jsconst providers = ... 'adonis-recaptcha/providers/RecaptchaProvider'
You can register the Recaptcha facade in the aliases key of your bootstrap/app.js file if you like.
// bootstrap/app.jsconst aliases = ... Recaptcha: 'Adonis/Addons/Recaptcha'
Enable the recaptcha middleware inside app/Http/kernel.js
file.
// app/Http/kernel.js const namedMiddleware = ... recaptcha: 'Adonis/Middleware/Recaptcha'
Add your site key and secret to your .env file using the following keys:
RECAPTCHA_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
RECAPTCHA_SITE_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
(keys can be generated here https://www.google.com/recaptcha/admin)
Usage
Middleware
Use the recaptcha middleware to require catpcha solution for a given route.
Route
Display Recaptcha Widget
{% set recaptcha = use('Recaptcha') %} <!-- Generate script tag. --> {{ recaptcha.script | safe }} <!-- ... --> <!-- Generate recaptcha field --> {{ recaptcha.field | safe }} Submit <!-- ... -->