|
|
@ -18,12 +18,21 @@ let login = create({
|
|
|
|
pass: "",
|
|
|
|
pass: "",
|
|
|
|
hs: ""
|
|
|
|
hs: ""
|
|
|
|
},
|
|
|
|
},
|
|
|
|
promptHS: false
|
|
|
|
hs: {
|
|
|
|
|
|
|
|
prompt: false,
|
|
|
|
|
|
|
|
error: null,
|
|
|
|
|
|
|
|
valid: false
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
login: function() {
|
|
|
|
login: function() {
|
|
|
|
this.setState({error: ""})
|
|
|
|
this.setState({error: ""})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.state.hs.valid) {
|
|
|
|
|
|
|
|
return this.doLogin()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let parts = this.state.formState.user.split(':')
|
|
|
|
let parts = this.state.formState.user.split(':')
|
|
|
|
if (parts.length != 2) {
|
|
|
|
if (parts.length != 2) {
|
|
|
|
return this.setState({error: "Please enter a full mxid, like username:homeserver.tld"})
|
|
|
|
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
|
|
|
|
let formState = this.state.formState
|
|
|
|
formState.user = parts[0]
|
|
|
|
formState.user = parts[0]
|
|
|
|
formState.hs = hs
|
|
|
|
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()
|
|
|
|
this.doLogin()
|
|
|
|
}).catch((error) => {
|
|
|
|
}).catch((error) => {
|
|
|
|
console.log("LOGIN ERROR", error)
|
|
|
|
console.log("ERROR fetching homeserver url", error)
|
|
|
|
this.setState({error: error})
|
|
|
|
let hsState = Object.assign(this.state.hs, {error: error, valid: false})
|
|
|
|
|
|
|
|
this.setState({hs: hsState})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
doLogin: function() {
|
|
|
|
doLogin: function() {
|
|
|
|
console.log("Logging in")
|
|
|
|
console.log("Logging in")
|
|
|
|
let user = this.state.formState.user
|
|
|
|
let user = this.state.formState.user.replace('@', '')
|
|
|
|
let password = this.state.formState.pass
|
|
|
|
let password = this.state.formState.pass
|
|
|
|
let hs = this.state.apiUrl
|
|
|
|
let hs = this.state.apiUrl
|
|
|
|
|
|
|
|
|
|
|
@ -86,6 +97,8 @@ let login = create({
|
|
|
|
let parts = user.split(':')
|
|
|
|
let parts = user.split(':')
|
|
|
|
if (parts.length == 2) {
|
|
|
|
if (parts.length == 2) {
|
|
|
|
formState.hs = parts[1]
|
|
|
|
formState.hs = parts[1]
|
|
|
|
|
|
|
|
let hsState = Object.assign(this.state.hs, {error: null, valid: false})
|
|
|
|
|
|
|
|
this.setState({hs: hsState})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.setState({formState: formState})
|
|
|
|
this.setState({formState: formState})
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -103,28 +116,35 @@ let login = create({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
render: function() {
|
|
|
|
let hsActive = "inactive"
|
|
|
|
let hsState = "inactive"
|
|
|
|
if (this.state.promptHS) {
|
|
|
|
if (this.state.hs.prompt) {
|
|
|
|
hsActive = "active"
|
|
|
|
hsState = "active"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.hs.error != null) {
|
|
|
|
|
|
|
|
hsState = "error"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.hs.valid) {
|
|
|
|
|
|
|
|
hsState = "validated"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className="loginwrapper">
|
|
|
|
<div className="loginwrapper">
|
|
|
|
<img src="./neo.png"/>
|
|
|
|
<img src="./neo.png"/>
|
|
|
|
<div className="error">{this.state.error != null && this.state.error}</div>
|
|
|
|
<div className="errorMessage">{this.state.error}</div>
|
|
|
|
<div className="login">
|
|
|
|
<div className="login">
|
|
|
|
<label htmlFor="user">Username: </label>
|
|
|
|
<label htmlFor="user">Username: </label>
|
|
|
|
<input type="text" id="user" placeholder="username" value={this.state.formState["user"]} onChange={this.handleUserChange}/>
|
|
|
|
<input type="text" id="user" placeholder="@user:homeserver.tld" value={this.state.formState["user"]} onChange={this.handleUserChange}/>
|
|
|
|
|
|
|
|
|
|
|
|
<label htmlFor="pass">Password: </label>
|
|
|
|
<label htmlFor="pass">Password: </label>
|
|
|
|
<input type="password" id="pass" value={this.state.formState["pass"]} onChange={this.handlePassChange}/>
|
|
|
|
<input type="password" id="pass" placeholder="password" value={this.state.formState["pass"]} onChange={this.handlePassChange}/>
|
|
|
|
|
|
|
|
|
|
|
|
<label htmlFor="hs" className={hsActive}>Homeserver: </label>
|
|
|
|
<label htmlFor="hs" className={hsState}>Homeserver: </label>
|
|
|
|
{this.state.promptHS ? (
|
|
|
|
{this.state.hs.prompt ? (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<input type="text" id="hs" placeholder="https://lain.haus" value={this.state.formState["hs"]} onChange={this.handleHsChange}/>
|
|
|
|
<input type="text" id="hs" placeholder="https://lain.haus" value={this.state.formState["hs"]} onChange={this.handleHsChange}/>
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
) : (
|
|
|
|
<span>{this.state.formState["hs"]}</span>
|
|
|
|
<span id="hs">{this.state.formState["hs"]}</span>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<button onClick={()=>this.login()}>Log in</button>
|
|
|
|
<button onClick={()=>this.login()}>Log in</button>
|
|
|
|