port login fixes

pull/21833/head
David Baker 2015-09-21 16:36:17 +01:00
parent 28c4a648be
commit 65498600de
1 changed files with 37 additions and 21 deletions

View File

@ -33,57 +33,73 @@ module.exports = {
}, },
setStep: function(step) { setStep: function(step) {
this.setState({ step: step, errorText: '', busy: false }); this.setState({ step: step, busy: false });
}, },
onHSChosen: function(ev) { onHSChosen: function() {
ev.preventDefault();
MatrixClientPeg.replaceUsingUrls( MatrixClientPeg.replaceUsingUrls(
this.getHsUrl(), this.getHsUrl(),
this.getIsUrl() this.getIsUrl()
); );
this.setState({ this.setState({
hs_url: this.getHsUrl(), hs_url: this.getHsUrl(),
is_url: this.getIsUrl() is_url: this.getIsUrl(),
}); });
this.setStep("fetch_stages"); this.setStep("fetch_stages");
var cli = MatrixClientPeg.get(); var cli = MatrixClientPeg.get();
this.setState({busy: true}); this.setState({
var that = this; busy: true,
errorText: "",
});
var self = this;
cli.loginFlows().done(function(result) { cli.loginFlows().done(function(result) {
that.setState({ self.setState({
flows: result.flows, flows: result.flows,
currentStep: 1, currentStep: 1,
totalSteps: result.flows.length+1 totalSteps: result.flows.length+1
}); });
that.setStep('stage_'+result.flows[0].type); self.setStep('stage_'+result.flows[0].type);
}, function(error) { }, function(error) {
that.setStep("choose_hs"); self.setStep("choose_hs");
that.setState({errorText: 'Unable to contact the given Home Server'}); self.setState({errorText: 'Unable to contact the given Home Server'});
}); });
}, },
onUserPassEntered: function(ev) { onUserPassEntered: function(ev) {
ev.preventDefault(); ev.preventDefault();
this.setState({busy: true}); this.setState({
var that = this; busy: true,
errorText: "",
});
var self = this;
var formVals = this.getFormVals(); var formVals = this.getFormVals();
MatrixClientPeg.get().login('m.login.password', { var loginParams = {
'user': formVals.username, password: formVals.password
'password': formVals.password };
}).done(function(data) { if (formVals.username.indexOf('@') > 0) {
loginParams.medium = 'email';
loginParams.address = formVals.username;
} else {
loginParams.user = formVals.username;
}
MatrixClientPeg.get().login('m.login.password', loginParams).done(function(data) {
MatrixClientPeg.replaceUsingAccessToken( MatrixClientPeg.replaceUsingAccessToken(
that.state.hs_url, that.state.is_url, self.state.hs_url, self.state.is_url,
data.user_id, data.access_token data.user_id, data.access_token
); );
if (that.props.onLoggedIn) { if (self.props.onLoggedIn) {
that.props.onLoggedIn(); self.props.onLoggedIn();
} }
}, function(error) { }, function(error) {
that.setStep("stage_m.login.password"); self.setStep("stage_m.login.password");
that.setState({errorText: 'Login failed.'}); if (error.httpStatus == 400 && loginParams.medium) {
self.setState({errorText: 'This Home Server does not support login using email address.'});
} else {
self.setState({errorText: 'Login failed.'});
}
}); });
}, },