From d1a04fa06a56e48128b99005eb55d6b4780b60a2 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Fri, 8 Feb 2013 15:31:15 -0500 Subject: [PATCH] Enforce max username length on client --- .../discourse/templates/modal/create_account.js.handlebars | 2 +- .../discourse/templates/user/username.js.handlebars | 2 +- .../discourse/views/modal/create_account_view.js.coffee | 3 +++ config/locales/en.yml | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/templates/modal/create_account.js.handlebars b/app/assets/javascripts/discourse/templates/modal/create_account.js.handlebars index 71735338033..aec6b0392cd 100644 --- a/app/assets/javascripts/discourse/templates/modal/create_account.js.handlebars +++ b/app/assets/javascripts/discourse/templates/modal/create_account.js.handlebars @@ -30,7 +30,7 @@ - {{view Ember.TextField valueBinding="view.accountUsername" id="new-account-username"}} + {{view Ember.TextField valueBinding="view.accountUsername" id="new-account-username" maxlength="15"}}  {{view Discourse.InputTipView validationBinding="view.usernameValidation"}} diff --git a/app/assets/javascripts/discourse/templates/user/username.js.handlebars b/app/assets/javascripts/discourse/templates/user/username.js.handlebars index affaa199861..97c5b934b7e 100644 --- a/app/assets/javascripts/discourse/templates/user/username.js.handlebars +++ b/app/assets/javascripts/discourse/templates/user/username.js.handlebars @@ -17,7 +17,7 @@
- {{view Ember.TextField valueBinding="controller.newUsername" elementId="change_username" classNames="input-xxlarge"}} + {{view Ember.TextField valueBinding="controller.newUsername" elementId="change_username" classNames="input-xxlarge" maxlength="15"}}
{{#if controller.taken}} diff --git a/app/assets/javascripts/discourse/views/modal/create_account_view.js.coffee b/app/assets/javascripts/discourse/views/modal/create_account_view.js.coffee index 8ee6d82d5c1..6ea7fd50768 100644 --- a/app/assets/javascripts/discourse/views/modal/create_account_view.js.coffee +++ b/app/assets/javascripts/discourse/views/modal/create_account_view.js.coffee @@ -69,6 +69,9 @@ window.Discourse.CreateAccountView = window.Discourse.ModalBodyView.extend Disco # If too short return Discourse.InputValidation.create(failed: true, reason: Em.String.i18n('user.username.too_short')) if @get('accountUsername').length < 3 + # If too long + return Discourse.InputValidation.create(failed: true, reason: Em.String.i18n('user.username.too_long')) if @get('accountUsername').length > 15 + @checkUsernameAvailability() # Let's check it out asynchronously diff --git a/config/locales/en.yml b/config/locales/en.yml index 57faf80c080..0500ade667a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -504,6 +504,7 @@ en: global_mismatch: "Already registered. Try {{suggestion}}?" not_available: "Not available. Try {{suggestion}}?" 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.'