Fixes to login, and change to not use the dispatcher because it's just unnecessary here

This commit is contained in:
David Baker 2015-06-12 13:45:22 +01:00
parent e28fde7ae1
commit ffb0dc78b8
4 changed files with 22 additions and 9 deletions

View File

@ -7,5 +7,6 @@
text-align: center;
background-color: #eee;
border: 1px solid black;
position: relative;
}

View File

@ -14,6 +14,7 @@ if (localStorage) {
accessToken: access_token,
userId: user_id
});
matrixClient.startClient();
}
}

View File

@ -7,24 +7,27 @@ var Login = require('../templates/Login');
var mxCliPeg = require("../MatrixClientPeg");
var dis = require("../dispatcher");
//var dis = require("../dispatcher");
module.exports = React.createClass({
getInitialState: function() {
return {
logged_in: !!mxCliPeg.get().credentials
logged_in: !!(mxCliPeg.get() && mxCliPeg.get().credentials)
};
},
componentWillMount: function() {
/*componentWillMount: function() {
var that = this;
this.dispatcherRef = dis.register(function(payload) {
switch(payload.action) {
case 'logged_in':
that.setState({logged_in: true});
break;
}
});
},*/
onLoggedIn: function() {
this.setState({logged_in: true});
},
render: function() {
@ -37,7 +40,7 @@ module.exports = React.createClass({
);
} else {
return (
<Login />
<Login onLoggedIn={this.onLoggedIn} />
);
}
}

View File

@ -6,7 +6,7 @@ var ServerConfig = require("../molecules/ServerConfig");
var ProgressBar = require("../molecules/ProgressBar");
var Loader = require("react-loader");
var dis = require("../dispatcher");
//var dis = require("../dispatcher");
module.exports = React.createClass({
getInitialState: function() {
@ -19,7 +19,7 @@ module.exports = React.createClass({
},
setStep: function(step) {
this.setState({ step: step, errorText: '' });
this.setState({ step: step, errorText: '', busy: false });
},
onHSChosen: function(ev) {
@ -50,6 +50,11 @@ module.exports = React.createClass({
'password': that.refs.pass.getDOMNode().value
}).then(function(data) {
// XXX: we assume this means we're logged in, but there could be a next stage
MatrixClientPeg.replace(Matrix.createClient({
baseUrl: that.state.hs_url,
userId: data.user_id,
accessToken: data.access_token
}));
var localStorage = window.localStorage;
if (localStorage) {
localStorage.setItem("mx_hs_url", that.state.hs_url);
@ -58,9 +63,12 @@ module.exports = React.createClass({
} else {
console.warn("No local storage available: can't persist session!");
}
dis.dispatch({
if (that.props.onLoggedIn) {
that.props.onLoggedIn();
}
/*dis.dispatch({
'action': 'logged_in'
});
});*/
}, function(error) {
that.setStep("stage_m.login.password");
that.setState({errorText: 'Login failed.'});