diff --git a/skins/base/views/templates/Login.js b/skins/base/views/templates/Login.js index ceae07ec4..49dd05f5f 100644 --- a/skins/base/views/templates/Login.js +++ b/skins/base/views/templates/Login.js @@ -25,10 +25,37 @@ var Loader = require("react-loader"); var LoginController = require("../../../../src/controllers/templates/Login"); +var ServerConfig = ComponentBroker.get("molecules/ServerConfig"); + module.exports = React.createClass({ displayName: 'Login', mixins: [LoginController], + componentForStep: function(step) { + switch (step) { + case 'choose_hs': + return ( +
+
+ + + +
+ ); + // XXX: clearly these should be separate organisms + case 'stage_m.login.password': + return ( +
+
+
+
+ +
+
+ ); + } + }, + loginContent: function() { if (this.state.busy) { return ( diff --git a/skins/base/views/templates/Register.js b/skins/base/views/templates/Register.js index 676fa2e27..2a61fa2e9 100644 --- a/skins/base/views/templates/Register.js +++ b/skins/base/views/templates/Register.js @@ -24,10 +24,61 @@ var Loader = require("react-loader"); var RegisterController = require("../../../../src/controllers/templates/Register"); +var ServerConfig = ComponentBroker.get("molecules/ServerConfig"); + module.exports = React.createClass({ displayName: 'Register', mixins: [RegisterController], + getRegFormVals: function() { + return { + email: this.refs.email.getDOMNode().value, + username: this.refs.username.getDOMNode().value, + password: this.refs.password.getDOMNode().value, + confirmPassword: this.refs.confirmPassword.getDOMNode().value + }; + }, + + getHsUrl: function() { + return this.refs.serverConfig.getHsUrl(); + }, + + getIsUrl: function() { + return this.refs.serverConfig.getIsUrl(); + }, + + componentForStep: function(step) { + switch (step) { + case 'initial': + return ( +
+
+ Email:
+ Username:
+ Password:
+ Confirm Password:
+ + + +
+ ); + // XXX: clearly these should be separate organisms + case 'stage_m.login.email.identity': + return ( +
+ Please check your email to continue registration. +
+ ); + case 'stage_m.login.recaptcha': + return ( +
+ This Home Server would like to make sure you're not a robot +
+
+ ); + } + }, + registerContent: function() { if (this.state.busy) { return ( @@ -45,6 +96,22 @@ module.exports = React.createClass({ } }, + onBadFields: function(bad) { + var keys = Object.keys(bad); + var strings = []; + for (var i = 0; i < keys.length; ++i) { + switch (bad[keys[i]]) { + case this.FieldErrors.PasswordMismatch: + strings.push("Passwords don't match"); + break; + } + } + var errtxt = strings.join(', '); + this.setState({ + errorText: errtxt + }); + }, + render: function() { return (
diff --git a/src/controllers/pages/MatrixChat.js b/src/controllers/pages/MatrixChat.js index dd8594bbe..248b2c553 100644 --- a/src/controllers/pages/MatrixChat.js +++ b/src/controllers/pages/MatrixChat.js @@ -197,7 +197,7 @@ module.exports = { dis.dispatch({action: 'focus_composer'}); }, - showScreen(screen, params) { + showScreen: function(screen, params) { if (screen == 'register') { dis.dispatch({ action: 'start_registration', diff --git a/src/controllers/templates/Login.js b/src/controllers/templates/Login.js index 714fb2720..1c0559708 100644 --- a/src/controllers/templates/Login.js +++ b/src/controllers/templates/Login.js @@ -24,8 +24,6 @@ var dis = require("../../dispatcher"); var ComponentBroker = require("../../ComponentBroker"); -var ServerConfig = ComponentBroker.get("molecules/ServerConfig"); - module.exports = { getInitialState: function() { return { @@ -100,31 +98,6 @@ module.exports = { }); }, - componentForStep: function(step) { - switch (step) { - case 'choose_hs': - return ( -
-
- - - -
- ); - // XXX: clearly these should be separate organisms - case 'stage_m.login.password': - return ( -
-
-
-
- -
-
- ); - } - }, - showRegister: function(ev) { ev.preventDefault(); dis.dispatch({ diff --git a/src/controllers/templates/Register.js b/src/controllers/templates/Register.js index 650fdd6b2..4ad66d9f2 100644 --- a/src/controllers/templates/Register.js +++ b/src/controllers/templates/Register.js @@ -24,9 +24,12 @@ var dis = require("../../dispatcher"); var ComponentBroker = require("../../ComponentBroker"); -var ServerConfig = ComponentBroker.get("molecules/ServerConfig"); - module.exports = { + FieldErrors: { + PasswordMismatch: 'PasswordMismatch', + PasswordLength: 'PasswordLength' + }, + getInitialState: function() { return { step: 'initial', @@ -126,7 +129,7 @@ module.exports = { if ( this.savedParams.email != '' || - this.completedStages.indexOf('m.login.email.identity' > -1) + this.completedStages.indexOf('m.login.email.identity') > -1 ) { return emailFlow; } else { @@ -156,22 +159,34 @@ module.exports = { onInitialStageSubmit: function(ev) { ev.preventDefault(); + + var formVals = this.getRegFormVals(); + + var badFields = {}; + if (formVals.password != formVals.confirmPassword) { + badFields.confirmPassword = this.FieldErrors.PasswordMismatch; + } + if (formVals.password.length < 6) { + badFields.password = this.FieldErrors.PasswordLength; + } + this.onBadFields(badFields); + 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() }); var cli = MatrixClientPeg.get(); this.setState({busy: true}); var self = this; this.savedParams = { - email: this.refs.email.getDOMNode().value, - username: this.refs.username.getDOMNode().value, - password: this.refs.password.getDOMNode().value + email: formVals.email, + username: formVals.username, + password: formVals.password }; this.tryRegister(); @@ -246,37 +261,6 @@ module.exports = { } }, - componentForStep: function(step) { - switch (step) { - case 'initial': - return ( -
-
- Email:
- Username:
- Password:
- - - -
- ); - // XXX: clearly these should be separate organisms - case 'stage_m.login.email.identity': - return ( -
- Please check your email to continue registration. -
- ); - case 'stage_m.login.recaptcha': - return ( -
- This Home Server would like to make sure you're not a robot -
-
- ); - } - }, - onCaptchaLoaded: function() { if (this.refs.recaptchaContainer) { var sitekey = this.authParams['m.login.recaptcha'].public_key; @@ -308,7 +292,7 @@ module.exports = { self.authParams = error.data.params; self.authSessionId = error.data.session; - self.completedStages = error.data.completed; + self.completedStages = error.data.completed || []; var flow = self.chooseFlow(error.data.flows);