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

Commit 386770a

Browse files
committed
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 on
1 parent 1b46ab7 commit 386770a

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

src/Signup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class Register extends Signup {
191191
}
192192
}
193193
if (poll_for_success) {
194-
return q.delay(5000).then(function() {
194+
return q.delay(2000).then(function() {
195195
return self._tryRegister(client, authDict, poll_for_success);
196196
});
197197
} else {

src/SignupStages.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,29 @@ DummyStage.TYPE = "m.login.dummy";
5252
class RecaptchaStage extends Stage {
5353
constructor(matrixClient, signupInstance) {
5454
super(RecaptchaStage.TYPE, matrixClient, signupInstance);
55-
this.defer = q.defer(); // resolved with the captcha response
55+
this.authDict = {
56+
auth: {
57+
type: 'm.login.recaptcha',
58+
// we'll add in the response param if we get one from the local user.
59+
},
60+
poll_for_success: true,
61+
};
5662
}
5763

5864
// called when the recaptcha has been completed.
5965
onReceiveData(data) {
6066
if (!data || !data.response) {
6167
return;
6268
}
63-
this.defer.resolve({
64-
auth: {
65-
type: 'm.login.recaptcha',
66-
response: data.response,
67-
}
68-
});
69+
this.authDict.response = data.response;
6970
}
7071

7172
complete() {
72-
return this.defer.promise;
73+
// we return the authDict with no response, telling Signup to keep polling
74+
// the server in case the captcha is filled in on another window (e.g. by
75+
// following a nextlink from an email signup). If the user completes the
76+
// captcha locally, then we return at the next poll.
77+
return q(this.authDict);
7378
}
7479
}
7580
RecaptchaStage.TYPE = "m.login.recaptcha";

src/components/structures/login/Registration.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ module.exports = React.createClass({
273273
if (serverParams && serverParams["m.login.recaptcha"]) {
274274
publicKey = serverParams["m.login.recaptcha"].public_key;
275275
}
276+
276277
registerStep = (
277278
<CaptchaForm sitePublicKey={publicKey}
278279
onCaptchaResponse={this.onCaptchaResponse}

src/components/views/login/CaptchaForm.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,24 @@ module.exports = React.createClass({
5252
this._onCaptchaLoaded();
5353
} else {
5454
console.log("Loading recaptcha script...");
55-
var scriptTag = document.createElement('script');
5655
window.mx_on_recaptcha_loaded = () => {this._onCaptchaLoaded()};
57-
var protocol = global.location.protocol === "file:" ? "https:" : global.location.protocol;
58-
scriptTag.setAttribute(
59-
'src', protocol+"//www.google.com/recaptcha/api.js?onload=mx_on_recaptcha_loaded&render=explicit"
60-
);
61-
this.refs.recaptchaContainer.appendChild(scriptTag);
56+
var protocol = global.location.protocol;
57+
if (protocol === "file:") {
58+
var warning = document.createElement('div');
59+
// XXX: fix hardcoded app URL. Better solutions include:
60+
// * jumping straight to a hosted captcha page (but we don't support that yet)
61+
// * embedding the captcha in an iframe (if that works)
62+
// * using a better captcha lib
63+
warning.innerHTML = "Robot check is currently unavailable on desktop - please sign up <a href='https://riot.im/app'>using a web browser</a>.";
64+
this.refs.recaptchaContainer.appendChild(warning);
65+
}
66+
else {
67+
var scriptTag = document.createElement('script');
68+
scriptTag.setAttribute(
69+
'src', protocol+"//www.google.com/recaptcha/api.js?onload=mx_on_recaptcha_loaded&render=explicit"
70+
);
71+
this.refs.recaptchaContainer.appendChild(scriptTag);
72+
}
6273
}
6374
},
6475

@@ -107,6 +118,7 @@ module.exports = React.createClass({
107118
return (
108119
<div ref="recaptchaContainer">
109120
This Home Server would like to make sure you are not a robot
121+
<br/>
110122
<div id={DIV_ID}></div>
111123
{error}
112124
</div>

0 commit comments

Comments
 (0)