From 9b6060a3631a2d3559d617c67acbd2742a919e37 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 16 Jul 2015 16:49:40 +0100 Subject: [PATCH] Decouple login view & controller --- skins/base/views/templates/Login.js | 18 ++++++++++++++++++ src/controllers/templates/Login.js | 15 +++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/skins/base/views/templates/Login.js b/skins/base/views/templates/Login.js index 49dd05f5..f71e3070 100644 --- a/skins/base/views/templates/Login.js +++ b/skins/base/views/templates/Login.js @@ -31,6 +31,24 @@ module.exports = React.createClass({ displayName: 'Login', mixins: [LoginController], + getHsUrl: function() { + return this.refs.serverConfig.getHsUrl(); + }, + + getIsUrl: function() { + return this.refs.serverConfig.getIsUrl(); + }, + + /** + * Gets the form field values for the current login stage + */ + getFormVals: function() { + return { + 'username': this.refs.user.getDOMNode().value, + 'password': this.refs.pass.getDOMNode().value + }; + }, + componentForStep: function(step) { switch (step) { case 'choose_hs': diff --git a/src/controllers/templates/Login.js b/src/controllers/templates/Login.js index 2719436e..5543fbcf 100644 --- a/src/controllers/templates/Login.js +++ b/src/controllers/templates/Login.js @@ -41,12 +41,12 @@ module.exports = { onHSChosen: function(ev) { ev.preventDefault(); MatrixClientPeg.replaceUsingUrls( - this.refs.serverConfig.getHsUrl(), - this.refs.serverConfig.getIsUrl() + this.getHsUrl(), + this.getIsUrl() ); this.setState({ - hs_url: this.refs.serverConfig.getHsUrl(), - is_url: this.refs.serverConfig.getIsUrl() + hs_url: this.getHsUrl(), + is_url: this.getIsUrl() }); this.setStep("fetch_stages"); var cli = MatrixClientPeg.get(); @@ -69,9 +69,12 @@ module.exports = { ev.preventDefault(); this.setState({busy: true}); var that = this; + + var formVals = this.getFormVals(); + MatrixClientPeg.get().login('m.login.password', { - 'user': that.refs.user.getDOMNode().value, - 'password': that.refs.pass.getDOMNode().value + 'user': formVals.username, + 'password': formVals.password }).then(function(data) { // XXX: we assume this means we're logged in, but there could be a next stage MatrixClientPeg.replace(Matrix.createClient({