From 538bcf21c9a7fbc83affe3c074fc33ffa2281b46 Mon Sep 17 00:00:00 2001 From: Developer <> Date: Thu, 11 Feb 2021 00:57:48 -0500 Subject: [PATCH] Updated registration page username to disallow unallowed characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Updated: - registration page username to disallow unallowed characters (special characters, spaces, etc.) and rewrite if is written in that field --- app/javascript/packs/public.js | 13 +++++++++++++ app/views/auth/registrations/new.html.haml | 2 +- config/locales/simple_form.en.yml | 2 +- config/locales/simple_form.en_GB.yml | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/javascript/packs/public.js b/app/javascript/packs/public.js index 0754cb06..72d81cf6 100644 --- a/app/javascript/packs/public.js +++ b/app/javascript/packs/public.js @@ -232,6 +232,19 @@ function main ( ) { input.readonly = oldReadOnly; }); + + const handleRemoveSpecialCharactersForUsername = (e) => { + var input = e.target; + var text = input.value.replace(/[^\w\d_]/gmi, ""); + if (/\s/.test(text)) { + text = text.replace(/\s/g, ""); + } + input.value = text; + }; + + delegate(document, '#user_account_attributes_username.registration_username', 'keydown', handleRemoveSpecialCharactersForUsername); + delegate(document, '#user_account_attributes_username.registration_username', 'keyup', handleRemoveSpecialCharactersForUsername); + delegate(document, '#user_account_attributes_username.registration_username', 'change', handleRemoveSpecialCharactersForUsername); } loadPolyfills().then(main).catch(error => { diff --git a/app/views/auth/registrations/new.html.haml b/app/views/auth/registrations/new.html.haml index 3112bfdd..93815578 100644 --- a/app/views/auth/registrations/new.html.haml +++ b/app/views/auth/registrations/new.html.haml @@ -12,7 +12,7 @@ = f.simple_fields_for :account do |ff| .fields-group - = ff.input :username, wrapper: :with_label, autofocus: true, label: t('simple_form.labels.defaults.username'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.username'), :autocomplete => 'off' }, hint: t('simple_form.hints.defaults.username') + = ff.input :username, wrapper: :with_label, autofocus: true, label: t('simple_form.labels.defaults.username'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.username'), :autocomplete => 'off', :class => "registration_username" }, hint: t('simple_form.hints.defaults.username') .fields-group = f.input :email, wrapper: :with_label, label: t('simple_form.labels.defaults.email'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.email'), :autocomplete => 'off' } diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 2f36deaf..9ae5f8d2 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -35,7 +35,7 @@ en: setting_noindex: Affects your public profile and status pages setting_show_application: The application you use to gab will be displayed in the detailed view of your gabs setting_theme: Affects how Gab Social looks when you're logged in from any device. - username: Only numbers, letters, periods and underscores allowed. No spaces. + username: Only numbers, letters and underscores allowed. No spaces. whole_word: When the keyword or phrase is alphanumeric only, it will only be applied if it matches the whole word featured_tag: name: 'You might want to use one of these:' diff --git a/config/locales/simple_form.en_GB.yml b/config/locales/simple_form.en_GB.yml index 8bbba484..f326dfcb 100644 --- a/config/locales/simple_form.en_GB.yml +++ b/config/locales/simple_form.en_GB.yml @@ -35,7 +35,7 @@ en_GB: setting_noindex: Affects your public profile and status pages setting_show_application: The application you use to gab will be displayed in the detailed view of your gabs setting_theme: Affects how Gab Social looks when you're logged in from any device. - username: Only numbers, letters, periods and underscores allowed. No spaces. + username: Only numbers, letters and underscores allowed. No spaces. whole_word: When the keyword or phrase is alphanumeric only, it will only be applied if it matches the whole word featured_tag: name: 'You might want to use one of these:'