mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-18 06:35:35 +08:00
let registering guests either upgrade or create a new account by specifying a new username. fixes https://github.com/vector-im/vector-web/issues/1161
This commit is contained in:
parent
672a5cb89c
commit
f70eec62d1
@ -1033,7 +1033,6 @@ module.exports = React.createClass({
|
|||||||
idSid={this.state.register_id_sid}
|
idSid={this.state.register_id_sid}
|
||||||
email={this.props.startingQueryParams.email}
|
email={this.props.startingQueryParams.email}
|
||||||
username={this.state.upgradeUsername}
|
username={this.state.upgradeUsername}
|
||||||
disableUsernameChanges={Boolean(this.state.upgradeUsername)}
|
|
||||||
guestAccessToken={this.state.guestAccessToken}
|
guestAccessToken={this.state.guestAccessToken}
|
||||||
defaultHsUrl={this.props.config.default_hs_url}
|
defaultHsUrl={this.props.config.default_hs_url}
|
||||||
defaultIsUrl={this.props.config.default_is_url}
|
defaultIsUrl={this.props.config.default_is_url}
|
||||||
|
@ -43,7 +43,6 @@ module.exports = React.createClass({
|
|||||||
email: React.PropTypes.string,
|
email: React.PropTypes.string,
|
||||||
username: React.PropTypes.string,
|
username: React.PropTypes.string,
|
||||||
guestAccessToken: React.PropTypes.string,
|
guestAccessToken: React.PropTypes.string,
|
||||||
disableUsernameChanges: React.PropTypes.bool,
|
|
||||||
// registration shouldn't know or care how login is done.
|
// registration shouldn't know or care how login is done.
|
||||||
onLoginClick: React.PropTypes.func.isRequired
|
onLoginClick: React.PropTypes.func.isRequired
|
||||||
},
|
},
|
||||||
@ -108,6 +107,12 @@ module.exports = React.createClass({
|
|||||||
errorText: "",
|
errorText: "",
|
||||||
busy: true
|
busy: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (formVals.username !== this.props.username) {
|
||||||
|
// don't try to upgrade if we changed our username
|
||||||
|
this.registerLogic.setGuestAccessToken(null);
|
||||||
|
}
|
||||||
|
|
||||||
this.onProcessingRegistration(this.registerLogic.register(formVals));
|
this.onProcessingRegistration(this.registerLogic.register(formVals));
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -205,7 +210,6 @@ module.exports = React.createClass({
|
|||||||
showEmail={true}
|
showEmail={true}
|
||||||
defaultUsername={this.props.username}
|
defaultUsername={this.props.username}
|
||||||
defaultEmail={this.props.email}
|
defaultEmail={this.props.email}
|
||||||
disableUsernameChanges={this.props.disableUsernameChanges}
|
|
||||||
minPasswordLength={MIN_PASSWORD_LENGTH}
|
minPasswordLength={MIN_PASSWORD_LENGTH}
|
||||||
onError={this.onFormValidationFailed}
|
onError={this.onFormValidationFailed}
|
||||||
onRegisterClick={this.onFormSubmit} />
|
onRegisterClick={this.onFormSubmit} />
|
||||||
|
@ -38,7 +38,6 @@ module.exports = React.createClass({
|
|||||||
defaultUsername: React.PropTypes.string,
|
defaultUsername: React.PropTypes.string,
|
||||||
showEmail: React.PropTypes.bool,
|
showEmail: React.PropTypes.bool,
|
||||||
minPasswordLength: React.PropTypes.number,
|
minPasswordLength: React.PropTypes.number,
|
||||||
disableUsernameChanges: React.PropTypes.bool,
|
|
||||||
onError: React.PropTypes.func,
|
onError: React.PropTypes.func,
|
||||||
onRegisterClick: React.PropTypes.func // onRegisterClick(Object) => ?Promise
|
onRegisterClick: React.PropTypes.func // onRegisterClick(Object) => ?Promise
|
||||||
},
|
},
|
||||||
@ -56,7 +55,7 @@ module.exports = React.createClass({
|
|||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
email: this.props.defaultEmail,
|
email: this.props.defaultEmail,
|
||||||
username: this.props.defaultUsername,
|
username: null,
|
||||||
password: null,
|
password: null,
|
||||||
passwordConfirm: null,
|
passwordConfirm: null,
|
||||||
fieldValid: {}
|
fieldValid: {}
|
||||||
@ -78,7 +77,7 @@ module.exports = React.createClass({
|
|||||||
|
|
||||||
if (this.allFieldsValid()) {
|
if (this.allFieldsValid()) {
|
||||||
var promise = this.props.onRegisterClick({
|
var promise = this.props.onRegisterClick({
|
||||||
username: this.refs.username.value.trim(),
|
username: this.refs.username.value.trim() || this.props.defaultUsername,
|
||||||
password: this.refs.password.value.trim(),
|
password: this.refs.password.value.trim(),
|
||||||
email: this.refs.email.value.trim()
|
email: this.refs.email.value.trim()
|
||||||
});
|
});
|
||||||
@ -120,13 +119,14 @@ module.exports = React.createClass({
|
|||||||
break;
|
break;
|
||||||
case FIELD_USERNAME:
|
case FIELD_USERNAME:
|
||||||
// XXX: SPEC-1
|
// XXX: SPEC-1
|
||||||
if (encodeURIComponent(this.refs.username.value) != this.refs.username.value) {
|
var username = this.refs.username.value.trim() || this.props.defaultUsername;
|
||||||
|
if (encodeURIComponent(username) != username) {
|
||||||
this.markFieldValid(
|
this.markFieldValid(
|
||||||
field_id,
|
field_id,
|
||||||
false,
|
false,
|
||||||
"RegistrationForm.ERR_USERNAME_INVALID"
|
"RegistrationForm.ERR_USERNAME_INVALID"
|
||||||
);
|
);
|
||||||
} else if (this.refs.username.value == '') {
|
} else if (username == '') {
|
||||||
this.markFieldValid(
|
this.markFieldValid(
|
||||||
field_id,
|
field_id,
|
||||||
false,
|
false,
|
||||||
@ -199,7 +199,7 @@ module.exports = React.createClass({
|
|||||||
if (this.props.showEmail) {
|
if (this.props.showEmail) {
|
||||||
emailSection = (
|
emailSection = (
|
||||||
<input className="mx_Login_field" type="text" ref="email"
|
<input className="mx_Login_field" type="text" ref="email"
|
||||||
autoFocus={true} placeholder="Email address"
|
autoFocus={true} placeholder="Email address (optional)"
|
||||||
defaultValue={this.state.email}
|
defaultValue={this.state.email}
|
||||||
style={this._styleField(FIELD_EMAIL)}
|
style={this._styleField(FIELD_EMAIL)}
|
||||||
onBlur={function() {self.validateField(FIELD_EMAIL)}} />
|
onBlur={function() {self.validateField(FIELD_EMAIL)}} />
|
||||||
@ -211,17 +211,24 @@ module.exports = React.createClass({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var placeholderUserName = "User name";
|
||||||
|
if (this.props.defaultUsername) {
|
||||||
|
placeholderUserName += " (default: " + this.props.defaultUsername + ")"
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<form onSubmit={this.onSubmit}>
|
<form onSubmit={this.onSubmit}>
|
||||||
{emailSection}
|
{emailSection}
|
||||||
<br />
|
<br />
|
||||||
<input className="mx_Login_field" type="text" ref="username"
|
<input className="mx_Login_field" type="text" ref="username"
|
||||||
placeholder="User name" defaultValue={this.state.username}
|
placeholder={ placeholderUserName } defaultValue={this.state.username}
|
||||||
style={this._styleField(FIELD_USERNAME)}
|
style={this._styleField(FIELD_USERNAME)}
|
||||||
onBlur={function() {self.validateField(FIELD_USERNAME)}}
|
onBlur={function() {self.validateField(FIELD_USERNAME)}} />
|
||||||
disabled={this.props.disableUsernameChanges} />
|
|
||||||
<br />
|
<br />
|
||||||
|
{ this.props.defaultUsername ?
|
||||||
|
<div className="mx_Login_fieldLabel">Setting a user name will create a fresh account</div> : null
|
||||||
|
}
|
||||||
<input className="mx_Login_field" type="password" ref="password"
|
<input className="mx_Login_field" type="password" ref="password"
|
||||||
style={this._styleField(FIELD_PASSWORD)}
|
style={this._styleField(FIELD_PASSWORD)}
|
||||||
onBlur={function() {self.validateField(FIELD_PASSWORD)}}
|
onBlur={function() {self.validateField(FIELD_PASSWORD)}}
|
||||||
|
Loading…
Reference in New Issue
Block a user