remove old code for global username registry

This commit is contained in:
Neil Lalonde 2017-02-16 13:06:37 -05:00
parent 269f6e8c30
commit 6bb9c5ceee
3 changed files with 21 additions and 52 deletions

View File

@ -31,7 +31,6 @@ export default Ember.Controller.extend(ModalFunctionality, PasswordValidation, U
accountUsername: '',
accountPassword: '',
authOptions: null,
globalNicknameExists: false,
complete: false,
formSubmitted: false,
rejectedEmails: [],

View File

@ -1,11 +1,11 @@
import InputValidation from 'discourse/models/input-validation';
import debounce from 'discourse/lib/debounce';
import { setting } from 'discourse/lib/computed';
import { default as computed } from 'ember-addons/ember-computed-decorators';
export default Ember.Mixin.create({
uniqueUsernameValidation: null,
globalNicknameExists: false, // TODO: remove this
maxUsernameLength: setting('max_username_length'),
minUsernameLength: setting('min_username_length'),
@ -20,31 +20,12 @@ export default Ember.Mixin.create({
});
}, 500),
usernameMatch: function() {
if (this.usernameNeedsToBeValidatedWithEmail()) {
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() {
@computed('accountUsername')
basicUsernameValidation(accountUsername) {
this.set('uniqueUsernameValidation', null);
if (this.get('accountUsername') === this.get('prefilledUsername')) {
if (accountUsername === this.get('prefilledUsername')) {
return InputValidation.create({
ok: true,
reason: I18n.t('user.username.prefilled')
@ -52,14 +33,14 @@ export default Ember.Mixin.create({
}
// If blank, fail without a reason
if (Ember.isEmpty(this.get('accountUsername'))) {
if (Ember.isEmpty(accountUsername)) {
return InputValidation.create({
failed: true
});
}
// If too short
if (this.get('accountUsername').length < Discourse.SiteSettings.min_username_length) {
if (accountUsername.length < Discourse.SiteSettings.min_username_length) {
return InputValidation.create({
failed: true,
reason: I18n.t('user.username.too_short')
@ -67,7 +48,7 @@ export default Ember.Mixin.create({
}
// If too long
if (this.get('accountUsername').length > this.get('maxUsernameLength')) {
if (accountUsername.length > this.get('maxUsernameLength')) {
return InputValidation.create({
failed: true,
reason: I18n.t('user.username.too_long')
@ -80,40 +61,34 @@ export default Ember.Mixin.create({
failed: true,
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');
},
checkUsernameAvailability: debounce(function() {
const _this = this;
if (this.shouldCheckUsernameMatch()) {
return Discourse.User.checkUsername(this.get('accountUsername'), this.get('accountEmail')).then(function(result) {
_this.set('isDeveloper', false);
if (this.shouldCheckUsernameAvailability()) {
return Discourse.User.checkUsername(this.get('accountUsername'), this.get('accountEmail')).then(result => {
this.set('isDeveloper', false);
if (result.available) {
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,
reason: I18n.t('user.username.available')
}));
} else {
if (result.suggestion) {
return _this.set('uniqueUsernameValidation', InputValidation.create({
return this.set('uniqueUsernameValidation', InputValidation.create({
failed: true,
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 {
return _this.set('uniqueUsernameValidation', InputValidation.create({
return this.set('uniqueUsernameValidation', InputValidation.create({
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),
// 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 uniqueUsername = this.get('uniqueUsernameValidation');
return uniqueUsername ? uniqueUsername : basicValidation;
}.property('uniqueUsernameValidation', 'basicUsernameValidation'),
usernameNeedsToBeValidatedWithEmail() {
return( this.get('globalNicknameExists') || false );
}
});

View File

@ -718,13 +718,11 @@ en:
instructions: "unique, no spaces, short"
short_instructions: "People can mention you as @{{username}}"
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_no_suggestion: "Not available"
too_short: "Your username is too short"
too_long: "Your username is too long"
checking: "Checking username availability..."
enter_email: 'Username found; enter matching email'
prefilled: "Email matches this registered username"
locale: