2015-11-30 21:11:04 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-02-24 14:41:23 +03:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2018-09-04 20:26:09 +03:00
|
|
|
Copyright 2018 New Vector Ltd
|
2015-11-30 21:11:04 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-02-24 14:41:23 +03:00
|
|
|
import React from 'react';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-02-24 14:41:23 +03:00
|
|
|
import sdk from '../../../index';
|
|
|
|
import Email from '../../../email';
|
2017-03-14 14:50:13 +03:00
|
|
|
import { looksValid as phoneNumberLooksValid } from '../../../phonenumber';
|
2017-02-24 14:41:23 +03:00
|
|
|
import Modal from '../../../Modal';
|
2017-05-30 17:09:57 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2017-11-12 02:46:43 +03:00
|
|
|
import SdkConfig from '../../../SdkConfig';
|
2018-12-14 02:05:34 +03:00
|
|
|
import { SAFE_LOCALPART_REGEX } from '../../../Registration';
|
2019-04-16 18:52:31 +03:00
|
|
|
import withValidation from '../elements/Validation';
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2017-02-24 14:41:23 +03:00
|
|
|
const FIELD_EMAIL = 'field_email';
|
2017-03-14 14:50:13 +03:00
|
|
|
const FIELD_PHONE_NUMBER = 'field_phone_number';
|
2017-02-24 14:41:23 +03:00
|
|
|
const FIELD_USERNAME = 'field_username';
|
|
|
|
const FIELD_PASSWORD = 'field_password';
|
|
|
|
const FIELD_PASSWORD_CONFIRM = 'field_password_confirm';
|
2016-01-15 16:31:41 +03:00
|
|
|
|
2015-11-30 21:11:04 +03:00
|
|
|
/**
|
|
|
|
* A pure UI component which displays a registration form.
|
|
|
|
*/
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'RegistrationForm',
|
|
|
|
|
|
|
|
propTypes: {
|
2016-07-07 13:23:08 +03:00
|
|
|
// Values pre-filled in the input boxes when the component loads
|
2017-12-26 04:03:18 +03:00
|
|
|
defaultEmail: PropTypes.string,
|
|
|
|
defaultPhoneCountry: PropTypes.string,
|
|
|
|
defaultPhoneNumber: PropTypes.string,
|
|
|
|
defaultUsername: PropTypes.string,
|
|
|
|
defaultPassword: PropTypes.string,
|
|
|
|
minPasswordLength: PropTypes.number,
|
2019-02-21 17:31:11 +03:00
|
|
|
onValidationChange: PropTypes.func,
|
2017-12-26 04:03:18 +03:00
|
|
|
onRegisterClick: PropTypes.func.isRequired, // onRegisterClick(Object) => ?Promise
|
2019-01-30 00:05:15 +03:00
|
|
|
onEditServerDetailsClick: PropTypes.func,
|
2018-09-04 20:50:18 +03:00
|
|
|
flows: PropTypes.arrayOf(PropTypes.object).isRequired,
|
2019-02-20 15:14:03 +03:00
|
|
|
// This is optional and only set if we used a server name to determine
|
|
|
|
// the HS URL via `.well-known` discovery. The server name is used
|
|
|
|
// instead of the HS URL when talking about "your account".
|
|
|
|
hsName: PropTypes.string,
|
2019-01-30 09:33:29 +03:00
|
|
|
hsUrl: PropTypes.string,
|
2015-11-30 21:11:04 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
minPasswordLength: 6,
|
2019-02-21 17:31:11 +03:00
|
|
|
onValidationChange: console.error,
|
2015-11-30 21:11:04 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2019-02-21 17:31:11 +03:00
|
|
|
// Field error codes by field ID
|
2019-04-17 13:39:11 +03:00
|
|
|
// TODO: Remove `fieldErrors` once converted to new-style validation
|
2019-02-21 17:31:11 +03:00
|
|
|
fieldErrors: {},
|
2019-04-17 13:39:11 +03:00
|
|
|
fieldValid: {},
|
2017-03-14 14:50:13 +03:00
|
|
|
// The ISO2 country code selected in the phone number entry
|
|
|
|
phoneCountry: this.props.defaultPhoneCountry,
|
2019-03-14 17:29:04 +03:00
|
|
|
username: "",
|
|
|
|
email: "",
|
|
|
|
phoneNumber: "",
|
|
|
|
password: "",
|
|
|
|
passwordConfirm: "",
|
2015-11-30 21:11:04 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
onSubmit: function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
|
2016-01-15 19:17:27 +03:00
|
|
|
// validate everything, in reverse order so
|
|
|
|
// the error that ends up being displayed
|
|
|
|
// is the one from the first invalid field.
|
|
|
|
// It's not super ideal that this just calls
|
2019-02-21 17:31:11 +03:00
|
|
|
// onValidationChange once for each invalid field.
|
2019-04-17 16:23:59 +03:00
|
|
|
// TODO: Remove these calls once converted to new-style validation.
|
2019-02-21 14:35:50 +03:00
|
|
|
this.validateField(FIELD_PHONE_NUMBER, ev.type);
|
|
|
|
this.validateField(FIELD_EMAIL, ev.type);
|
2019-01-30 23:48:12 +03:00
|
|
|
this.validateField(FIELD_PASSWORD_CONFIRM, ev.type);
|
|
|
|
this.validateField(FIELD_PASSWORD, ev.type);
|
2016-01-15 19:17:27 +03:00
|
|
|
|
2019-04-17 16:23:59 +03:00
|
|
|
const allFieldsValid = this.verifyFieldsBeforeSubmit();
|
|
|
|
if (!allFieldsValid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const self = this;
|
2019-04-17 16:23:59 +03:00
|
|
|
if (this.state.email == '') {
|
|
|
|
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
|
|
|
Modal.createTrackedDialog('If you don\'t specify an email address...', '', QuestionDialog, {
|
|
|
|
title: _t("Warning!"),
|
|
|
|
description:
|
|
|
|
<div>
|
|
|
|
{ _t("If you don't specify an email address, you won't be able to reset your password. " +
|
|
|
|
"Are you sure?") }
|
|
|
|
</div>,
|
|
|
|
button: _t("Continue"),
|
|
|
|
onFinished: function(confirmed) {
|
|
|
|
if (confirmed) {
|
|
|
|
self._doSubmit(ev);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
self._doSubmit(ev);
|
2015-11-30 21:11:04 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-06-02 23:34:18 +03:00
|
|
|
_doSubmit: function(ev) {
|
2019-03-14 17:29:04 +03:00
|
|
|
const email = this.state.email.trim();
|
2017-10-11 19:56:17 +03:00
|
|
|
const promise = this.props.onRegisterClick({
|
2019-03-14 17:29:04 +03:00
|
|
|
username: this.state.username.trim(),
|
|
|
|
password: this.state.password.trim(),
|
2017-01-19 12:51:40 +03:00
|
|
|
email: email,
|
2017-03-14 14:50:13 +03:00
|
|
|
phoneCountry: this.state.phoneCountry,
|
2019-03-14 17:29:04 +03:00
|
|
|
phoneNumber: this.state.phoneNumber,
|
2016-03-21 04:15:11 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
if (promise) {
|
|
|
|
ev.target.disabled = true;
|
|
|
|
promise.finally(function() {
|
|
|
|
ev.target.disabled = false;
|
|
|
|
});
|
2016-08-03 17:59:17 +03:00
|
|
|
}
|
2016-03-21 04:15:11 +03:00
|
|
|
},
|
|
|
|
|
2019-04-17 16:23:59 +03:00
|
|
|
verifyFieldsBeforeSubmit() {
|
2019-04-18 23:33:37 +03:00
|
|
|
const fieldIDsInDisplayOrder = [
|
2019-04-17 16:23:59 +03:00
|
|
|
FIELD_USERNAME,
|
|
|
|
FIELD_PASSWORD,
|
|
|
|
FIELD_PASSWORD_CONFIRM,
|
|
|
|
FIELD_EMAIL,
|
|
|
|
FIELD_PHONE_NUMBER,
|
2019-04-18 23:33:37 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
// Run all fields with stricter validation that no longer allows empty
|
|
|
|
// values for required fields.
|
|
|
|
for (const fieldID of fieldIDsInDisplayOrder) {
|
|
|
|
const field = this[fieldID];
|
|
|
|
if (!field) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
field.validate({ allowEmpty: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.allFieldsValid()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const invalidField = this.findFirstInvalidField(fieldIDsInDisplayOrder);
|
2019-04-17 16:23:59 +03:00
|
|
|
|
|
|
|
if (!invalidField) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-18 23:33:37 +03:00
|
|
|
// Focus the first invalid field and show feedback in the stricter mode
|
|
|
|
// that no longer allows empty values for required fields.
|
2019-04-17 16:23:59 +03:00
|
|
|
invalidField.focus();
|
2019-04-18 23:33:37 +03:00
|
|
|
invalidField.validate({ allowEmpty: false, focused: true });
|
2019-04-17 16:23:59 +03:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2016-01-15 19:17:27 +03:00
|
|
|
/**
|
2019-01-24 03:32:36 +03:00
|
|
|
* @returns {boolean} true if all fields were valid last time they were validated.
|
2016-01-15 19:17:27 +03:00
|
|
|
*/
|
|
|
|
allFieldsValid: function() {
|
2019-04-17 13:39:11 +03:00
|
|
|
// TODO: Remove `fieldErrors` here when all fields converted
|
|
|
|
let keys = Object.keys(this.state.fieldErrors);
|
2017-10-11 19:56:17 +03:00
|
|
|
for (let i = 0; i < keys.length; ++i) {
|
2019-02-21 17:31:11 +03:00
|
|
|
if (this.state.fieldErrors[keys[i]]) {
|
2016-01-15 19:17:27 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 13:39:11 +03:00
|
|
|
keys = Object.keys(this.state.fieldValid);
|
|
|
|
for (let i = 0; i < keys.length; ++i) {
|
|
|
|
if (!this.state.fieldValid[keys[i]]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-01-15 19:17:27 +03:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2019-04-17 16:23:59 +03:00
|
|
|
findFirstInvalidField(fieldIDs) {
|
|
|
|
for (const fieldID of fieldIDs) {
|
|
|
|
if (!this.state.fieldValid[fieldID] && this[fieldID]) {
|
|
|
|
return this[fieldID];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2019-01-30 23:48:12 +03:00
|
|
|
validateField: function(fieldID, eventType) {
|
2019-03-14 17:29:04 +03:00
|
|
|
const pwd1 = this.state.password.trim();
|
|
|
|
const pwd2 = this.state.passwordConfirm.trim();
|
2019-01-30 23:48:12 +03:00
|
|
|
const allowEmpty = eventType === "blur";
|
2016-01-15 16:31:41 +03:00
|
|
|
|
2019-04-16 18:52:31 +03:00
|
|
|
// TODO: Remove rules here as they are converted to new-style validation
|
|
|
|
|
2019-01-24 03:32:36 +03:00
|
|
|
switch (fieldID) {
|
|
|
|
case FIELD_EMAIL: {
|
2019-03-14 17:29:04 +03:00
|
|
|
const email = this.state.email;
|
2017-02-24 14:41:23 +03:00
|
|
|
const emailValid = email === '' || Email.looksValid(email);
|
2018-09-27 20:53:45 +03:00
|
|
|
if (this._authStepIsRequired('m.login.email.identity') && (!emailValid || email === '')) {
|
2019-04-17 13:39:11 +03:00
|
|
|
this.markFieldError(fieldID, false, "RegistrationForm.ERR_MISSING_EMAIL");
|
|
|
|
} else this.markFieldError(fieldID, emailValid, "RegistrationForm.ERR_EMAIL_INVALID");
|
2016-01-15 16:31:41 +03:00
|
|
|
break;
|
2019-01-24 03:32:36 +03:00
|
|
|
}
|
|
|
|
case FIELD_PHONE_NUMBER: {
|
2019-03-14 17:29:04 +03:00
|
|
|
const phoneNumber = this.state.phoneNumber;
|
2017-03-14 14:50:13 +03:00
|
|
|
const phoneNumberValid = phoneNumber === '' || phoneNumberLooksValid(phoneNumber);
|
2018-09-27 20:53:45 +03:00
|
|
|
if (this._authStepIsRequired('m.login.msisdn') && (!phoneNumberValid || phoneNumber === '')) {
|
2019-04-17 13:39:11 +03:00
|
|
|
this.markFieldError(fieldID, false, "RegistrationForm.ERR_MISSING_PHONE_NUMBER");
|
|
|
|
} else this.markFieldError(fieldID, phoneNumberValid, "RegistrationForm.ERR_PHONE_NUMBER_INVALID");
|
2017-03-14 14:50:13 +03:00
|
|
|
break;
|
2019-01-24 03:32:36 +03:00
|
|
|
}
|
2016-01-15 16:31:41 +03:00
|
|
|
case FIELD_PASSWORD:
|
2019-01-30 23:48:12 +03:00
|
|
|
if (allowEmpty && pwd1 === "") {
|
2019-04-17 13:39:11 +03:00
|
|
|
this.markFieldError(fieldID, true);
|
2019-01-30 23:48:12 +03:00
|
|
|
} else if (pwd1 == '') {
|
2019-04-17 13:39:11 +03:00
|
|
|
this.markFieldError(
|
2019-01-24 03:32:36 +03:00
|
|
|
fieldID,
|
2016-01-15 16:31:41 +03:00
|
|
|
false,
|
2017-10-11 19:56:17 +03:00
|
|
|
"RegistrationForm.ERR_PASSWORD_MISSING",
|
2016-01-15 16:31:41 +03:00
|
|
|
);
|
|
|
|
} else if (pwd1.length < this.props.minPasswordLength) {
|
2019-04-17 13:39:11 +03:00
|
|
|
this.markFieldError(
|
2019-01-24 03:32:36 +03:00
|
|
|
fieldID,
|
2016-01-15 16:31:41 +03:00
|
|
|
false,
|
2017-10-11 19:56:17 +03:00
|
|
|
"RegistrationForm.ERR_PASSWORD_LENGTH",
|
2016-01-15 16:31:41 +03:00
|
|
|
);
|
|
|
|
} else {
|
2019-04-17 13:39:11 +03:00
|
|
|
this.markFieldError(fieldID, true);
|
2016-01-15 16:31:41 +03:00
|
|
|
}
|
|
|
|
break;
|
2016-01-15 19:17:27 +03:00
|
|
|
case FIELD_PASSWORD_CONFIRM:
|
2019-02-21 15:36:31 +03:00
|
|
|
if (allowEmpty && pwd2 === "") {
|
2019-04-17 13:39:11 +03:00
|
|
|
this.markFieldError(fieldID, true);
|
2019-02-21 15:36:31 +03:00
|
|
|
} else {
|
2019-04-17 13:39:11 +03:00
|
|
|
this.markFieldError(
|
2019-02-21 15:36:31 +03:00
|
|
|
fieldID, pwd1 == pwd2,
|
|
|
|
"RegistrationForm.ERR_PASSWORD_MISMATCH",
|
|
|
|
);
|
|
|
|
}
|
2016-01-15 19:17:27 +03:00
|
|
|
break;
|
2016-01-15 16:31:41 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-04-17 13:39:11 +03:00
|
|
|
markFieldError: function(fieldID, valid, errorCode) {
|
|
|
|
// TODO: Remove this function once all fields converted to new-style validation.
|
2019-02-21 17:31:11 +03:00
|
|
|
const { fieldErrors } = this.state;
|
|
|
|
if (valid) {
|
|
|
|
fieldErrors[fieldID] = null;
|
|
|
|
} else {
|
|
|
|
fieldErrors[fieldID] = errorCode;
|
2016-01-15 16:31:41 +03:00
|
|
|
}
|
2019-02-21 17:31:11 +03:00
|
|
|
this.setState({
|
|
|
|
fieldErrors,
|
|
|
|
});
|
2019-04-16 18:52:31 +03:00
|
|
|
// TODO: Remove outer validation handling once all fields converted to new-style
|
|
|
|
// validation in the form.
|
2019-02-21 17:31:11 +03:00
|
|
|
this.props.onValidationChange(fieldErrors);
|
2016-01-15 16:31:41 +03:00
|
|
|
},
|
|
|
|
|
2019-04-17 13:39:11 +03:00
|
|
|
markFieldValid: function(fieldID, valid) {
|
|
|
|
const { fieldValid } = this.state;
|
|
|
|
fieldValid[fieldID] = valid;
|
|
|
|
this.setState({
|
|
|
|
fieldValid,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-01-24 03:32:36 +03:00
|
|
|
_classForField: function(fieldID, ...baseClasses) {
|
2017-02-24 14:41:23 +03:00
|
|
|
let cls = baseClasses.join(' ');
|
2019-04-16 18:52:31 +03:00
|
|
|
// TODO: Remove this from fields as they are converted to new-style validation.
|
2019-02-21 17:31:11 +03:00
|
|
|
if (this.state.fieldErrors[fieldID]) {
|
2016-08-03 17:59:17 +03:00
|
|
|
if (cls) cls += ' ';
|
|
|
|
cls += 'error';
|
2016-01-15 16:31:41 +03:00
|
|
|
}
|
2016-08-03 17:59:17 +03:00
|
|
|
return cls;
|
2016-01-15 16:31:41 +03:00
|
|
|
},
|
|
|
|
|
2019-01-30 23:48:12 +03:00
|
|
|
onEmailBlur(ev) {
|
|
|
|
this.validateField(FIELD_EMAIL, ev.type);
|
|
|
|
},
|
|
|
|
|
2019-03-14 17:29:04 +03:00
|
|
|
onEmailChange(ev) {
|
|
|
|
this.setState({
|
|
|
|
email: ev.target.value,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-01-30 23:48:12 +03:00
|
|
|
onPasswordBlur(ev) {
|
|
|
|
this.validateField(FIELD_PASSWORD, ev.type);
|
|
|
|
},
|
|
|
|
|
2019-03-14 17:29:04 +03:00
|
|
|
onPasswordChange(ev) {
|
|
|
|
this.setState({
|
|
|
|
password: ev.target.value,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-01-30 23:48:12 +03:00
|
|
|
onPasswordConfirmBlur(ev) {
|
|
|
|
this.validateField(FIELD_PASSWORD_CONFIRM, ev.type);
|
|
|
|
},
|
|
|
|
|
2019-03-14 17:29:04 +03:00
|
|
|
onPasswordConfirmChange(ev) {
|
|
|
|
this.setState({
|
|
|
|
passwordConfirm: ev.target.value,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-01-30 23:48:12 +03:00
|
|
|
onPhoneCountryChange(newVal) {
|
2017-03-14 14:50:13 +03:00
|
|
|
this.setState({
|
2017-04-25 13:21:47 +03:00
|
|
|
phoneCountry: newVal.iso2,
|
|
|
|
phonePrefix: newVal.prefix,
|
2017-03-14 14:50:13 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-01-30 23:48:12 +03:00
|
|
|
onPhoneNumberBlur(ev) {
|
|
|
|
this.validateField(FIELD_PHONE_NUMBER, ev.type);
|
|
|
|
},
|
|
|
|
|
2019-03-14 17:29:04 +03:00
|
|
|
onPhoneNumberChange(ev) {
|
|
|
|
this.setState({
|
|
|
|
phoneNumber: ev.target.value,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onUsernameChange(ev) {
|
|
|
|
this.setState({
|
|
|
|
username: ev.target.value,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-04-17 13:39:11 +03:00
|
|
|
onUsernameValidate(fieldState) {
|
|
|
|
const result = this.validateUsernameRules(fieldState);
|
|
|
|
this.markFieldValid(FIELD_USERNAME, result.valid);
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
validateUsernameRules: withValidation({
|
|
|
|
description: () => _t("Use letters, numbers, dashes and underscores only"),
|
|
|
|
rules: [
|
2019-04-18 23:33:37 +03:00
|
|
|
{
|
|
|
|
key: "required",
|
|
|
|
test: ({ value, allowEmpty }) => allowEmpty || !!value,
|
|
|
|
invalid: () => _t("Enter username"),
|
|
|
|
},
|
2019-04-17 13:39:11 +03:00
|
|
|
{
|
|
|
|
key: "safeLocalpart",
|
2019-04-18 23:33:37 +03:00
|
|
|
test: ({ value }) => !value || SAFE_LOCALPART_REGEX.test(value),
|
2019-04-17 13:39:11 +03:00
|
|
|
invalid: () => _t("Some characters not allowed"),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
|
2019-02-01 01:37:37 +03:00
|
|
|
/**
|
|
|
|
* A step is required if all flows include that step.
|
|
|
|
*
|
|
|
|
* @param {string} step A stage name to check
|
|
|
|
* @returns {boolean} Whether it is required
|
|
|
|
*/
|
2018-09-04 20:26:09 +03:00
|
|
|
_authStepIsRequired(step) {
|
2019-02-01 01:37:37 +03:00
|
|
|
return this.props.flows.every((flow) => {
|
|
|
|
return flow.stages.includes(step);
|
2018-09-04 20:26:09 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-02-01 03:07:40 +03:00
|
|
|
/**
|
|
|
|
* A step is used if any flows include that step.
|
|
|
|
*
|
|
|
|
* @param {string} step A stage name to check
|
|
|
|
* @returns {boolean} Whether it is used
|
|
|
|
*/
|
|
|
|
_authStepIsUsed(step) {
|
|
|
|
return this.props.flows.some((flow) => {
|
|
|
|
return flow.stages.includes(step);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-04-16 18:52:31 +03:00
|
|
|
renderUsername() {
|
|
|
|
const Field = sdk.getComponent('elements.Field');
|
|
|
|
return <Field
|
|
|
|
id="mx_RegistrationForm_username"
|
2019-04-17 16:23:59 +03:00
|
|
|
ref={field => this[FIELD_USERNAME] = field}
|
2019-04-16 18:52:31 +03:00
|
|
|
type="text"
|
|
|
|
autoFocus={true}
|
|
|
|
label={_t("Username")}
|
|
|
|
defaultValue={this.props.defaultUsername}
|
|
|
|
value={this.state.username}
|
|
|
|
onChange={this.onUsernameChange}
|
2019-04-17 13:39:11 +03:00
|
|
|
onValidate={this.onUsernameValidate}
|
2019-04-16 18:52:31 +03:00
|
|
|
/>;
|
|
|
|
},
|
|
|
|
|
2015-11-30 21:11:04 +03:00
|
|
|
render: function() {
|
2019-03-01 17:39:09 +03:00
|
|
|
const Field = sdk.getComponent('elements.Field');
|
|
|
|
|
2019-02-20 17:29:57 +03:00
|
|
|
let yourMatrixAccountText = _t('Create your Matrix account');
|
2019-02-20 15:14:03 +03:00
|
|
|
if (this.props.hsName) {
|
2019-02-20 17:29:57 +03:00
|
|
|
yourMatrixAccountText = _t('Create your Matrix account on %(serverName)s', {
|
2019-02-20 15:14:03 +03:00
|
|
|
serverName: this.props.hsName,
|
2019-01-29 21:23:01 +03:00
|
|
|
});
|
2019-02-20 15:14:03 +03:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
const parsedHsUrl = new URL(this.props.hsUrl);
|
2019-02-20 17:29:57 +03:00
|
|
|
yourMatrixAccountText = _t('Create your Matrix account on %(serverName)s', {
|
2019-02-20 15:14:03 +03:00
|
|
|
serverName: parsedHsUrl.hostname,
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
// ignore
|
|
|
|
}
|
2019-01-29 21:23:01 +03:00
|
|
|
}
|
|
|
|
|
2019-01-30 00:05:15 +03:00
|
|
|
let editLink = null;
|
|
|
|
if (this.props.onEditServerDetailsClick) {
|
2019-01-30 21:46:40 +03:00
|
|
|
editLink = <a className="mx_AuthBody_editServerDetails"
|
2019-01-30 00:05:15 +03:00
|
|
|
href="#" onClick={this.props.onEditServerDetailsClick}
|
|
|
|
>
|
2019-02-21 14:03:48 +03:00
|
|
|
{_t('Change')}
|
2019-01-30 00:05:15 +03:00
|
|
|
</a>;
|
|
|
|
}
|
|
|
|
|
2019-02-01 03:07:40 +03:00
|
|
|
let emailSection;
|
|
|
|
if (this._authStepIsUsed('m.login.email.identity')) {
|
|
|
|
const emailPlaceholder = this._authStepIsRequired('m.login.email.identity') ?
|
|
|
|
_t("Email") :
|
|
|
|
_t("Email (optional)");
|
|
|
|
|
|
|
|
emailSection = (
|
2019-03-01 17:39:09 +03:00
|
|
|
<Field
|
|
|
|
className={this._classForField(FIELD_EMAIL)}
|
|
|
|
id="mx_RegistrationForm_email"
|
|
|
|
type="text"
|
|
|
|
label={emailPlaceholder}
|
|
|
|
defaultValue={this.props.defaultEmail}
|
|
|
|
value={this.state.email}
|
|
|
|
onBlur={this.onEmailBlur}
|
2019-03-14 17:29:04 +03:00
|
|
|
onChange={this.onEmailChange}
|
2019-03-01 17:39:09 +03:00
|
|
|
/>
|
2019-02-01 03:07:40 +03:00
|
|
|
);
|
|
|
|
}
|
2015-11-30 21:11:04 +03:00
|
|
|
|
2019-02-01 03:07:40 +03:00
|
|
|
const threePidLogin = !SdkConfig.get().disable_3pid_login;
|
2019-01-22 01:11:10 +03:00
|
|
|
const CountryDropdown = sdk.getComponent('views.auth.CountryDropdown');
|
2017-10-25 04:04:02 +03:00
|
|
|
let phoneSection;
|
2019-02-01 03:07:40 +03:00
|
|
|
if (threePidLogin && this._authStepIsUsed('m.login.msisdn')) {
|
2019-03-05 18:16:07 +03:00
|
|
|
const phoneLabel = this._authStepIsRequired('m.login.msisdn') ?
|
2019-01-30 02:07:15 +03:00
|
|
|
_t("Phone") :
|
|
|
|
_t("Phone (optional)");
|
2019-03-05 18:16:07 +03:00
|
|
|
const phoneCountry = <CountryDropdown
|
|
|
|
value={this.state.phoneCountry}
|
|
|
|
isSmall={true}
|
|
|
|
showPrefix={true}
|
|
|
|
onOptionChange={this.onPhoneCountryChange}
|
|
|
|
/>;
|
|
|
|
|
|
|
|
phoneSection = <Field
|
|
|
|
className={this._classForField(FIELD_PHONE_NUMBER)}
|
|
|
|
id="mx_RegistrationForm_phoneNumber"
|
|
|
|
type="text"
|
|
|
|
label={phoneLabel}
|
|
|
|
defaultValue={this.props.defaultPhoneNumber}
|
|
|
|
value={this.state.phoneNumber}
|
|
|
|
prefix={phoneCountry}
|
|
|
|
onBlur={this.onPhoneNumberBlur}
|
2019-03-14 17:29:04 +03:00
|
|
|
onChange={this.onPhoneNumberChange}
|
2019-03-05 18:16:07 +03:00
|
|
|
/>;
|
2017-10-25 04:04:02 +03:00
|
|
|
}
|
2017-03-14 14:50:13 +03:00
|
|
|
|
2017-02-24 14:41:23 +03:00
|
|
|
const registerButton = (
|
2017-06-08 14:33:29 +03:00
|
|
|
<input className="mx_Login_submit" type="submit" value={_t("Register")} />
|
2017-02-24 14:41:23 +03:00
|
|
|
);
|
|
|
|
|
2015-11-30 21:11:04 +03:00
|
|
|
return (
|
|
|
|
<div>
|
2019-01-30 00:05:15 +03:00
|
|
|
<h3>
|
|
|
|
{yourMatrixAccountText}
|
|
|
|
{editLink}
|
|
|
|
</h3>
|
2015-11-30 21:11:04 +03:00
|
|
|
<form onSubmit={this.onSubmit}>
|
2019-01-30 21:46:40 +03:00
|
|
|
<div className="mx_AuthBody_fieldRow">
|
2019-04-16 18:52:31 +03:00
|
|
|
{this.renderUsername()}
|
2019-01-30 00:52:12 +03:00
|
|
|
</div>
|
2019-01-30 21:46:40 +03:00
|
|
|
<div className="mx_AuthBody_fieldRow">
|
2019-03-01 17:39:09 +03:00
|
|
|
<Field
|
|
|
|
className={this._classForField(FIELD_PASSWORD)}
|
|
|
|
id="mx_RegistrationForm_password"
|
|
|
|
type="password"
|
|
|
|
label={_t("Password")}
|
|
|
|
defaultValue={this.props.defaultPassword}
|
2019-03-14 17:29:04 +03:00
|
|
|
value={this.state.password}
|
2019-01-30 23:48:12 +03:00
|
|
|
onBlur={this.onPasswordBlur}
|
2019-03-14 17:29:04 +03:00
|
|
|
onChange={this.onPasswordChange}
|
2019-03-01 17:39:09 +03:00
|
|
|
/>
|
|
|
|
<Field
|
|
|
|
className={this._classForField(FIELD_PASSWORD_CONFIRM)}
|
|
|
|
id="mx_RegistrationForm_passwordConfirm"
|
|
|
|
type="password"
|
|
|
|
label={_t("Confirm")}
|
|
|
|
defaultValue={this.props.defaultPassword}
|
2019-03-14 17:29:04 +03:00
|
|
|
value={this.state.passwordConfirm}
|
2019-01-30 23:48:12 +03:00
|
|
|
onBlur={this.onPasswordConfirmBlur}
|
2019-03-14 17:29:04 +03:00
|
|
|
onChange={this.onPasswordConfirmChange}
|
2019-03-01 17:39:09 +03:00
|
|
|
/>
|
2019-01-30 00:52:12 +03:00
|
|
|
</div>
|
2019-01-30 21:46:40 +03:00
|
|
|
<div className="mx_AuthBody_fieldRow">
|
2019-01-30 00:52:12 +03:00
|
|
|
{ emailSection }
|
|
|
|
{ phoneSection }
|
|
|
|
</div>
|
2019-01-30 02:12:39 +03:00
|
|
|
{_t(
|
2019-02-01 03:15:18 +03:00
|
|
|
"Use an email address to recover your account. Other users " +
|
2019-01-30 02:12:39 +03:00
|
|
|
"can invite you to rooms using your contact details.",
|
|
|
|
)}
|
2017-10-11 19:56:17 +03:00
|
|
|
{ registerButton }
|
2015-11-30 21:11:04 +03:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
},
|
2015-11-30 21:11:04 +03:00
|
|
|
});
|