Bug fixes

- fixed #18 preloaded info messages can't be hidden
- fixed #19 no special character allowed in username
pull/21/head
Trivernis 6 years ago
parent 4e86293213
commit fe401152a5

@ -45,12 +45,12 @@ function spawnNotification(body, title) {
*/ */
async function submitUsername() { async function submitUsername() {
let unameInput = document.querySelector('#input-username'); let unameInput = document.querySelector('#input-username');
let username = unameInput.value.replace(/^\s+|\s+$/g, ''); let username = unameInput.value;
if (username.length > 1) { if (username.length > 1 && username.length <= 30) {
return await setUsername(username); return await setUsername(username);
} else { } else {
showError('You need to provide a username (minimum 2 characters)!'); showError('You need to provide a username (min. 2 characters, max. 30)!');
return false; return false;
} }
} }
@ -61,7 +61,8 @@ async function submitUsername() {
* @returns {Promise<boolean>} * @returns {Promise<boolean>}
*/ */
async function setUsername(username) { async function setUsername(username) {
let uname = username.substring(0, 30).replace(/[^\w- ;[\]]/g, ''); username = username.replace(/^\s+|\s+$/g, '');
let uname = username.replace(/[\n\t👑🌟]|^\s+|\s+$/gu, '');
if (uname.length === username.length) { if (uname.length === username.length) {
let response = await postGraphqlQuery(` let response = await postGraphqlQuery(`
mutation($username:String!) { mutation($username:String!) {
@ -83,7 +84,7 @@ async function setUsername(username) {
return false; return false;
} }
} else { } else {
showError('Your username contains illegal characters.'); showError(`Your username contains illegal characters (${username.replace(uname, '')}).`);
} }
} }

@ -1496,7 +1496,7 @@ router.graphqlResolver = async (req, res) => {
}, },
// mutations // mutations
setUsername: async ({username}) => { setUsername: async ({username}) => {
username = replaceTagSigns(username.substring(0, 30)).replace(/[^\w- ;[\]]/g, ''); // only allow 30 characters username = replaceTagSigns(username.substring(0, 30)).replace(/[\n\t👑🌟]|^\s+|\s+$/gu, ''); // only allow 30 characters
if (username.length > 0) { if (username.length > 0) {
let playerWrapper = new PlayerWrapper(playerId); let playerWrapper = new PlayerWrapper(playerId);

@ -7,6 +7,7 @@ block content
type='text' type='text'
placeholder='Enter your name' placeholder='Enter your name'
value=username value=username
maxlength=30
onkeydown='submitOnEnter(event, () => indicateStatus(submitUsername, "#username-status"))') onkeydown='submitOnEnter(event, () => indicateStatus(submitUsername, "#username-status"))')
button( button(
id='submit-username' id='submit-username'

@ -2,7 +2,7 @@ div(id='container-chat')
style(id='js-style') style(id='js-style')
div(id='chat-content') div(id='chat-content')
for message in messages for message in messages
span.chatMessage(type=message.type msg-id=message.id) span.chatMessage(msg-type=message.type msg-id=message.id)
if message.type === 'USER' if message.type === 'USER'
span.chatUsername= `${message.username}: ` span.chatUsername= `${message.username}: `
span(class=`chatMessageContent ${message.type}`)!= message.htmlContent span(class=`chatMessageContent ${message.type}`)!= message.htmlContent

Loading…
Cancel
Save