Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1106 from matrix-org/dbkr/reset_captcha_on_unmount
Browse files Browse the repository at this point in the history
Make sure captcha disappears when container does
  • Loading branch information
dbkr authored Jun 16, 2017
2 parents 56eb71d + 2a01e63 commit 3b23fc7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/components/views/login/CaptchaForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ module.exports = React.createClass({
};
},

componentWillMount: function() {
this._captchaWidgetId = null;
},

componentDidMount: function() {
// Just putting a script tag into the returned jsx doesn't work, annoyingly,
// so we do this instead.
Expand Down Expand Up @@ -75,6 +79,10 @@ module.exports = React.createClass({
}
},

componentWillUnmount: function() {
this._resetRecaptcha();
},

_renderRecaptcha: function(divId) {
if (!global.grecaptcha) {
console.error("grecaptcha not loaded!");
Expand All @@ -90,12 +98,18 @@ module.exports = React.createClass({
}

console.log("Rendering to %s", divId);
global.grecaptcha.render(divId, {
this._captchaWidgetId = global.grecaptcha.render(divId, {
sitekey: publicKey,
callback: this.props.onCaptchaResponse,
});
},

_resetRecaptcha: function() {
if (this._captchaWidgetId !== null) {
global.grecaptcha.reset(this._captchaWidgetId);
}
},

_onCaptchaLoaded: function() {
console.log("Loaded recaptcha script.");
try {
Expand Down

0 comments on commit 3b23fc7

Please sign in to comment.