From b4c0625961c3c95302d0cc666e237af7b59eecae Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 18 Nov 2015 15:32:44 +0000 Subject: [PATCH] Show validation errors --- src/components/login/Registration.js | 53 +++++++++++++++------- src/skins/vector/views/pages/MatrixChat.js | 11 +++-- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/components/login/Registration.js b/src/components/login/Registration.js index a1ebe57c..c44d1368 100644 --- a/src/components/login/Registration.js +++ b/src/components/login/Registration.js @@ -22,6 +22,7 @@ var sdk = require('matrix-react-sdk'); var MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg'); var ServerConfig = require("./ServerConfig"); var RegistrationForm = require("./RegistrationForm"); +var MIN_PASSWORD_LENGTH = 6; module.exports = React.createClass({ displayName: 'Registration', @@ -61,7 +62,40 @@ module.exports = React.createClass({ }, onFormValidationFailed: function(errCode) { - console.error("Ruh roh: %s", errCode); + var errMsg; + switch (errCode) { + case "RegistrationForm.ERR_PASSWORD_MISSING": + errMsg = "Missing password."; + break; + case "RegistrationForm.ERR_PASSWORD_MISMATCH": + errMsg = "Passwords don't match."; + break; + case "RegistrationForm.ERR_PASSWORD_LENGTH": + errMsg = `Password too short (min ${MIN_PASSWORD_LENGTH}).`; + break; + default: + console.error("Unknown error code: %s", errCode); + errMsg = "An unknown error occurred."; + break; + } + this.setState({ + errorText: errMsg + }); + }, + + _getPostRegisterJsx: function() { + var ChangeDisplayName = sdk.getComponent('molecules.ChangeDisplayName'); + var ChangeAvatar = sdk.getComponent('molecules.ChangeAvatar'); + return ( +
+ Set a display name: + + Upload an avatar: + + +
+ ); }, _getRegisterContentJsx: function() { @@ -74,7 +108,7 @@ module.exports = React.createClass({ registerStep = ( ); @@ -117,21 +151,6 @@ module.exports = React.createClass({ ); }, - _getPostRegisterJsx: function() { - var ChangeDisplayName = sdk.getComponent('molecules.ChangeDisplayName'); - var ChangeAvatar = sdk.getComponent('molecules.ChangeAvatar'); - return ( -
- Set a display name: - - Upload an avatar: - - -
- ); - }, - render: function() { return (
diff --git a/src/skins/vector/views/pages/MatrixChat.js b/src/skins/vector/views/pages/MatrixChat.js index 51de92a7..85506c21 100644 --- a/src/skins/vector/views/pages/MatrixChat.js +++ b/src/skins/vector/views/pages/MatrixChat.js @@ -176,12 +176,17 @@ module.exports = React.createClass({ /> ); */ return ( + var registerLogic = new Signup.Register( + config.default_hs_url, config.default_is_url + ); + registerLogic.setClientSecret(this.state.register_client_secret); + registerLogic.setSessionId(this.state.register_session_id); + registerLogic.setRegistrationUrl(this.props.registrationUrl); + registerLogic.setIdSid(this.state.register_id_sid); + registerLogic={registerLogic} /> ); } else { return (