allow special chars in nicks again, make nicklength customizable

This commit is contained in:
¯\_(ツ)_/¯ 2021-05-17 12:01:51 +02:00 committed by Thomas Basler
parent 9d66085623
commit b27922a15f
6 changed files with 17 additions and 11 deletions

View File

@ -52,7 +52,8 @@ services:
TURN_PASSWORD: "$TURN_PASSWORD"
TURN_SERVER: "$TURN_SERVER"
TURN_USER: "$TURN_USER"
MAX_PER_GROUP: "$MAX_PER_GROUP"
MAX_PER_GROUP: $MAX_PER_GROUP
MAX_USERNAME_LENGTH: $MAX_USERNAME_LENGTH
labels:
- "traefik.http.routers.front.rule=Host(`${BASE_DOMAIN}`) && PathPrefix(`/`)"
- "traefik.http.routers.front.entryPoints=web,websecure"

View File

@ -30,6 +30,8 @@ ARG STUN_SERVER
ARG TURN_SERVER
ARG TURN_USER
ARG TURN_PASSWORD
ARG MAX_USERNAME_LENGTH
ARG MAX_PER_GROUP
COPY front .
COPY --from=builder /usr/src/generated src/Messages/generated
@ -50,7 +52,8 @@ ARG UPLOADER_URL=uploader.$BASE_DOMAIN
RUN ./templater.sh
RUN API_URL=$API_URL UPLOADER_URL=$UPLOADER_URL ADMIN_URL=$ADMIN_URL START_ROOM_URL=$START_ROOM_URL \
JITSI_URL=$JITSI_URL JITSI_PRIVATE_MODE=$JITSI_PRIVATE_MODE \
STUN_SERVER=$STUN_SERVER TURN_SERVER=$TURN_SERVER TURN_USER=$TURN_USER TURN_PASSWORD=$TURN_PASSWORD \
STUN_SERVER=$STUN_SERVER TURN_SERVER=$TURN_SERVER TURN_USER=$TURN_USER \
TURN_PASSWORD=$TURN_PASSWORD MAX_USERNAME_LENGTH=$MAX_USERNAME_LENGTH MAX_PER_GROUP=$MAX_PER_GROUP \
yarn run build
# final production image

View File

@ -7,10 +7,8 @@ export interface CharacterTexture {
rights: string
}
export const maxUserNameLength: number = MAX_USERNAME_LENGTH;
export function isUserNameValid(value: string): boolean {
const regexp = new RegExp('^[A-Za-z0-9]{1,'+maxUserNameLength+'}$');
const regexp = new RegExp('^[A-Za-z0-9\-\+\?\_\&\!]{1,'+MAX_USERNAME_LENGTH+'}$');
return regexp.test(value);
}

View File

@ -12,8 +12,8 @@ const JITSI_URL : string|undefined = (process.env.JITSI_URL === '') ? undefined
const JITSI_PRIVATE_MODE : boolean = process.env.JITSI_PRIVATE_MODE == "true";
const POSITION_DELAY = 200; // Wait 200ms between sending position events
const MAX_EXTRAPOLATION_TIME = 100; // Extrapolate a maximum of 250ms if no new movement is sent by the player
export const MAX_USERNAME_LENGTH = parseInt(process.env.MAX_USERNAME_LENGTH || '') || 8;
export const MAX_PER_GROUP = parseInt(process.env.MAX_PER_GROUP || '4');
const MAX_USERNAME_LENGTH = parseInt(process.env.MAX_USERNAME_LENGTH || '8');
const MAX_PER_GROUP = parseInt(process.env.MAX_PER_GROUP || '4');
export const isMobile = ():boolean => ( ( window.innerWidth <= 800 ) || ( window.innerHeight <= 600 ) );
@ -31,5 +31,7 @@ export {
TURN_USER,
TURN_PASSWORD,
JITSI_URL,
JITSI_PRIVATE_MODE
JITSI_PRIVATE_MODE,
MAX_USERNAME_LENGTH,
MAX_PER_GROUP
}

View File

@ -4,6 +4,7 @@ import {ResizableScene} from "./ResizableScene";
import { localUserStore } from "../../Connexion/LocalUserStore";
import {MenuScene} from "../Menu/MenuScene";
import { isUserNameValid } from "../../Connexion/LocalUser";
import { MAX_USERNAME_LENGTH } from "../../Enum/EnvironmentVariable";
export const LoginSceneName = "LoginScene";
@ -35,7 +36,7 @@ export class LoginScene extends ResizableScene {
inputElement.value = localUserStore.getName() ?? '';
inputElement.focus();
inputElement.addEventListener('keypress', (event: KeyboardEvent) => {
if(inputElement.value.length > 7){
if(inputElement.value.length >= MAX_USERNAME_LENGTH){
event.preventDefault();
return;
}

View File

@ -1,5 +1,6 @@
import "jasmine";
import {areCharacterLayersValid, isUserNameValid, maxUserNameLength} from "../../../src/Connexion/LocalUser";
import {areCharacterLayersValid, isUserNameValid} from "../../../src/Connexion/LocalUser";
import {MAX_USERNAME_LENGTH} from "../../../src/Enum/EnvironmentVariable";
describe("isUserNameValid()", () => {
it("should validate name with letters", () => {
@ -11,7 +12,7 @@ describe("isUserNameValid()", () => {
});
it("should not validate string with too many letters", () => {
let testString = '';
for (let i = 0; i < maxUserNameLength + 2; i++) {
for (let i = 0; i < MAX_USERNAME_LENGTH + 2; i++) {
testString += 'a';
}
expect(isUserNameValid(testString)).toBe(false);