mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-01-10 20:17:32 +01:00
Separate errors for each vm
Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
355468b637
commit
a2677a6400
@ -24,15 +24,22 @@ export class CompleteSSOLoginViewModel extends ViewModel {
|
|||||||
loginToken,
|
loginToken,
|
||||||
sessionContainer,
|
sessionContainer,
|
||||||
attemptLogin,
|
attemptLogin,
|
||||||
showError,
|
|
||||||
} = options;
|
} = options;
|
||||||
this._loginToken = loginToken;
|
this._loginToken = loginToken;
|
||||||
this._sessionContainer = sessionContainer;
|
this._sessionContainer = sessionContainer;
|
||||||
this._attemptLogin = attemptLogin;
|
this._attemptLogin = attemptLogin;
|
||||||
this._showError = showError;
|
this._errorMessage = "";
|
||||||
this.performSSOLoginCompletion();
|
this.performSSOLoginCompletion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get errorMessage() { return this._errorMessage; }
|
||||||
|
|
||||||
|
_showError(message) {
|
||||||
|
this._errorMessage = message;
|
||||||
|
this.emitChange("errorMessage");
|
||||||
|
this._errorMessage = "";
|
||||||
|
}
|
||||||
|
|
||||||
async performSSOLoginCompletion() {
|
async performSSOLoginCompletion() {
|
||||||
if (!this._loginToken) {
|
if (!this._loginToken) {
|
||||||
return;
|
return;
|
||||||
|
@ -20,21 +20,28 @@ import {LoginFailure} from "../../matrix/SessionContainer.js";
|
|||||||
export class PasswordLoginViewModel extends ViewModel {
|
export class PasswordLoginViewModel extends ViewModel {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
const {loginOptions, homeserver, attemptLogin, showError} = options;
|
const {loginOptions, homeserver, attemptLogin} = options;
|
||||||
this._loginOptions = loginOptions;
|
this._loginOptions = loginOptions;
|
||||||
this._attemptLogin = attemptLogin;
|
this._attemptLogin = attemptLogin;
|
||||||
this._showError = showError;
|
|
||||||
this._homeserver = homeserver;
|
this._homeserver = homeserver;
|
||||||
this._isBusy = false;
|
this._isBusy = false;
|
||||||
|
this._errorMessage = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
get isBusy() { return this._isBusy; }
|
get isBusy() { return this._isBusy; }
|
||||||
|
get errorMessage() { return this._errorMessage; }
|
||||||
|
|
||||||
toggleBusy(state) {
|
toggleBusy(state) {
|
||||||
this._isBusy = state;
|
this._isBusy = state;
|
||||||
this.emitChange("isBusy");
|
this.emitChange("isBusy");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_showError(message) {
|
||||||
|
this._errorMessage = message;
|
||||||
|
this.emitChange("errorMessage");
|
||||||
|
this._errorMessage = "";
|
||||||
|
}
|
||||||
|
|
||||||
async login(username, password) {
|
async login(username, password) {
|
||||||
const status = await this._attemptLogin(this._loginOptions.password(username, password));
|
const status = await this._attemptLogin(this._loginOptions.password(username, password));
|
||||||
let error = "";
|
let error = "";
|
||||||
|
@ -22,7 +22,8 @@ export class CompleteSSOView extends TemplateView {
|
|||||||
return t.div({ className: "CompleteSSOView" },
|
return t.div({ className: "CompleteSSOView" },
|
||||||
[
|
[
|
||||||
t.p({ className: "CompleteSSOView_title" }, "Finishing up your SSO Login"),
|
t.p({ className: "CompleteSSOView_title" }, "Finishing up your SSO Login"),
|
||||||
t.mapView(vm => vm.loadViewModel, loadViewModel => loadViewModel ? new SessionLoadStatusView(loadViewModel) : null)
|
t.if(vm => vm.errorMessage, (t, vm) => t.p({className: "CompleteSSOView_error"}, vm.i18n(vm.errorMessage))),
|
||||||
|
t.mapView(vm => vm.loadViewModel, loadViewModel => loadViewModel ? new SessionLoadStatusView(loadViewModel) : null),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ export class LoginView extends TemplateView {
|
|||||||
t.mapView(vm => vm.completeSSOLoginViewModel, vm => vm ? new CompleteSSOView(vm) : null),
|
t.mapView(vm => vm.completeSSOLoginViewModel, vm => vm ? new CompleteSSOView(vm) : null),
|
||||||
t.if(vm => vm.showHomeserver, (t, vm) => t.div({ className: "LoginView_sso form form-row" },
|
t.if(vm => vm.showHomeserver, (t, vm) => t.div({ className: "LoginView_sso form form-row" },
|
||||||
[
|
[
|
||||||
|
t.if(vm => vm.errorMessage, (t, vm) => t.p({className: "LoginView_error"}, vm.i18n(vm.errorMessage))),
|
||||||
t.label({for: "homeserver"}, vm.i18n`Homeserver`),
|
t.label({for: "homeserver"}, vm.i18n`Homeserver`),
|
||||||
t.input({
|
t.input({
|
||||||
id: "homeserver",
|
id: "homeserver",
|
||||||
@ -43,7 +44,6 @@ export class LoginView extends TemplateView {
|
|||||||
t.mapView(vm => vm.passwordLoginViewModel, vm => vm ? new PasswordLoginView(vm): null),
|
t.mapView(vm => vm.passwordLoginViewModel, vm => vm ? new PasswordLoginView(vm): null),
|
||||||
t.if(vm => vm.passwordLoginViewModel && vm.startSSOLoginViewModel, t => t.p({className: "LoginView_separator"}, vm.i18n`or`)),
|
t.if(vm => vm.passwordLoginViewModel && vm.startSSOLoginViewModel, t => t.p({className: "LoginView_separator"}, vm.i18n`or`)),
|
||||||
t.mapView(vm => vm.startSSOLoginViewModel, vm => vm ? new StartSSOLoginView(vm) : null),
|
t.mapView(vm => vm.startSSOLoginViewModel, vm => vm ? new StartSSOLoginView(vm) : null),
|
||||||
t.if(vm => vm.errorMessage, (t, vm) => t.p({className: "LoginView_error"}, vm.i18n(vm.errorMessage))),
|
|
||||||
t.mapView(vm => vm.loadViewModel, loadViewModel => loadViewModel ? new SessionLoadStatusView(loadViewModel) : null),
|
t.mapView(vm => vm.loadViewModel, loadViewModel => loadViewModel ? new SessionLoadStatusView(loadViewModel) : null),
|
||||||
// use t.mapView rather than t.if to create a new view when the view model changes too
|
// use t.mapView rather than t.if to create a new view when the view model changes too
|
||||||
t.p(hydrogenGithubLink(t))
|
t.p(hydrogenGithubLink(t))
|
||||||
|
@ -40,6 +40,7 @@ export class PasswordLoginView extends TemplateView {
|
|||||||
vm.login(username.value, password.value);
|
vm.login(username.value, password.value);
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
|
t.if(vm => vm.errorMessage, (t, vm) => t.p({className: "PasswordLoginView_error"}, vm.i18n(vm.errorMessage))),
|
||||||
t.div({ className: "form-row" }, [t.label({ for: "username" }, vm.i18n`Username`), username]),
|
t.div({ className: "form-row" }, [t.label({ for: "username" }, vm.i18n`Username`), username]),
|
||||||
t.div({ className: "form-row" }, [t.label({ for: "password" }, vm.i18n`Password`), password]),
|
t.div({ className: "form-row" }, [t.label({ for: "password" }, vm.i18n`Password`), password]),
|
||||||
t.div({ className: "button-row" }, [
|
t.div({ className: "button-row" }, [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user