Last active
November 29, 2017 01:39
-
-
Save jdanyow/231c18eec8be2fa96169 to your computer and use it in GitHub Desktop.
Google reCAPTCHA with Aurelia
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
<template> | |
<require from="./recaptcha"></require> | |
<form action="?" method="POST"> | |
<recaptcha theme="light" verified.call="onVerified($event)"></recaptcha> | |
<recaptcha theme="dark" verified.call="onVerified($event)"></recaptcha> | |
<br> | |
<input type="submit" value="Submit"> | |
</form> | |
</template> |
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
export class App { | |
message = 'hello world'; | |
onVerified(response) { | |
alert(response); | |
} | |
} |
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
<!doctype html> | |
<html> | |
<head> | |
<title>Aurelia</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script> | |
<script> | |
System.import('aurelia-bootstrapper'); | |
</script> | |
</body> | |
</html> |
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
import {inject, noView, bindable} from 'aurelia-framework'; | |
const recaptchaCallbackName = 'setRecaptchaReady'; | |
const ready = new Promise(resolve => window[recaptchaCallbackName] = resolve); | |
// https://developers.google.com/recaptcha/docs/display#explicit_render | |
let script = document.createElement('script'); | |
script.src = `https://www.google.com/recaptcha/api.js?onload=${recaptchaCallbackName}&render=explicit`; | |
script.async = true; | |
script.defer = true; | |
document.head.appendChild(script); | |
const sitekey = '6LfwTRkTAAAAAKl5YtVOgNVsENf5TysXLJaZjIen'; | |
@noView() | |
@inject(Element) | |
export class Recaptcha { | |
@bindable verified; | |
@bindable theme = 'light'; | |
constructor(element) { | |
this.element = element; | |
} | |
attached() { | |
ready.then(() => grecaptcha.render(this.element, { | |
sitekey: sitekey, | |
theme: this.theme, | |
callback: this.verified | |
})); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment