Updated registration page username to disallow unallowed characters

• Updated:
- registration page username to disallow unallowed characters (special characters, spaces, etc.) and rewrite if is written in that field
This commit is contained in:
Developer 2021-02-11 00:57:48 -05:00
parent 8a2f34d815
commit 538bcf21c9
4 changed files with 16 additions and 3 deletions

View File

@ -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 => {

View File

@ -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' }

View File

@ -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:'

View File

@ -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:'