-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use PascalCase for component registration This allows both `<Recaptcha>` and `<recaptcha>` to be used in templates. Components that are registered in PascalCase can be used in templates with either PascalCase or kebab-case, whereas components registered in kebab-case can only be referenced in kebab-case. Some projects prefer to use PascalCase for component tags, so it's better for this plugin to make both options available. See https://vuejs.org/v2/guide/components-registration.html#Name-Casing * update plugin.js for global use * Moved script element error callback to within promise so that the error can be caught further up the stack * Reset ready state after error * docs: remove david badge * docs: add usage (#74) Co-authored-by: Sébastien Chopin <seb@nuxtjs.com> * feat(multi-widget): render and verify multiple v2 widgets (#75) * feat(language): enable google auto detection (#72) Co-authored-by: Sébastien Chopin <seb@nuxtjs.com> * fix: describe error within execute() (#40) Co-authored-by: Abdelhak Akermi <abdelhak@akermi.me> * feat: runtime config (#70) Co-authored-by: Sébastien Chopin <seb@nuxtjs.com> Co-authored-by: Nikolay Baskov <baskov@adv.ru> * fix: remove badge on destroy (#76) * Apply suggestions from code review Co-authored-by: Simon Garner <simon.garner@madscience.co.nz> Co-authored-by: mvrlin <mvrlin@pm.me> Co-authored-by: lat1992 <lat1992@users.noreply.github.com> Co-authored-by: Owen Andrews <owen@owenandre.ws> Co-authored-by: Sébastien Chopin <seb@nuxtjs.com> Co-authored-by: Red Bayoub <40964509+redbayoub@users.noreply.github.com> Co-authored-by: Abdelhak Akermi <abdelhak.akermi@gmail.com> Co-authored-by: Abdelhak Akermi <abdelhak@akermi.me> Co-authored-by: bason8800 <41577602+bason8800@users.noreply.github.com> Co-authored-by: Nikolay Baskov <baskov@adv.ru>
- Loading branch information
1 parent
fc6c496
commit 4a3e3f2
Showing
11 changed files
with
4,044 additions
and
1,315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { resolve } = require('path') | ||
|
||
module.exports = { | ||
buildDir: resolve(__dirname, '.nuxt'), | ||
|
||
modules: [ | ||
['../../lib/module', { | ||
hideBadge: true, | ||
siteKey: '6LeE3ZAUAAAAANVaDO60w4ZBK44khqO7OpsitZNY', | ||
|
||
version: 3, | ||
}] | ||
], | ||
|
||
srcDir: __dirname, | ||
|
||
render: { resourceHints: false }, | ||
rootDir: resolve(__dirname, '..') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<template> | ||
<section class="index-page"> | ||
<h2>Sign In</h2> | ||
|
||
<form @submit.prevent="onSubmit"> | ||
<input | ||
v-model="email" | ||
autocomplete="true" | ||
placeholder="Email" | ||
type="email" | ||
> | ||
|
||
<input | ||
v-model="password" | ||
autocomplete="current-password" | ||
placeholder="Password" | ||
type="password" | ||
> | ||
<recaptcha | ||
id="v2-normal" | ||
site-key="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI" | ||
/> | ||
<button type="submit"> | ||
Sign In | ||
</button> | ||
</form> | ||
</section> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data: () => ({ | ||
email: 'test@example.com', | ||
password: '123', | ||
widgetId: 0 | ||
}), | ||
async mounted() { | ||
await this.$recaptcha.init() | ||
this.widgetId = this.$recaptcha.render('v2-normal', { | ||
sitekey: '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI' | ||
}) | ||
}, | ||
methods: { | ||
async onSubmit() { | ||
try { | ||
const tokenV2 = await this.$recaptcha.getResponse(this.widgetId) | ||
console.log('V2 ReCaptcha token:', tokenV2) | ||
const token = await this.$recaptcha.execute('login') | ||
console.log('V3 ReCaptcha token:', token) | ||
this.$recaptcha.reset(this.widgetId) | ||
} catch (error) { | ||
console.log('Login error:', error) | ||
} | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useBody } from 'h3' | ||
import { $fetch } from 'ohmyfetch/node' | ||
|
||
/** | ||
* It is highly recommended to use enviroment variables instead of hardcoded secrets. | ||
*/ | ||
const SECRET_KEY = '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe' | ||
|
||
/** | ||
* This is an example that demonstrates how verifying reCAPTCHA on the server side works. | ||
* Do not use this middleware in your production. | ||
*/ | ||
export default async (req, res) => { | ||
res.setHeader('Content-Type', 'application/json') | ||
try { | ||
const { token } = await useBody(req) | ||
|
||
if (!token) { | ||
res.end(JSON.stringify({ | ||
success: false, | ||
message: 'Invalid token' | ||
})) | ||
return | ||
} | ||
const response = await $fetch( | ||
`https://www.google.com/recaptcha/api/siteverify?secret=${SECRET_KEY}&response=${token}` | ||
) | ||
|
||
if (response.success) { | ||
res.end(JSON.stringify({ | ||
success: true, | ||
message: 'Token verifyed', | ||
response: response | ||
})) | ||
} else { | ||
res.end(JSON.stringify({ | ||
success: false, | ||
message: 'Invalid token', | ||
response: response | ||
})) | ||
} | ||
} catch (e) { | ||
console.log('ReCaptcha error:', e) | ||
res.end(JSON.stringify({ | ||
success: false, | ||
message: 'Internal error' | ||
})) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.