mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Move normalizeHomeserver into session container
Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
c4e7dc3b5a
commit
7b9ec5516a
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
import {ViewModel} from "../ViewModel.js";
|
import {ViewModel} from "../ViewModel.js";
|
||||||
import {PasswordLoginViewModel} from "./PasswordLoginViewModel.js";
|
import {PasswordLoginViewModel} from "./PasswordLoginViewModel.js";
|
||||||
import {StartSSOLoginViewModel} from "./StartSSOLoginViewModel.js";
|
import {StartSSOLoginViewModel} from "./StartSSOLoginViewModel.js";
|
||||||
import {normalizeHomeserver} from "./common.js";
|
|
||||||
import {CompleteSSOLoginViewModel} from "./CompleteSSOLoginViewModel.js";
|
import {CompleteSSOLoginViewModel} from "./CompleteSSOLoginViewModel.js";
|
||||||
|
|
||||||
export class LoginViewModel extends ViewModel {
|
export class LoginViewModel extends ViewModel {
|
||||||
@ -46,10 +45,9 @@ export class LoginViewModel extends ViewModel {
|
|||||||
this.emitChange("completeSSOLoginViewModel");
|
this.emitChange("completeSSOLoginViewModel");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const defaultHomeServer = normalizeHomeserver(this._defaultHomeServer);
|
await this.queryLogin(this._defaultHomeServer);
|
||||||
await this.queryLogin(defaultHomeServer);
|
|
||||||
this._showPasswordLogin();
|
this._showPasswordLogin();
|
||||||
this._showSSOLogin(defaultHomeServer);
|
this._showSSOLogin(this._defaultHomeServer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,9 +78,8 @@ export class LoginViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _onHomeServerChange(homeserver) {
|
async _onHomeServerChange(homeserver) {
|
||||||
const normalizedHS = normalizeHomeserver(homeserver);
|
await this.queryLogin(homeserver);
|
||||||
await this.queryLogin(normalizedHS);
|
this._showSSOLogin(homeserver);
|
||||||
this._showSSOLogin(normalizedHS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
childOptions(options) {
|
childOptions(options) {
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
import {ViewModel} from "../ViewModel.js";
|
import {ViewModel} from "../ViewModel.js";
|
||||||
import {SessionLoadViewModel} from "../SessionLoadViewModel.js";
|
import {SessionLoadViewModel} from "../SessionLoadViewModel.js";
|
||||||
import {ObservableValue} from "../../observable/ObservableValue.js";
|
import {ObservableValue} from "../../observable/ObservableValue.js";
|
||||||
import {normalizeHomeserver} from "./common.js";
|
|
||||||
|
|
||||||
export class PasswordLoginViewModel extends ViewModel {
|
export class PasswordLoginViewModel extends ViewModel {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
@ -50,7 +49,6 @@ export class PasswordLoginViewModel extends ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async login(username, password, homeserver) {
|
async login(username, password, homeserver) {
|
||||||
homeserver = normalizeHomeserver(homeserver);
|
|
||||||
this._loadViewModelSubscription = this.disposeTracked(this._loadViewModelSubscription);
|
this._loadViewModelSubscription = this.disposeTracked(this._loadViewModelSubscription);
|
||||||
if (this._loadViewModel) {
|
if (this._loadViewModel) {
|
||||||
this._loadViewModel = this.disposeTracked(this._loadViewModel);
|
this._loadViewModel = this.disposeTracked(this._loadViewModel);
|
||||||
|
@ -1,23 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export function normalizeHomeserver(homeServer) {
|
|
||||||
try {
|
|
||||||
return new URL(homeServer).origin;
|
|
||||||
} catch (err) {
|
|
||||||
return new URL(`https://${homeServer}`).origin;
|
|
||||||
}
|
|
||||||
}
|
|
@ -27,6 +27,14 @@ import {PasswordLoginMethod} from "./login/PasswordLoginMethod.js";
|
|||||||
import {TokenLoginMethod} from "./login/TokenLoginMethod.js";
|
import {TokenLoginMethod} from "./login/TokenLoginMethod.js";
|
||||||
import {SSOLoginHelper} from "./login/SSOLoginHelper.js";
|
import {SSOLoginHelper} from "./login/SSOLoginHelper.js";
|
||||||
|
|
||||||
|
function normalizeHomeserver(homeServer) {
|
||||||
|
try {
|
||||||
|
return new URL(homeServer).origin;
|
||||||
|
} catch (err) {
|
||||||
|
return new URL(`https://${homeServer}`).origin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const LoadStatus = createEnum(
|
export const LoadStatus = createEnum(
|
||||||
"NotLoading",
|
"NotLoading",
|
||||||
"Login",
|
"Login",
|
||||||
@ -114,9 +122,10 @@ export class SessionContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async queryLogin(homeServer) {
|
async queryLogin(homeServer) {
|
||||||
const hsApi = new HomeServerApi({homeServer, request: this._platform.request});
|
const normalizedHS = normalizeHomeserver(homeServer);
|
||||||
|
const hsApi = new HomeServerApi({homeServer: normalizedHS, request: this._platform.request});
|
||||||
const response = await hsApi.queryLogin().response();
|
const response = await hsApi.queryLogin().response();
|
||||||
return this.parseLoginOptions(response, homeServer);
|
return this.parseLoginOptions(response, normalizedHS);
|
||||||
}
|
}
|
||||||
|
|
||||||
async startWithLogin(loginMethod) {
|
async startWithLogin(loginMethod) {
|
||||||
|
Loading…
Reference in New Issue
Block a user