diff --git a/components/Login.js b/components/Login.js index aaa1bd9..225e9d8 100644 --- a/components/Login.js +++ b/components/Login.js @@ -18,12 +18,21 @@ let login = create({ pass: "", hs: "" }, - promptHS: false + hs: { + prompt: false, + error: null, + valid: false + } } }, login: function() { this.setState({error: ""}) + + if (this.state.hs.valid) { + return this.doLogin() + } + let parts = this.state.formState.user.split(':') if (parts.length != 2) { return this.setState({error: "Please enter a full mxid, like username:homeserver.tld"}) @@ -35,17 +44,19 @@ let login = create({ let formState = this.state.formState formState.user = parts[0] formState.hs = hs - this.setState({apiUrl: hs, formState: formState}) + let hsState = Object.assign(this.state.hs, {valid: true}) + this.setState({apiUrl: hs, formState: formState, hs: hsState}) this.doLogin() }).catch((error) => { - console.log("LOGIN ERROR", error) - this.setState({error: error}) + console.log("ERROR fetching homeserver url", error) + let hsState = Object.assign(this.state.hs, {error: error, valid: false}) + this.setState({hs: hsState}) }) }, doLogin: function() { console.log("Logging in") - let user = this.state.formState.user + let user = this.state.formState.user.replace('@', '') let password = this.state.formState.pass let hs = this.state.apiUrl @@ -86,6 +97,8 @@ let login = create({ let parts = user.split(':') if (parts.length == 2) { formState.hs = parts[1] + let hsState = Object.assign(this.state.hs, {error: null, valid: false}) + this.setState({hs: hsState}) } this.setState({formState: formState}) }, @@ -103,28 +116,35 @@ let login = create({ }, render: function() { - let hsActive = "inactive" - if (this.state.promptHS) { - hsActive = "active" + let hsState = "inactive" + if (this.state.hs.prompt) { + hsState = "active" } + if (this.state.hs.error != null) { + hsState = "error" + } + if (this.state.hs.valid) { + hsState = "validated" + } + return (