Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict username characters #540

Merged
merged 2 commits into from Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion background.html
Expand Up @@ -622,7 +622,7 @@ <h4 class='section-toggle section-toggle-visible'>Register a new account</h4>
<!-- Profile -->
<div class='page'>
<div class='display-name-input'>
<div class='input-header'>Enter a name that will be shown to all your contacts</div>
<div class='input-header'>Enter your public display name (alphanumeric characters and spaces only)</div>
<input class='form-control' type='text' id='display-name' placeholder='Display Name (optional)' autocomplete='off' spellcheck='false' maxlength='25'>
</div>
<div class='password-inputs'>
Expand Down
46 changes: 43 additions & 3 deletions js/views/standalone_registration_view.js
@@ -1,4 +1,4 @@
/* global Whisper, $, getAccountManager, textsecure, i18n, passwordUtil, _ */
/* global Whisper, $, getAccountManager, textsecure, i18n, passwordUtil, _, setTimeout */

/* eslint-disable more/no-then */

Expand All @@ -8,6 +8,10 @@

window.Whisper = window.Whisper || {};

const REGISTER_INDEX = 0;
const PROFILE_INDEX = 1;
let currentPageIndex = REGISTER_INDEX;

Whisper.StandaloneRegistrationView = Whisper.View.extend({
templateName: 'standalone',
className: 'full-screen-flow standalone-fullscreen',
Expand Down Expand Up @@ -52,8 +56,25 @@
this.showRegisterPage();

this.onValidatePassword();

const sanitiseNameInput = () => {
const oldVal = this.$('#display-name').val();
this.$('#display-name').val(oldVal.replace(/[^a-zA-Z0-9 ]/g, ''));
};

this.$('#display-name').get(0).oninput = () => {
sanitiseNameInput();
};

this.$('#display-name').get(0).onpaste = () => {
// Sanitise data immediately after paste because it's easier
setTimeout(() => {
sanitiseNameInput();
});
};
},
events: {
keyup: 'onKeyup',
'validation input.number': 'onValidation',
'click #request-voice': 'requestVoice',
'click #request-sms': 'requestSMSVerification',
Expand All @@ -77,12 +98,13 @@
$(this).hide();
} else {
$(this).show();
currentPageIndex = pageIndex;
}
});
},
async showRegisterPage() {
this.registrationParams = {};
this.showPage(0);
this.showPage(REGISTER_INDEX);
},
async showProfilePage(mnemonic, language) {
this.registrationParams = {
Expand All @@ -92,7 +114,25 @@
this.$passwordInput.val('');
this.$passwordConfirmationInput.val('');
this.onValidatePassword();
this.showPage(1);
this.showPage(PROFILE_INDEX);
this.$('#display-name').focus();
},
onKeyup(event) {
if (currentPageIndex !== PROFILE_INDEX) {
// Only want enter/escape keys to work on profile page
return;
}

switch (event.key) {
case 'Enter':
this.onSaveProfile();
break;
case 'Escape':
case 'Esc':
this.onBack();
break;
default:
}
},
async register(mnemonic, language) {
// Make sure the password is valid
Expand Down