diff --git a/src/app/components/creator/room-creator-page/room-creator-page.component.html b/src/app/components/creator/room-creator-page/room-creator-page.component.html index 0773fd256a2ef8d79cecf839a86c682c15f91a2b..eaf734408eedda04f6bed6c3183f3e7ef30b34f3 100644 --- a/src/app/components/creator/room-creator-page/room-creator-page.component.html +++ b/src/app/components/creator/room-creator-page/room-creator-page.component.html @@ -89,7 +89,7 @@ <button id="question_answer-button" mat-icon-button [disableRipple]="true" - routerLink="/creator/room/{{ room.shortId }}/comments" + routerLink="/creator/room/{{ encodedShortId }}/comments" aria-labelledby="question_answer"> <mat-icon matBadge="{{commentCounter > 0 ? commentCounter : null}}" class="main-icon" @@ -103,7 +103,7 @@ <button id="gavel-button" mat-icon-button [disableRipple]="true" - routerLink="/moderator/room/{{ room.shortId }}/moderator/comments" + routerLink="/moderator/room/{{ encodedShortId }}/moderator/comments" aria-labelledby="gavel"> <mat-icon matBadge="{{moderatorCommentCounter > 0 ? moderatorCommentCounter : null}}" class="main-icon" @@ -121,7 +121,7 @@ <button id="question_answer-button2" mat-icon-button [disableRipple]="true" - routerLink="/creator/room/{{ room.shortId }}/comments" + routerLink="/creator/room/{{ encodedShortId }}/comments" aria-labelledby="question_answer"> <mat-icon matBadge="{{commentCounter > 0 ? commentCounter : null}}" class="main-icon">question_answer diff --git a/src/app/components/creator/room-creator-page/room-creator-page.component.ts b/src/app/components/creator/room-creator-page/room-creator-page.component.ts index f47f4fab4d464d0bc4861522a7ab4564833e7817..8325a78bc740662392e23babeaedf2c22f374645 100644 --- a/src/app/components/creator/room-creator-page/room-creator-page.component.ts +++ b/src/app/components/creator/room-creator-page/room-creator-page.component.ts @@ -29,6 +29,7 @@ import { KeyboardKey } from '../../../utils/keyboard/keys'; }) export class RoomCreatorPageComponent extends RoomPageComponent implements OnInit, OnDestroy, AfterContentInit { room: Room; + encodedShortId: string; updRoom: Room; commentThreshold: number; updCommentThreshold: number; @@ -62,9 +63,9 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni ngOnInit() { window.scroll(0, 0); this.translateService.use(localStorage.getItem('currentLang')); - this.route.params.subscribe(params => { this.initializeRoom(params['shortId']); + this.encodedShortId = params['shortId']; }); this.listenerFn = this._r.listen(document, 'keyup', (event) => { const lang: string = this.translateService.currentLang; @@ -241,7 +242,7 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni selBox.style.left = '0'; selBox.style.top = '0'; selBox.style.opacity = '0'; - selBox.value = `${this.urlToCopy}${this.room.shortId}`; + selBox.value = `${this.urlToCopy}${this.encodedShortId}`; document.body.appendChild(selBox); selBox.focus(); selBox.select(); diff --git a/src/app/components/shared/_dialogs/room-create/room-create.component.html b/src/app/components/shared/_dialogs/room-create/room-create.component.html index e98a114ee00ec1f297fb1efd48f93cb8ec843005..57793f30a2dc6eaf4dc5691c3eca8661bb96c3df 100644 --- a/src/app/components/shared/_dialogs/room-create/room-create.component.html +++ b/src/app/components/shared/_dialogs/room-create/room-create.component.html @@ -42,6 +42,9 @@ <mat-hint align="start" class="error" *ngIf="shortIdAlreadyUsed"><strong>{{ 'home-page.invalid-shortid' | translate }}</strong></mat-hint> + <mat-hint align="start" + class="error" + *ngIf="shortIdCharInvalid"><strong>{{ 'home-page.invalid-char-shortid' | translate }}</strong></mat-hint> </mat-form-field> </div> </form> diff --git a/src/app/components/shared/_dialogs/room-create/room-create.component.ts b/src/app/components/shared/_dialogs/room-create/room-create.component.ts index bb3dcbb0bf28c84bdb536e628aff15ea4a3b021f..e152dfbb2a727958c90de2b65dcd0c34ac887e8e 100644 --- a/src/app/components/shared/_dialogs/room-create/room-create.component.ts +++ b/src/app/components/shared/_dialogs/room-create/room-create.component.ts @@ -21,6 +21,7 @@ export class RoomCreateComponent implements OnInit { customShortIdName: string; emptyInputs = false; shortIdAlreadyUsed = false; + shortIdCharInvalid = false; room: Room; roomId: string; user: User; @@ -68,6 +69,13 @@ export class RoomCreateComponent implements OnInit { newRoom.abbreviation = '00000000'; newRoom.description = ''; if (this.hasCustomShortId && this.customShortIdName && this.customShortIdName.length > 0) { + if (!new RegExp('[a-z,A-Z,\s,\-,\.,\_,\~]+').test(this.customShortIdName) + || this.customShortIdName.startsWith(' ') || this.customShortIdName.endsWith(' ')) { + this.shortIdCharInvalid = true; + return; + } else { + this.shortIdCharInvalid = false; + } newRoom.shortId = this.customShortIdName; } else { newRoom.shortId = undefined; @@ -75,15 +83,20 @@ export class RoomCreateComponent implements OnInit { this.roomService.addRoom(newRoom, () => { this.shortIdAlreadyUsed = true; }).subscribe(room => { + const encoded = encodeURIComponent(this.customShortIdName) + .replace('\~', '%7E') + .replace('\.', '%2E') + .replace('\_', '%5F') + .replace('\-', '%2D'); this.room = room; let msg1: string; let msg2: string; this.translateService.get('home-page.created-1').subscribe(msg => { msg1 = msg; }); this.translateService.get('home-page.created-2').subscribe(msg => { msg2 = msg; }); this.notification.show(msg1 + longRoomName + msg2); - this.authenticationService.setAccess(encodeURIComponent(this.room.shortId), UserRole.CREATOR); + this.authenticationService.setAccess(encoded, UserRole.CREATOR); this.authenticationService.assignRole(UserRole.CREATOR); - this.router.navigate(['/creator/room/' + encodeURIComponent(this.room.shortId) ]); + this.router.navigate(['/creator/room/' + encoded ]); this.closeDialog(); }); } diff --git a/src/assets/i18n/home/de.json b/src/assets/i18n/home/de.json index 9fe27e333de9930165643a54f4d9c45a3012b611..debe85fb07dbf7934412020d5f9ab952ab0bb7de 100644 --- a/src/assets/i18n/home/de.json +++ b/src/assets/i18n/home/de.json @@ -98,7 +98,8 @@ "update-available": "Eine neue Version ist verfügbar.", "custom-shortid": "Raum-Code selbst bestimmen?", "custom-shortid-placeholder": "Code-Beispiel: »A12.1.12a«", - "invalid-shortid": "Der Code ist nicht verfügbar" + "invalid-shortid": "Der Code ist nicht verfügbar", + "invalid-char-shortid": "Der Code enthält verbotene Character" }, "imprint": { "cancel": "Schließen", diff --git a/src/assets/i18n/home/en.json b/src/assets/i18n/home/en.json index 6ea85077e98e1eb25bcecbd297fa9a7b9fce319b..7aee82a75945672b3490d04064ab7206b074f284 100644 --- a/src/assets/i18n/home/en.json +++ b/src/assets/i18n/home/en.json @@ -99,7 +99,8 @@ "update-available": "An update is available.", "custom-shortid": "Set the key code yourself?", "custom-shortid-placeholder": "Example: A12.1.12a", - "invalid-shortid": "This key code is not available." + "invalid-shortid": "This key code is not available.", + "invalid-char-shortid": "This key code contains invalid characters" }, "imprint": { "cancel": "Close",