ask electron users to do captchas in a web browser.
This will happen anyway when they follow email verification links. make captchas poll for success so if they are completed elsewhere, electron moves onpull/21833/head
parent
1b46ab7a80
commit
386770a22a
|
@ -191,7 +191,7 @@ class Register extends Signup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (poll_for_success) {
|
if (poll_for_success) {
|
||||||
return q.delay(5000).then(function() {
|
return q.delay(2000).then(function() {
|
||||||
return self._tryRegister(client, authDict, poll_for_success);
|
return self._tryRegister(client, authDict, poll_for_success);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -52,7 +52,13 @@ DummyStage.TYPE = "m.login.dummy";
|
||||||
class RecaptchaStage extends Stage {
|
class RecaptchaStage extends Stage {
|
||||||
constructor(matrixClient, signupInstance) {
|
constructor(matrixClient, signupInstance) {
|
||||||
super(RecaptchaStage.TYPE, matrixClient, signupInstance);
|
super(RecaptchaStage.TYPE, matrixClient, signupInstance);
|
||||||
this.defer = q.defer(); // resolved with the captcha response
|
this.authDict = {
|
||||||
|
auth: {
|
||||||
|
type: 'm.login.recaptcha',
|
||||||
|
// we'll add in the response param if we get one from the local user.
|
||||||
|
},
|
||||||
|
poll_for_success: true,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// called when the recaptcha has been completed.
|
// called when the recaptcha has been completed.
|
||||||
|
@ -60,16 +66,15 @@ class RecaptchaStage extends Stage {
|
||||||
if (!data || !data.response) {
|
if (!data || !data.response) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.defer.resolve({
|
this.authDict.response = data.response;
|
||||||
auth: {
|
|
||||||
type: 'm.login.recaptcha',
|
|
||||||
response: data.response,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
complete() {
|
complete() {
|
||||||
return this.defer.promise;
|
// we return the authDict with no response, telling Signup to keep polling
|
||||||
|
// the server in case the captcha is filled in on another window (e.g. by
|
||||||
|
// following a nextlink from an email signup). If the user completes the
|
||||||
|
// captcha locally, then we return at the next poll.
|
||||||
|
return q(this.authDict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RecaptchaStage.TYPE = "m.login.recaptcha";
|
RecaptchaStage.TYPE = "m.login.recaptcha";
|
||||||
|
|
|
@ -273,6 +273,7 @@ module.exports = React.createClass({
|
||||||
if (serverParams && serverParams["m.login.recaptcha"]) {
|
if (serverParams && serverParams["m.login.recaptcha"]) {
|
||||||
publicKey = serverParams["m.login.recaptcha"].public_key;
|
publicKey = serverParams["m.login.recaptcha"].public_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
registerStep = (
|
registerStep = (
|
||||||
<CaptchaForm sitePublicKey={publicKey}
|
<CaptchaForm sitePublicKey={publicKey}
|
||||||
onCaptchaResponse={this.onCaptchaResponse}
|
onCaptchaResponse={this.onCaptchaResponse}
|
||||||
|
|
|
@ -52,13 +52,24 @@ module.exports = React.createClass({
|
||||||
this._onCaptchaLoaded();
|
this._onCaptchaLoaded();
|
||||||
} else {
|
} else {
|
||||||
console.log("Loading recaptcha script...");
|
console.log("Loading recaptcha script...");
|
||||||
var scriptTag = document.createElement('script');
|
|
||||||
window.mx_on_recaptcha_loaded = () => {this._onCaptchaLoaded()};
|
window.mx_on_recaptcha_loaded = () => {this._onCaptchaLoaded()};
|
||||||
var protocol = global.location.protocol === "file:" ? "https:" : global.location.protocol;
|
var protocol = global.location.protocol;
|
||||||
scriptTag.setAttribute(
|
if (protocol === "file:") {
|
||||||
'src', protocol+"//www.google.com/recaptcha/api.js?onload=mx_on_recaptcha_loaded&render=explicit"
|
var warning = document.createElement('div');
|
||||||
);
|
// XXX: fix hardcoded app URL. Better solutions include:
|
||||||
this.refs.recaptchaContainer.appendChild(scriptTag);
|
// * jumping straight to a hosted captcha page (but we don't support that yet)
|
||||||
|
// * embedding the captcha in an iframe (if that works)
|
||||||
|
// * using a better captcha lib
|
||||||
|
warning.innerHTML = "Robot check is currently unavailable on desktop - please sign up <a href='https://riot.im/app'>using a web browser</a>.";
|
||||||
|
this.refs.recaptchaContainer.appendChild(warning);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var scriptTag = document.createElement('script');
|
||||||
|
scriptTag.setAttribute(
|
||||||
|
'src', protocol+"//www.google.com/recaptcha/api.js?onload=mx_on_recaptcha_loaded&render=explicit"
|
||||||
|
);
|
||||||
|
this.refs.recaptchaContainer.appendChild(scriptTag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -107,6 +118,7 @@ module.exports = React.createClass({
|
||||||
return (
|
return (
|
||||||
<div ref="recaptchaContainer">
|
<div ref="recaptchaContainer">
|
||||||
This Home Server would like to make sure you are not a robot
|
This Home Server would like to make sure you are not a robot
|
||||||
|
<br/>
|
||||||
<div id={DIV_ID}></div>
|
<div id={DIV_ID}></div>
|
||||||
{error}
|
{error}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue