remove old code for global username registry
This commit is contained in:
parent
269f6e8c30
commit
6bb9c5ceee
|
@ -31,7 +31,6 @@ export default Ember.Controller.extend(ModalFunctionality, PasswordValidation, U
|
||||||
accountUsername: '',
|
accountUsername: '',
|
||||||
accountPassword: '',
|
accountPassword: '',
|
||||||
authOptions: null,
|
authOptions: null,
|
||||||
globalNicknameExists: false,
|
|
||||||
complete: false,
|
complete: false,
|
||||||
formSubmitted: false,
|
formSubmitted: false,
|
||||||
rejectedEmails: [],
|
rejectedEmails: [],
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import InputValidation from 'discourse/models/input-validation';
|
import InputValidation from 'discourse/models/input-validation';
|
||||||
import debounce from 'discourse/lib/debounce';
|
import debounce from 'discourse/lib/debounce';
|
||||||
import { setting } from 'discourse/lib/computed';
|
import { setting } from 'discourse/lib/computed';
|
||||||
|
import { default as computed } from 'ember-addons/ember-computed-decorators';
|
||||||
|
|
||||||
export default Ember.Mixin.create({
|
export default Ember.Mixin.create({
|
||||||
|
|
||||||
uniqueUsernameValidation: null,
|
uniqueUsernameValidation: null,
|
||||||
globalNicknameExists: false, // TODO: remove this
|
|
||||||
|
|
||||||
maxUsernameLength: setting('max_username_length'),
|
maxUsernameLength: setting('max_username_length'),
|
||||||
minUsernameLength: setting('min_username_length'),
|
minUsernameLength: setting('min_username_length'),
|
||||||
|
@ -20,31 +20,12 @@ export default Ember.Mixin.create({
|
||||||
});
|
});
|
||||||
}, 500),
|
}, 500),
|
||||||
|
|
||||||
usernameMatch: function() {
|
@computed('accountUsername')
|
||||||
if (this.usernameNeedsToBeValidatedWithEmail()) {
|
basicUsernameValidation(accountUsername) {
|
||||||
if (this.get('emailValidation.failed')) {
|
|
||||||
if (this.shouldCheckUsernameMatch()) {
|
|
||||||
return this.set('uniqueUsernameValidation', InputValidation.create({
|
|
||||||
failed: true,
|
|
||||||
reason: I18n.t('user.username.enter_email')
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
return this.set('uniqueUsernameValidation', InputValidation.create({ failed: true }));
|
|
||||||
}
|
|
||||||
} else if (this.shouldCheckUsernameMatch()) {
|
|
||||||
this.set('uniqueUsernameValidation', InputValidation.create({
|
|
||||||
failed: true,
|
|
||||||
reason: I18n.t('user.username.checking')
|
|
||||||
}));
|
|
||||||
return this.checkUsernameAvailability();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.observes('accountEmail'),
|
|
||||||
|
|
||||||
basicUsernameValidation: function() {
|
|
||||||
this.set('uniqueUsernameValidation', null);
|
this.set('uniqueUsernameValidation', null);
|
||||||
|
|
||||||
if (this.get('accountUsername') === this.get('prefilledUsername')) {
|
|
||||||
|
if (accountUsername === this.get('prefilledUsername')) {
|
||||||
return InputValidation.create({
|
return InputValidation.create({
|
||||||
ok: true,
|
ok: true,
|
||||||
reason: I18n.t('user.username.prefilled')
|
reason: I18n.t('user.username.prefilled')
|
||||||
|
@ -52,14 +33,14 @@ export default Ember.Mixin.create({
|
||||||
}
|
}
|
||||||
|
|
||||||
// If blank, fail without a reason
|
// If blank, fail without a reason
|
||||||
if (Ember.isEmpty(this.get('accountUsername'))) {
|
if (Ember.isEmpty(accountUsername)) {
|
||||||
return InputValidation.create({
|
return InputValidation.create({
|
||||||
failed: true
|
failed: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// If too short
|
// If too short
|
||||||
if (this.get('accountUsername').length < Discourse.SiteSettings.min_username_length) {
|
if (accountUsername.length < Discourse.SiteSettings.min_username_length) {
|
||||||
return InputValidation.create({
|
return InputValidation.create({
|
||||||
failed: true,
|
failed: true,
|
||||||
reason: I18n.t('user.username.too_short')
|
reason: I18n.t('user.username.too_short')
|
||||||
|
@ -67,7 +48,7 @@ export default Ember.Mixin.create({
|
||||||
}
|
}
|
||||||
|
|
||||||
// If too long
|
// If too long
|
||||||
if (this.get('accountUsername').length > this.get('maxUsernameLength')) {
|
if (accountUsername.length > this.get('maxUsernameLength')) {
|
||||||
return InputValidation.create({
|
return InputValidation.create({
|
||||||
failed: true,
|
failed: true,
|
||||||
reason: I18n.t('user.username.too_long')
|
reason: I18n.t('user.username.too_long')
|
||||||
|
@ -80,40 +61,34 @@ export default Ember.Mixin.create({
|
||||||
failed: true,
|
failed: true,
|
||||||
reason: I18n.t('user.username.checking')
|
reason: I18n.t('user.username.checking')
|
||||||
});
|
});
|
||||||
}.property('accountUsername'),
|
},
|
||||||
|
|
||||||
shouldCheckUsernameMatch: function() {
|
shouldCheckUsernameAvailability: function() {
|
||||||
return !Ember.isEmpty(this.get('accountUsername')) && this.get('accountUsername').length >= this.get('minUsernameLength');
|
return !Ember.isEmpty(this.get('accountUsername')) && this.get('accountUsername').length >= this.get('minUsernameLength');
|
||||||
},
|
},
|
||||||
|
|
||||||
checkUsernameAvailability: debounce(function() {
|
checkUsernameAvailability: debounce(function() {
|
||||||
const _this = this;
|
if (this.shouldCheckUsernameAvailability()) {
|
||||||
if (this.shouldCheckUsernameMatch()) {
|
return Discourse.User.checkUsername(this.get('accountUsername'), this.get('accountEmail')).then(result => {
|
||||||
return Discourse.User.checkUsername(this.get('accountUsername'), this.get('accountEmail')).then(function(result) {
|
this.set('isDeveloper', false);
|
||||||
_this.set('isDeveloper', false);
|
|
||||||
if (result.available) {
|
if (result.available) {
|
||||||
if (result.is_developer) {
|
if (result.is_developer) {
|
||||||
_this.set('isDeveloper', true);
|
this.set('isDeveloper', true);
|
||||||
}
|
}
|
||||||
return _this.set('uniqueUsernameValidation', InputValidation.create({
|
return this.set('uniqueUsernameValidation', InputValidation.create({
|
||||||
ok: true,
|
ok: true,
|
||||||
reason: I18n.t('user.username.available')
|
reason: I18n.t('user.username.available')
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
if (result.suggestion) {
|
if (result.suggestion) {
|
||||||
return _this.set('uniqueUsernameValidation', InputValidation.create({
|
return this.set('uniqueUsernameValidation', InputValidation.create({
|
||||||
failed: true,
|
failed: true,
|
||||||
reason: I18n.t('user.username.not_available', result)
|
reason: I18n.t('user.username.not_available', result)
|
||||||
}));
|
}));
|
||||||
} else if (result.errors) {
|
|
||||||
return _this.set('uniqueUsernameValidation', InputValidation.create({
|
|
||||||
failed: true,
|
|
||||||
reason: result.errors.join(' ')
|
|
||||||
}));
|
|
||||||
} else {
|
} else {
|
||||||
return _this.set('uniqueUsernameValidation', InputValidation.create({
|
return this.set('uniqueUsernameValidation', InputValidation.create({
|
||||||
failed: true,
|
failed: true,
|
||||||
reason: I18n.t('user.username.enter_email')
|
reason: result.errors ? result.errors.join(' ') : I18n.t('user.username.not_available_no_suggestion')
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,13 +97,10 @@ export default Ember.Mixin.create({
|
||||||
}, 500),
|
}, 500),
|
||||||
|
|
||||||
// Actually wait for the async name check before we're 100% sure we're good to go
|
// Actually wait for the async name check before we're 100% sure we're good to go
|
||||||
usernameValidation: function() {
|
@computed('uniqueUsernameValidation', 'basicUsernameValidation')
|
||||||
|
usernameValidation() {
|
||||||
const basicValidation = this.get('basicUsernameValidation');
|
const basicValidation = this.get('basicUsernameValidation');
|
||||||
const uniqueUsername = this.get('uniqueUsernameValidation');
|
const uniqueUsername = this.get('uniqueUsernameValidation');
|
||||||
return uniqueUsername ? uniqueUsername : basicValidation;
|
return uniqueUsername ? uniqueUsername : basicValidation;
|
||||||
}.property('uniqueUsernameValidation', 'basicUsernameValidation'),
|
|
||||||
|
|
||||||
usernameNeedsToBeValidatedWithEmail() {
|
|
||||||
return( this.get('globalNicknameExists') || false );
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -718,13 +718,11 @@ en:
|
||||||
instructions: "unique, no spaces, short"
|
instructions: "unique, no spaces, short"
|
||||||
short_instructions: "People can mention you as @{{username}}"
|
short_instructions: "People can mention you as @{{username}}"
|
||||||
available: "Your username is available"
|
available: "Your username is available"
|
||||||
global_match: "Email matches the registered username"
|
|
||||||
global_mismatch: "Already registered. Try {{suggestion}}?"
|
|
||||||
not_available: "Not available. Try {{suggestion}}?"
|
not_available: "Not available. Try {{suggestion}}?"
|
||||||
|
not_available_no_suggestion: "Not available"
|
||||||
too_short: "Your username is too short"
|
too_short: "Your username is too short"
|
||||||
too_long: "Your username is too long"
|
too_long: "Your username is too long"
|
||||||
checking: "Checking username availability..."
|
checking: "Checking username availability..."
|
||||||
enter_email: 'Username found; enter matching email'
|
|
||||||
prefilled: "Email matches this registered username"
|
prefilled: "Email matches this registered username"
|
||||||
|
|
||||||
locale:
|
locale:
|
||||||
|
|
Loading…
Reference in New Issue