From cfe19d710b37bd07230f8baedf71973a703b0ac4 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 30 Jan 2019 00:33:29 -0600 Subject: [PATCH] Avoid hsName for auth headers which can be outdated `hsName` uses only the default HS, so that can easily be outdated if the HS URL is customized. --- src/components/structures/MatrixChat.js | 2 -- src/components/structures/auth/Login.js | 5 ----- src/components/structures/auth/Registration.js | 5 ----- src/components/views/auth/PasswordLogin.js | 18 +++++++----------- src/components/views/auth/RegistrationForm.js | 17 ++++++----------- 5 files changed, 13 insertions(+), 34 deletions(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 9f3db9b531..d0a5aa42c4 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -1892,7 +1892,6 @@ export default React.createClass({ idSid={this.state.register_id_sid} email={this.props.startingFragmentQueryParams.email} referrer={this.props.startingFragmentQueryParams.referrer} - defaultServerName={this.getDefaultServerName()} defaultServerDiscoveryError={this.state.defaultServerDiscoveryError} defaultHsUrl={this.getDefaultHsUrl()} defaultIsUrl={this.getDefaultIsUrl()} @@ -1932,7 +1931,6 @@ export default React.createClass({ ); diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index 2a2d0eb4d6..e2d1bf1321 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -56,10 +56,6 @@ module.exports = React.createClass({ email: PropTypes.string, referrer: PropTypes.string, - // The default server name to use when the user hasn't specified - // one. This is used when displaying the defaultHsUrl in the UI. - defaultServerName: PropTypes.string, - // An error passed along from higher up explaining that something // went wrong when finding the defaultHsUrl. defaultServerDiscoveryError: PropTypes.string, @@ -473,7 +469,6 @@ module.exports = React.createClass({ onEditServerDetailsClick={onEditServerDetailsClick} flows={this.state.flows} hsUrl={this.state.hsUrl} - hsName={this.props.defaultServerName} />; } }, diff --git a/src/components/views/auth/PasswordLogin.js b/src/components/views/auth/PasswordLogin.js index 60f9c5b8aa..f692c31b35 100644 --- a/src/components/views/auth/PasswordLogin.js +++ b/src/components/views/auth/PasswordLogin.js @@ -41,7 +41,6 @@ class PasswordLogin extends React.Component { initialPassword: "", loginIncorrect: false, hsUrl: "", - hsName: null, disableSubmit: false, } @@ -251,15 +250,13 @@ class PasswordLogin extends React.Component { } let yourMatrixAccountText = _t('Your account'); - if (this.props.hsName) { - yourMatrixAccountText = _t('Your %(serverName)s account', {serverName: this.props.hsName}); - } else { - try { - const parsedHsUrl = new URL(this.props.hsUrl); - yourMatrixAccountText = _t('Your %(serverName)s account', {serverName: parsedHsUrl.hostname}); - } catch (e) { - // ignore - } + try { + const parsedHsUrl = new URL(this.props.hsUrl); + yourMatrixAccountText = _t('Your %(serverName)s account', { + serverName: parsedHsUrl.hostname, + }); + } catch (e) { + // ignore } let editLink = null; @@ -341,7 +338,6 @@ PasswordLogin.propTypes = { onPhoneNumberChanged: PropTypes.func, onPasswordChanged: PropTypes.func, loginIncorrect: PropTypes.bool, - hsName: PropTypes.string, disableSubmit: PropTypes.bool, }; diff --git a/src/components/views/auth/RegistrationForm.js b/src/components/views/auth/RegistrationForm.js index fcd306c5da..e43537364b 100644 --- a/src/components/views/auth/RegistrationForm.js +++ b/src/components/views/auth/RegistrationForm.js @@ -51,6 +51,7 @@ module.exports = React.createClass({ onRegisterClick: PropTypes.func.isRequired, // onRegisterClick(Object) => ?Promise onEditServerDetailsClick: PropTypes.func, flows: PropTypes.arrayOf(PropTypes.object).isRequired, + hsUrl: PropTypes.string, }, getDefaultProps: function() { @@ -258,19 +259,13 @@ module.exports = React.createClass({ const self = this; let yourMatrixAccountText = _t('Create your account'); - if (this.props.hsName) { + try { + const parsedHsUrl = new URL(this.props.hsUrl); yourMatrixAccountText = _t('Create your %(serverName)s account', { - serverName: this.props.hsName, + serverName: parsedHsUrl.hostname, }); - } else { - try { - const parsedHsUrl = new URL(this.props.hsUrl); - yourMatrixAccountText = _t('Create your %(serverName)s account', { - serverName: parsedHsUrl.hostname, - }); - } catch (e) { - // ignore - } + } catch (e) { + // ignore } let editLink = null;