Create registration stage in Registration itself
This commit is contained in:
parent
e66549a067
commit
22d5505a2b
2 changed files with 15 additions and 37 deletions
|
@ -15,14 +15,16 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type {HomeServerApi} from "../net/HomeServerApi";
|
import type {HomeServerApi} from "../net/HomeServerApi";
|
||||||
import {registrationStageFromType} from "./registrationStageFromType";
|
|
||||||
import type {BaseRegistrationStage} from "./stages/BaseRegistrationStage";
|
import type {BaseRegistrationStage} from "./stages/BaseRegistrationStage";
|
||||||
|
import {DummyAuth} from "./stages/DummyAuth";
|
||||||
|
import {TermsAuth} from "./stages/TermsAuth";
|
||||||
import type {
|
import type {
|
||||||
AccountDetails,
|
AccountDetails,
|
||||||
RegistrationFlow,
|
RegistrationFlow,
|
||||||
RegistrationResponseMoreDataNeeded,
|
RegistrationResponseMoreDataNeeded,
|
||||||
RegistrationResponse,
|
RegistrationResponse,
|
||||||
RegistrationResponseSuccess,
|
RegistrationResponseSuccess,
|
||||||
|
RegistrationParams,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
type FlowSelector = (flows: RegistrationFlow[]) => RegistrationFlow | void;
|
type FlowSelector = (flows: RegistrationFlow[]) => RegistrationFlow | void;
|
||||||
|
@ -73,11 +75,7 @@ export class Registration {
|
||||||
let firstStage: BaseRegistrationStage | undefined;
|
let firstStage: BaseRegistrationStage | undefined;
|
||||||
let lastStage: BaseRegistrationStage;
|
let lastStage: BaseRegistrationStage;
|
||||||
for (const stage of flow.stages) {
|
for (const stage of flow.stages) {
|
||||||
const stageClass = registrationStageFromType(stage);
|
const registrationStage = this._createRegistrationStage(stage, session, params);
|
||||||
if (!stageClass) {
|
|
||||||
throw new Error(`Unknown stage: ${stage}`);
|
|
||||||
}
|
|
||||||
const registrationStage = new stageClass(session, params?.[stage]);
|
|
||||||
if (!firstStage) {
|
if (!firstStage) {
|
||||||
firstStage = registrationStage;
|
firstStage = registrationStage;
|
||||||
lastStage = registrationStage;
|
lastStage = registrationStage;
|
||||||
|
@ -104,6 +102,17 @@ export class Registration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _createRegistrationStage(type: string, session: string, params?: RegistrationParams) {
|
||||||
|
switch (type) {
|
||||||
|
case "m.login.dummy":
|
||||||
|
return new DummyAuth(session, params);
|
||||||
|
case "m.login.terms":
|
||||||
|
return new TermsAuth(session, params);
|
||||||
|
default:
|
||||||
|
throw new Error(`Unknown stage: ${type}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get sessionInfo(): RegistrationResponseSuccess | undefined {
|
get sessionInfo(): RegistrationResponseSuccess | undefined {
|
||||||
return this._sessionInfo;
|
return this._sessionInfo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright 2021 The Matrix.org Foundation C.I.C.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import type {BaseRegistrationStage} from "./stages/BaseRegistrationStage";
|
|
||||||
import type {RegistrationParams} from "./types";
|
|
||||||
import {DummyAuth} from "./stages/DummyAuth";
|
|
||||||
import {TermsAuth} from "./stages/TermsAuth";
|
|
||||||
|
|
||||||
type ClassDerivedFromBaseRegistration = { new(session: string, params?: RegistrationParams): BaseRegistrationStage } & typeof BaseRegistrationStage;
|
|
||||||
|
|
||||||
export function registrationStageFromType(type: string): ClassDerivedFromBaseRegistration | undefined{
|
|
||||||
switch (type) {
|
|
||||||
case "m.login.dummy":
|
|
||||||
return DummyAuth;
|
|
||||||
case "m.login.terms":
|
|
||||||
return TermsAuth;
|
|
||||||
}
|
|
||||||
}
|
|
Reference in a new issue