diff --git a/src/Signup.js b/src/Signup.js index 0107075f9c..02a59ebe6e 100644 --- a/src/Signup.js +++ b/src/Signup.js @@ -6,6 +6,10 @@ var q = require("q"); const EMAIL_STAGE_TYPE = "m.login.email.identity"; +/** + * A base class for common functionality between Registration and Login e.g. + * storage of HS/IS URLs. + */ class Signup { constructor(hsUrl, isUrl) { this._hsUrl = hsUrl; @@ -29,13 +33,16 @@ class Signup { } } - +/** + * Registration logic class + */ class Register extends Signup { constructor(hsUrl, isUrl) { super(hsUrl, isUrl); this.setStep("START"); this.data = null; // from the server - this.params = {}; // random other stuff (e.g. query params, NOT params from the server) + // random other stuff (e.g. query params, NOT params from the server) + this.params = {}; this.credentials = null; this.activeStage = null; this.registrationPromise = null; @@ -104,12 +111,12 @@ class Register extends Signup { this._hsUrl, this._isUrl ); - console.log("register(formVals)"); + console.log("Starting registration process (form submission)"); return this._tryRegister(); } _tryRegister(authDict) { - console.log("_tryRegister %s", JSON.stringify(authDict)); + console.log("Trying to register with auth dict: %s", JSON.stringify(authDict)); var self = this; return MatrixClientPeg.get().register( this.username, this.password, this.params.sessionId, authDict @@ -163,6 +170,11 @@ class Register extends Signup { } } + hasCompletedStage(stageType) { + var completed = (this.data || {}).completed || []; + return completed.indexOf(stageType) !== -1; + } + startStage(stageName) { var self = this; this.setStep(`STEP_${stageName}`); @@ -175,8 +187,8 @@ class Register extends Signup { var stage = new StageClass(MatrixClientPeg.get(), this); this.activeStage = stage; return stage.complete().then(function(request) { - console.log("Stage %s completed with %s", stageName, JSON.stringify(request)); if (request.auth) { + console.log("Stage %s is returning an auth dict", stageName); return self._tryRegister(request.auth); } else { @@ -189,11 +201,6 @@ class Register extends Signup { }); } - hasCompletedStage(stageType) { - var completed = (this.data || {}).completed || []; - return completed.indexOf(stageType) !== -1; - } - chooseFlow(flows) { // If the user gave us an email then we want to pick an email // flow we can do, else any other flow. @@ -248,7 +255,6 @@ class Register extends Signup { ); if (this.params.hasEmailInfo) { - console.log("recheckState has email info.. starting email info.."); this.registrationPromise = this.startStage(EMAIL_STAGE_TYPE); } return this.registrationPromise; diff --git a/src/SignupStages.js b/src/SignupStages.js index 2a63ae6058..272a955d95 100644 --- a/src/SignupStages.js +++ b/src/SignupStages.js @@ -1,6 +1,9 @@ "use strict"; var q = require("q"); +/** + * An interface class which login types should abide by. + */ class Stage { constructor(type, matrixClient, signupInstance) { this.type = type; @@ -24,6 +27,9 @@ class Stage { Stage.TYPE = "NOT IMPLEMENTED"; +/** + * This stage requires no auth. + */ class DummyStage extends Stage { constructor(matrixClient, signupInstance) { super(DummyStage.TYPE, matrixClient, signupInstance); @@ -40,17 +46,24 @@ class DummyStage extends Stage { DummyStage.TYPE = "m.login.dummy"; +/** + * This stage uses Google's Recaptcha to do auth. + */ class RecaptchaStage extends Stage { constructor(matrixClient, signupInstance) { super(RecaptchaStage.TYPE, matrixClient, signupInstance); - this.defer = q.defer(); - this.publicKey = null; + this.defer = q.defer(); // resolved with the captcha response + this.publicKey = null; // from the HS + this.divId = null; // from the UI component } + // called when the UI component has loaded the recaptcha