Call through to password login

This commit is contained in:
Kegan Dougal 2015-11-12 15:16:29 +00:00
parent 05eda88ea2
commit 8826eb60cc
2 changed files with 28 additions and 4 deletions

View File

@ -32,7 +32,8 @@ module.exports = React.createClass({displayName: 'PasswordLogin',
}; };
}, },
onSubmitForm: function() { onSubmitForm: function(ev) {
ev.preventDefault();
this.props.onSubmit(this.state.username, this.state.password); this.props.onSubmit(this.state.username, this.state.password);
}, },

View File

@ -54,15 +54,30 @@ module.exports = React.createClass({displayName: 'LoginPage',
}, },
onPasswordLogin: function(username, password) { onPasswordLogin: function(username, password) {
// TODO var self = this;
console.log("onPasswordLogin %s %s", username, password); self.setState({
busy: true
});
this._loginLogic.loginViaPassword(username, password).then(function(data) {
self.props.onLoggedIn(data);
}, function(error) {
self._setErrorTextFromError(error);
}).finally(function() {
self.setState({
busy: false
});
});
}, },
onHsUrlChanged: function(newHsUrl) { onHsUrlChanged: function(newHsUrl) {
console.log("onHsUrlChanged %s", newHsUrl);
this._initLoginLogic(newHsUrl); this._initLoginLogic(newHsUrl);
}, },
onIsUrlChanged: function(newIsUrl) {
this._initLoginLogic(null, newIsUrl);
},
_initLoginLogic: function(hsUrl, isUrl) { _initLoginLogic: function(hsUrl, isUrl) {
var self = this; var self = this;
hsUrl = hsUrl || this.state.enteredHomeserverUrl; hsUrl = hsUrl || this.state.enteredHomeserverUrl;
@ -97,6 +112,13 @@ module.exports = React.createClass({displayName: 'LoginPage',
}, },
_setErrorTextFromError: function(err) { _setErrorTextFromError: function(err) {
if (err.friendlyText) {
this.setState({
errorText: err.friendlyText
});
return;
}
var errCode = err.errcode; var errCode = err.errcode;
if (!errCode && err.httpStatus) { if (!errCode && err.httpStatus) {
errCode = "HTTP " + err.httpStatus; errCode = "HTTP " + err.httpStatus;
@ -153,6 +175,7 @@ module.exports = React.createClass({displayName: 'LoginPage',
defaultHsUrl={this.props.homeserverUrl} defaultHsUrl={this.props.homeserverUrl}
defaultIsUrl={this.props.identityServerUrl} defaultIsUrl={this.props.identityServerUrl}
onHsUrlChanged={this.onHsUrlChanged} onHsUrlChanged={this.onHsUrlChanged}
onIsUrlChanged={this.onIsUrlChanged}
delayTimeMs={1000}/> delayTimeMs={1000}/>
<div className="mx_Login_error"> <div className="mx_Login_error">
{ loader } { loader }