-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from rtCamp/feature/recaptcha-google
Google reCAPTCHA demo
- Loading branch information
Showing
5 changed files
with
70 additions
and
0 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
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,54 @@ | ||
<%- include(commonPath + '/header.ejs') %> | ||
|
||
<%- include(commonPath + '/internal-page/header.ejs', {containerType: 'sm'}) %> | ||
<div id="status-message" class="text-center font-bold text-lg my-4"></div> | ||
<form action="?" method="POST" id="captcha-form" class="flex justify-between" > | ||
<div id="html_element"></div> | ||
<input | ||
type="submit" | ||
value="Send" | ||
disabled | ||
class="px-4 py-2 bg-gray-100 text-white rounded transition duration-300 cursor-not-allowed" /> | ||
</form> | ||
<%- include(commonPath + '/internal-page/footer.ejs') %> | ||
<script type="text/javascript"> | ||
const statusMessage = document.getElementById('status-message'); | ||
const captchaForm = document.getElementById('captcha-form'); | ||
const sendButton = captchaForm.querySelector('input[type="submit"]') | ||
const verifyCallback = (response) => { | ||
console.log(response); | ||
if (response) { | ||
statusMessage.textContent = `captcha verified`; | ||
sendButton.removeAttribute('disabled'); | ||
sendButton.classList.remove('cursor-not-allowed'); | ||
sendButton.classList.remove('bg-gray-100'); | ||
sendButton.classList.add('bg-blue-500'); | ||
} | ||
}; | ||
const errorCallback = (error) => { | ||
console.log('error'); | ||
if (error) { | ||
statusMessage.textContent = `captcha error`; | ||
} | ||
}; | ||
captchaForm.onsubmit = (event) => { | ||
event.preventDefault(); | ||
const token = grecaptcha.getResponse(); | ||
statusMessage.textContent = `form submitted, captcha token ${token}`; | ||
} | ||
window.onloadCallback = function() { | ||
grecaptcha.render('html_element', { | ||
'sitekey' : '<%= recaptchaSiteKey %>', | ||
'callback' : verifyCallback, | ||
'error-callback' : errorCallback | ||
}); | ||
}; | ||
</script> | ||
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" | ||
async defer> | ||
</script> | ||
<%- include(commonPath + '/footer.ejs') %> |
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,12 @@ | ||
const express = require('express'); | ||
const path = require('path'); | ||
const router = express.Router(); | ||
|
||
router.get('/', (req, res) => { | ||
// Send the default page | ||
res.render(path.join(__dirname,'index'), { | ||
title: 'Google reCAPTCHA' | ||
}); | ||
}); | ||
|
||
module.exports = router; |