From 23fc4417e82d06883e314b06d724f9e7a9c206c1 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 29 Jan 2019 12:09:07 -0600 Subject: [PATCH] Wire up server type selector, similar to login flow --- .../structures/auth/Registration.js | 204 +++++++++++++----- 1 file changed, 150 insertions(+), 54 deletions(-) diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index a78720dcfa..e761ac74b0 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -23,13 +23,22 @@ import React from 'react'; import PropTypes from 'prop-types'; import sdk from '../../../index'; -import RegistrationForm from '../../views/auth/RegistrationForm'; import { _t, _td } from '../../../languageHandler'; import SdkConfig from '../../../SdkConfig'; import { messageForResourceLimitError } from '../../../utils/ErrorUtils'; +import * as ServerType from '../../views/auth/ServerTypeSelector'; const MIN_PASSWORD_LENGTH = 6; +// Phases +// Show controls to configure server details +const PHASE_SERVER_DETAILS = 0; +// Show the appropriate registration flow(s) for the server +const PHASE_REGISTRATION = 1; + +// Enable phases for registration +const PHASES_ENABLED = true; + module.exports = React.createClass({ displayName: 'Registration', @@ -82,6 +91,7 @@ module.exports = React.createClass({ // If we've been given a session ID, we're resuming // straight back into UI auth doingUIAuth: Boolean(this.props.sessionId), + serverType: null, hsUrl: this.props.customHsUrl, isUrl: this.props.customIsUrl, flows: null, @@ -107,6 +117,39 @@ module.exports = React.createClass({ }); }, + onServerTypeChange(type) { + this.setState({ + serverType: type, + }); + + // When changing server types, set the HS / IS URLs to reasonable defaults for the + // the new type. + switch (type) { + case ServerType.FREE: { + const { hsUrl, isUrl } = ServerType.TYPES.FREE; + this.onServerConfigChange({ + hsUrl, + isUrl, + }); + // Move directly to the registration phase since the server details are fixed. + this.setState({ + phase: PHASE_REGISTRATION, + }); + break; + } + case ServerType.PREMIUM: + case ServerType.ADVANCED: + this.onServerConfigChange({ + hsUrl: this.props.defaultHsUrl, + isUrl: this.props.defaultIsUrl, + }); + this.setState({ + phase: PHASE_SERVER_DETAILS, + }); + break; + } + }, + _replaceClient: async function() { this._matrixClient = Matrix.createClient({ baseUrl: this.state.hsUrl, @@ -300,62 +343,114 @@ module.exports = React.createClass({ }; }, + renderServerComponent() { + const ServerTypeSelector = sdk.getComponent("auth.ServerTypeSelector"); + const ServerConfig = sdk.getComponent("auth.ServerConfig"); + const ModularServerConfig = sdk.getComponent("auth.ModularServerConfig"); + const AccessibleButton = sdk.getComponent("elements.AccessibleButton"); + + // TODO: May need to adjust the behavior of this config option + if (SdkConfig.get()['disable_custom_urls']) { + return null; + } + + // If we're on a different phase, we only show the server type selector, + // which is always shown if we allow custom URLs at all. + if (PHASES_ENABLED && this.state.phase !== PHASE_SERVER_DETAILS) { + return
+ +
; + } + + let serverDetails = null; + switch (this.state.serverType) { + case ServerType.FREE: + break; + case ServerType.PREMIUM: + serverDetails = ; + break; + case ServerType.ADVANCED: + serverDetails = ; + break; + } + + let nextButton = null; + if (PHASES_ENABLED) { + nextButton = + {_t("Next")} + ; + } + + return
+ + {serverDetails} + {nextButton} +
; + }, + + renderRegisterComponent() { + if (PHASES_ENABLED && this.state.phase !== PHASE_REGISTRATION) { + return null; + } + + const InteractiveAuth = sdk.getComponent('structures.InteractiveAuth'); + const Spinner = sdk.getComponent('elements.Spinner'); + const RegistrationForm = sdk.getComponent('auth.RegistrationForm'); + + if (this.state.doingUIAuth) { + return ; + } else if (this.state.busy || !this.state.flows) { + return ; + } else { + return ; + } + }, + render: function() { const AuthHeader = sdk.getComponent('auth.AuthHeader'); const AuthBody = sdk.getComponent("auth.AuthBody"); const AuthPage = sdk.getComponent('auth.AuthPage'); - const InteractiveAuth = sdk.getComponent('structures.InteractiveAuth'); - const Spinner = sdk.getComponent("elements.Spinner"); - const ServerConfig = sdk.getComponent('views.auth.ServerConfig'); - - let registerBody; - if (this.state.doingUIAuth) { - registerBody = ( - - ); - } else if (this.state.busy || !this.state.flows) { - registerBody = ; - } else { - let serverConfigSection; - if (!SdkConfig.get()['disable_custom_urls']) { - serverConfigSection = ( - - ); - } - registerBody = ( -
- - { serverConfigSection } -
- ); - } let errorText; const err = this.state.errorText || this.props.defaultServerDiscoveryError; @@ -378,7 +473,8 @@ module.exports = React.createClass({

{ _t('Create your account') }

{ errorText } - { registerBody } + { this.renderServerComponent() } + { this.renderRegisterComponent() } { signIn }