From 5424567a66b9a1ecc6a1808abce4bb9d85e0e547 Mon Sep 17 00:00:00 2001 From: Kegan Dougal <kegan@matrix.org> Date: Wed, 18 Nov 2015 17:15:20 +0000 Subject: [PATCH] Hook up onFormSubmit to make registration (dummy only) work again. --- src/components/login/Registration.js | 46 +++++++++++++++++++--- src/skins/vector/views/pages/MatrixChat.js | 12 +++--- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/components/login/Registration.js b/src/components/login/Registration.js index c44d1368..05960c61 100644 --- a/src/components/login/Registration.js +++ b/src/components/login/Registration.js @@ -20,6 +20,7 @@ var React = require('react'); var sdk = require('matrix-react-sdk'); var MatrixClientPeg = require('matrix-react-sdk/lib/MatrixClientPeg'); +var dis = require('matrix-react-sdk/lib/dispatcher'); var ServerConfig = require("./ServerConfig"); var RegistrationForm = require("./RegistrationForm"); var MIN_PASSWORD_LENGTH = 6; @@ -44,7 +45,11 @@ module.exports = React.createClass({ }, componentWillMount: function() { + this.dispatcherRef = dis.register(this.onAction); + }, + componentWillUnmount: function() { + dis.unregister(this.dispatcherRef); }, onHsUrlChanged: function(newHsUrl) { @@ -57,8 +62,38 @@ module.exports = React.createClass({ this.forceUpdate(); // registration state may have changed. }, + onAction: function(payload) { + if (payload.action !== "registration_step_update") { + return; + } + this.forceUpdate(); + }, + onFormSubmit: function(formVals) { - console.log("Form vals: %s", formVals); + var self = this; + this.props.registerLogic.register(formVals).done(function(response) { + if (!response || !response.access_token) { + console.warn( + "FIXME: Register fulfilled without a final response, " + + "did you break the promise chain?" + ); + // no matter, we'll grab it direct + response = self.props.registerLogic.getCredentials(); + } + self.props.onLoggedIn({ + userId: response.user_id, + homeserverUrl: self.props.registerLogic.getHomeserverUrl(), + identityServerUrl: self.props.registerLogic.getIdentityServerUrl(), + accessToken: response.access_token + }); + }, function(err) { + if (err.message) { + self.setState({ + errorText: err.message + }); + } + console.log(err); + }); }, onFormValidationFailed: function(errCode) { @@ -99,12 +134,13 @@ module.exports = React.createClass({ }, _getRegisterContentJsx: function() { - var currState = this.props.registerLogic.getState(); + var currStep = this.props.registerLogic.getStep(); var registerStep; - switch (currState) { + switch (currStep) { case "Register.COMPLETE": return this._getPostRegisterJsx(); case "Register.START": + case "Register.STEP_m.login.dummy": registerStep = ( <RegistrationForm showEmail={true} @@ -129,13 +165,14 @@ module.exports = React.createClass({ ); break; default: - console.error("Unknown register state: %s", currState); + console.error("Unknown register state: %s", currStep); break; } return ( <div> <h2>Create an account</h2> {registerStep} + <div className="mx_Login_error">{this.state.errorText}</div> <ServerConfig ref="serverConfig" withToggleButton={true} defaultHsUrl={this.state.enteredHomeserverUrl} @@ -143,7 +180,6 @@ module.exports = React.createClass({ onHsUrlChanged={this.onHsUrlChanged} onIsUrlChanged={this.onIsUrlChanged} delayTimeMs={1000} /> - <div className="mx_Login_error">{this.state.errorText}</div> <a className="mx_Login_create" onClick={this.props.onLoginClick} href="#"> I already have an account </a> diff --git a/src/skins/vector/views/pages/MatrixChat.js b/src/skins/vector/views/pages/MatrixChat.js index 85506c21..7dafff91 100644 --- a/src/skins/vector/views/pages/MatrixChat.js +++ b/src/skins/vector/views/pages/MatrixChat.js @@ -175,14 +175,14 @@ module.exports = React.createClass({ registrationUrl={this.props.registrationUrl} /> ); */ - return ( - var registerLogic = new Signup.Register( + 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.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); + return ( <Registration onLoggedIn={this.onLoggedIn} onLoginClick={this.onLoginClick}