Merge pull request #2838 from lidlanca/fix_min_username

Fix: remove hardcoded minimum for username length validation
This commit is contained in:
Sam 2014-10-02 16:44:24 +10:00
commit bc703897e1
2 changed files with 4 additions and 2 deletions

View file

@ -20,6 +20,7 @@ export default DiscourseController.extend(ModalFunctionality, {
canCreateLocal: Discourse.computed.setting('enable_local_logins'), canCreateLocal: Discourse.computed.setting('enable_local_logins'),
showCreateForm: Em.computed.or('hasAuthOptions', 'canCreateLocal'), showCreateForm: Em.computed.or('hasAuthOptions', 'canCreateLocal'),
maxUsernameLength: Discourse.computed.setting('max_username_length'), maxUsernameLength: Discourse.computed.setting('max_username_length'),
minUsernameLength: Discourse.computed.setting('min_username_length'),
resetForm: function() { resetForm: function() {
@ -227,7 +228,7 @@ export default DiscourseController.extend(ModalFunctionality, {
}.property('accountUsername'), }.property('accountUsername'),
shouldCheckUsernameMatch: function() { shouldCheckUsernameMatch: function() {
return !this.blank('accountUsername') && this.get('accountUsername').length > 2; return !this.blank('accountUsername') && this.get('accountUsername').length >= this.get('minUsernameLength');
}, },
checkUsernameAvailability: Discourse.debounce(function() { checkUsernameAvailability: Discourse.debounce(function() {

View file

@ -8,12 +8,13 @@ export default ObjectController.extend({
newUsername: null, newUsername: null,
maxLength: Discourse.computed.setting('max_username_length'), maxLength: Discourse.computed.setting('max_username_length'),
minLength: Discourse.computed.setting('min_username_length'),
newUsernameEmpty: Em.computed.empty('newUsername'), newUsernameEmpty: Em.computed.empty('newUsername'),
saveDisabled: Em.computed.or('saving', 'newUsernameEmpty', 'taken', 'unchanged', 'errorMessage'), saveDisabled: Em.computed.or('saving', 'newUsernameEmpty', 'taken', 'unchanged', 'errorMessage'),
unchanged: Discourse.computed.propertyEqual('newUsername', 'username'), unchanged: Discourse.computed.propertyEqual('newUsername', 'username'),
checkTaken: function() { checkTaken: function() {
if( this.get('newUsername') && this.get('newUsername').length < 3 ) { if( this.get('newUsername') && this.get('newUsername').length < this.get('minLength') ) {
this.set('errorMessage', I18n.t('user.name.too_short')); this.set('errorMessage', I18n.t('user.name.too_short'));
} else { } else {
var self = this; var self = this;