mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 19:56:47 +03:00
Poll for email validation once the validation email has been sent, and continue with the registration process if/when it succeeds.
Fixes https://github.com/vector-im/vector-web/issues/1027 Requires https://github.com/matrix-org/synapse/pull/650 and https://github.com/matrix-org/synapse/pull/649
This commit is contained in:
parent
81674684bb
commit
c9ad3705d9
2 changed files with 35 additions and 20 deletions
|
@ -118,7 +118,7 @@ class Register extends Signup {
|
|||
return this._tryRegister();
|
||||
}
|
||||
|
||||
_tryRegister(authDict) {
|
||||
_tryRegister(authDict, poll_for_success) {
|
||||
var self = this;
|
||||
|
||||
var bindEmail;
|
||||
|
@ -137,25 +137,32 @@ class Register extends Signup {
|
|||
self.setStep("COMPLETE");
|
||||
return result; // contains the credentials
|
||||
}, function(error) {
|
||||
if (error.httpStatus === 401 && error.data && error.data.flows) {
|
||||
if (error.httpStatus === 401) {
|
||||
if (error.data && error.data.flows) {
|
||||
self.params.sessionId = error.data.session;
|
||||
self.data = error.data || {};
|
||||
var flow = self.chooseFlow(error.data.flows);
|
||||
|
||||
if (flow) {
|
||||
console.log("Active flow => %s", JSON.stringify(flow));
|
||||
var flowStage = self.firstUncompletedStage(flow);
|
||||
if (flowStage != self.activeStage) {
|
||||
return self.startStage(flowStage);
|
||||
}
|
||||
else {
|
||||
throw new Error("Unable to register - missing email address?");
|
||||
}
|
||||
}
|
||||
if (poll_for_success) {
|
||||
return q.delay(5000).then(function() {
|
||||
return self._tryRegister(authDict, poll_for_success);
|
||||
});
|
||||
} else {
|
||||
throw new Error("Authorisation failed!");
|
||||
}
|
||||
} else {
|
||||
if (error.errcode === 'M_USER_IN_USE') {
|
||||
throw new Error("Username in use");
|
||||
} else if (error.errcode == 'M_INVALID_USERNAME') {
|
||||
throw new Error("User names may only contain alphanumeric characters, underscores or dots!");
|
||||
} else if (error.httpStatus == 401) {
|
||||
throw new Error("Authorisation failed!");
|
||||
} else if (error.httpStatus >= 400 && error.httpStatus < 500) {
|
||||
throw new Error(`Registration failed! (${error.httpStatus})`);
|
||||
} else if (error.httpStatus >= 500 && error.httpStatus < 600) {
|
||||
|
@ -200,7 +207,7 @@ class Register extends Signup {
|
|||
return stage.complete().then(function(request) {
|
||||
if (request.auth) {
|
||||
console.log("Stage %s is returning an auth dict", stageName);
|
||||
return self._tryRegister(request.auth);
|
||||
return self._tryRegister(request.auth, request.poll_for_success);
|
||||
}
|
||||
else {
|
||||
// never resolve the promise chain. This is for things like email auth
|
||||
|
|
|
@ -130,12 +130,15 @@ class EmailIdentityStage extends Stage {
|
|||
var isLocation = document.createElement('a');
|
||||
isLocation.href = this.signupInstance.getIdentityServerUrl();
|
||||
|
||||
var clientSecret = this.clientSecret || this.signupInstance.params.clientSecret;
|
||||
var sid = this.sid || this.signupInstance.params.idSid;
|
||||
|
||||
return q({
|
||||
auth: {
|
||||
type: 'm.login.email.identity',
|
||||
threepid_creds: {
|
||||
sid: this.signupInstance.params.idSid,
|
||||
client_secret: this.signupInstance.params.clientSecret,
|
||||
sid: sid,
|
||||
client_secret: clientSecret,
|
||||
id_server: isLocation.host
|
||||
}
|
||||
}
|
||||
|
@ -155,10 +158,10 @@ class EmailIdentityStage extends Stage {
|
|||
return this._completeVerify();
|
||||
}
|
||||
|
||||
var clientSecret = this.client.generateClientSecret();
|
||||
this.clientSecret = this.client.generateClientSecret();
|
||||
var nextLink = this.signupInstance.params.registrationUrl +
|
||||
'?client_secret=' +
|
||||
encodeURIComponent(clientSecret) +
|
||||
encodeURIComponent(this.clientSecret) +
|
||||
"&hs_url=" +
|
||||
encodeURIComponent(this.signupInstance.getHomeserverUrl()) +
|
||||
"&is_url=" +
|
||||
|
@ -166,13 +169,18 @@ class EmailIdentityStage extends Stage {
|
|||
"&session_id=" +
|
||||
encodeURIComponent(this.signupInstance.getServerData().session);
|
||||
|
||||
var self = this;
|
||||
return this.client.requestEmailToken(
|
||||
this.signupInstance.email,
|
||||
clientSecret,
|
||||
this.clientSecret,
|
||||
1, // TODO: Multiple send attempts?
|
||||
nextLink
|
||||
).then(function(response) {
|
||||
return {}; // don't want to make a request
|
||||
self.sid = response.sid;
|
||||
return self._completeVerify();
|
||||
}).then(function(request) {
|
||||
request.poll_for_success = true;
|
||||
return request;
|
||||
}, function(error) {
|
||||
console.error(error);
|
||||
var e = {
|
||||
|
|
Loading…
Reference in a new issue