diff --git a/src/domain/login/CompleteSSOLoginViewModel.js b/src/domain/login/CompleteSSOLoginViewModel.js index 1fed0b41..9bdb0509 100644 --- a/src/domain/login/CompleteSSOLoginViewModel.js +++ b/src/domain/login/CompleteSSOLoginViewModel.js @@ -24,15 +24,22 @@ export class CompleteSSOLoginViewModel extends ViewModel { loginToken, sessionContainer, attemptLogin, - showError, } = options; this._loginToken = loginToken; this._sessionContainer = sessionContainer; this._attemptLogin = attemptLogin; - this._showError = showError; + this._errorMessage = ""; this.performSSOLoginCompletion(); } + get errorMessage() { return this._errorMessage; } + + _showError(message) { + this._errorMessage = message; + this.emitChange("errorMessage"); + this._errorMessage = ""; + } + async performSSOLoginCompletion() { if (!this._loginToken) { return; diff --git a/src/domain/login/PasswordLoginViewModel.js b/src/domain/login/PasswordLoginViewModel.js index d23cda4a..3524779e 100644 --- a/src/domain/login/PasswordLoginViewModel.js +++ b/src/domain/login/PasswordLoginViewModel.js @@ -20,21 +20,28 @@ import {LoginFailure} from "../../matrix/SessionContainer.js"; export class PasswordLoginViewModel extends ViewModel { constructor(options) { super(options); - const {loginOptions, homeserver, attemptLogin, showError} = options; + const {loginOptions, homeserver, attemptLogin} = options; this._loginOptions = loginOptions; this._attemptLogin = attemptLogin; - this._showError = showError; this._homeserver = homeserver; this._isBusy = false; + this._errorMessage = ""; } get isBusy() { return this._isBusy; } + get errorMessage() { return this._errorMessage; } toggleBusy(state) { this._isBusy = state; this.emitChange("isBusy"); } + _showError(message) { + this._errorMessage = message; + this.emitChange("errorMessage"); + this._errorMessage = ""; + } + async login(username, password) { const status = await this._attemptLogin(this._loginOptions.password(username, password)); let error = ""; diff --git a/src/platform/web/ui/login/CompleteSSOView.js b/src/platform/web/ui/login/CompleteSSOView.js index cece7184..8b0654c6 100644 --- a/src/platform/web/ui/login/CompleteSSOView.js +++ b/src/platform/web/ui/login/CompleteSSOView.js @@ -22,7 +22,8 @@ export class CompleteSSOView extends TemplateView { return t.div({ className: "CompleteSSOView" }, [ 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), ] ); } diff --git a/src/platform/web/ui/login/LoginView.js b/src/platform/web/ui/login/LoginView.js index 7672a719..1dcbde3d 100644 --- a/src/platform/web/ui/login/LoginView.js +++ b/src/platform/web/ui/login/LoginView.js @@ -29,6 +29,7 @@ export class LoginView extends TemplateView { 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.errorMessage, (t, vm) => t.p({className: "LoginView_error"}, vm.i18n(vm.errorMessage))), t.label({for: "homeserver"}, vm.i18n`Homeserver`), t.input({ id: "homeserver", @@ -43,7 +44,6 @@ export class LoginView extends TemplateView { 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.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), // use t.mapView rather than t.if to create a new view when the view model changes too t.p(hydrogenGithubLink(t)) diff --git a/src/platform/web/ui/login/PasswordLoginView.js b/src/platform/web/ui/login/PasswordLoginView.js index ca26d1cc..7fd7d534 100644 --- a/src/platform/web/ui/login/PasswordLoginView.js +++ b/src/platform/web/ui/login/PasswordLoginView.js @@ -40,6 +40,7 @@ export class PasswordLoginView extends TemplateView { 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: "password" }, vm.i18n`Password`), password]), t.div({ className: "button-row" }, [