Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 4517eab

Browse files
authored
Merge pull request #2148 from matrix-org/dbkr/dont_say_email_optional_if_it_isnt
Correctly mark email as optional
2 parents e5b761b + 775d995 commit 4517eab

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

src/components/structures/login/Registration.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ module.exports = React.createClass({
9393
doingUIAuth: Boolean(this.props.sessionId),
9494
hsUrl: this.props.customHsUrl,
9595
isUrl: this.props.customIsUrl,
96+
flows: null,
9697
};
9798
},
9899

@@ -145,11 +146,27 @@ module.exports = React.createClass({
145146
});
146147
},
147148

148-
_replaceClient: function() {
149+
_replaceClient: async function() {
149150
this._matrixClient = Matrix.createClient({
150151
baseUrl: this.state.hsUrl,
151152
idBaseUrl: this.state.isUrl,
152153
});
154+
try {
155+
await this._makeRegisterRequest({});
156+
// This should never succeed since we specified an empty
157+
// auth object.
158+
console.log("Expecting 401 from register request but got success!");
159+
} catch (e) {
160+
if (e.httpStatus === 401) {
161+
this.setState({
162+
flows: e.data.flows,
163+
});
164+
} else {
165+
this.setState({
166+
errorText: _t("Unable to query for supported registration methods"),
167+
});
168+
}
169+
}
153170
},
154171

155172
onFormSubmit: function(formVals) {
@@ -378,7 +395,7 @@ module.exports = React.createClass({
378395
poll={true}
379396
/>
380397
);
381-
} else if (this.state.busy || this.state.teamServerBusy) {
398+
} else if (this.state.busy || this.state.teamServerBusy || !this.state.flows) {
382399
registerBody = <Spinner />;
383400
} else {
384401
let serverConfigSection;
@@ -408,6 +425,7 @@ module.exports = React.createClass({
408425
onError={this.onFormValidationFailed}
409426
onRegisterClick={this.onFormSubmit}
410427
onTeamSelected={this.onTeamSelected}
428+
flows={this.state.flows}
411429
/>
412430
{ serverConfigSection }
413431
</div>

src/components/views/login/RegistrationForm.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
Copyright 2015, 2016 OpenMarket Ltd
33
Copyright 2017 Vector Creations Ltd
4+
Copyright 2018 New Vector Ltd
45
56
Licensed under the Apache License, Version 2.0 (the "License");
67
you may not use this file except in compliance with the License.
@@ -49,7 +50,7 @@ module.exports = React.createClass({
4950
teamsConfig: PropTypes.shape({
5051
// Email address to request new teams
5152
supportEmail: PropTypes.string,
52-
teams: PropTypes.arrayOf(React.PropTypes.shape({
53+
teams: PropTypes.arrayOf(PropTypes.shape({
5354
// The displayed name of the team
5455
"name": PropTypes.string,
5556
// The domain of team email addresses
@@ -60,6 +61,7 @@ module.exports = React.createClass({
6061
minPasswordLength: PropTypes.number,
6162
onError: PropTypes.func,
6263
onRegisterClick: PropTypes.func.isRequired, // onRegisterClick(Object) => ?Promise
64+
flows: PropTypes.arrayOf(PropTypes.object).isRequired,
6365
},
6466

6567
getDefaultProps: function() {
@@ -273,12 +275,18 @@ module.exports = React.createClass({
273275
});
274276
},
275277

278+
_authStepIsRequired(step) {
279+
// A step is required if no flow exists which does not include that step
280+
// (Notwithstanding setups like either email or msisdn being required)
281+
return !this.props.flows.some((flow) => {
282+
return !flow.stages.includes(step);
283+
});
284+
},
285+
276286
render: function() {
277287
const self = this;
278288

279-
const theme = SettingsStore.getValue("theme");
280-
// FIXME: remove hardcoded Status team tweaks at some point
281-
const emailPlaceholder = theme === 'status' ? _t("Email address") : _t("Email address (optional)");
289+
const emailPlaceholder = this._authStepIsRequired('m.login.email.identity') ? _t("Email address") : _t("Email address (optional)");
282290

283291
const emailSection = (
284292
<div>
@@ -315,6 +323,7 @@ module.exports = React.createClass({
315323
const CountryDropdown = sdk.getComponent('views.login.CountryDropdown');
316324
let phoneSection;
317325
if (!SdkConfig.get().disable_3pid_login) {
326+
const phonePlaceholder = this._authStepIsRequired('m.login.msisdn') ? _t("Mobile phone number") : _t("Mobile phone number (optional)");
318327
phoneSection = (
319328
<div className="mx_Login_phoneSection">
320329
<CountryDropdown ref="phone_country" onOptionChange={this._onPhoneCountryChange}
@@ -324,7 +333,7 @@ module.exports = React.createClass({
324333
showPrefix={true}
325334
/>
326335
<input type="text" ref="phoneNumber"
327-
placeholder={_t("Mobile phone number (optional)")}
336+
placeholder={phonePlaceholder}
328337
defaultValue={this.props.defaultPhoneNumber}
329338
className={this._classForField(
330339
FIELD_PHONE_NUMBER,

test/components/views/login/RegistrationForm-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ function doInputEmail(inputEmail, onTeamSelected) {
3737
<RegistrationForm
3838
teamsConfig={TEAM_CONFIG}
3939
onTeamSelected={onTeamSelected}
40+
flows={[
41+
{
42+
stages: ['m.login.dummy'],
43+
},
44+
]}
4045
/>,
4146
);
4247

0 commit comments

Comments
 (0)