fixed pbm in room name check
This commit is contained in:
@@ -7,6 +7,7 @@ import { PartialUsersDto } from 'src/users/dto/partial-users.dto';
|
|||||||
import { createRoomDto } from './dto/createRoom.dto';
|
import { createRoomDto } from './dto/createRoom.dto';
|
||||||
import { joinRoomDto } from './dto/joinRoom.dto';
|
import { joinRoomDto } from './dto/joinRoom.dto';
|
||||||
import { setCurrentRoomDto } from './dto/setCurrentRoom.dto';
|
import { setCurrentRoomDto } from './dto/setCurrentRoom.dto';
|
||||||
|
import { ChatGateway } from './chat.gateway';
|
||||||
|
|
||||||
@Controller('chat')
|
@Controller('chat')
|
||||||
export class ChatController {
|
export class ChatController {
|
||||||
@@ -15,6 +16,7 @@ export class ChatController {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private chatService: ChatService,
|
private chatService: ChatService,
|
||||||
|
private chatGateway: ChatGateway,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.allowed_chars = "#!?-_";
|
this.allowed_chars = "#!?-_";
|
||||||
@@ -71,9 +73,13 @@ export class ChatController {
|
|||||||
{
|
{
|
||||||
console.log("- in createRoom controller");
|
console.log("- in createRoom controller");
|
||||||
|
|
||||||
let regex = new RegExp("^[a-zA-Z0-9\\s" + this.allowed_chars + "]+$/");
|
let regex_base = `[a-zA-Z0-9\\s${this.allowed_chars}]`;
|
||||||
if (!regex.test(createRoomDto.room_name))
|
let test_regex = new RegExp(`^${regex_base}+$`);
|
||||||
throw new HttpException(`Onlly special characters accepted in room name: ${this.allowed_chars}`, HttpStatus.UNPROCESSABLE_ENTITY);
|
if (test_regex.test(createRoomDto.room_name) === false)
|
||||||
|
{
|
||||||
|
let forbidden_chars = createRoomDto.room_name.replace(new RegExp(regex_base, "g"), "");
|
||||||
|
throw new HttpException(`Your room name can not contains these characters : ${forbidden_chars}`, HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
const response = await this.chatService.addUserToNewRoom(req.user.username, createRoomDto);
|
const response = await this.chatService.addUserToNewRoom(req.user.username, createRoomDto);
|
||||||
console.log("- out createRoom controller");
|
console.log("- out createRoom controller");
|
||||||
@@ -88,6 +94,9 @@ export class ChatController {
|
|||||||
console.log("- in joinRoom controller");
|
console.log("- in joinRoom controller");
|
||||||
console.log("-- room_name", joinRoomDto.room_name);
|
console.log("-- room_name", joinRoomDto.room_name);
|
||||||
const response = await this.chatService.addUserToRoom(req.user.username, joinRoomDto.room_name);
|
const response = await this.chatService.addUserToRoom(req.user.username, joinRoomDto.room_name);
|
||||||
|
|
||||||
|
//this.chatGateway.joinRoom(null, joinRoomDto.room_name);
|
||||||
|
|
||||||
console.log("- out joinRoom controller");
|
console.log("- out joinRoom controller");
|
||||||
return res.status(HttpStatus.OK).json({ room_name: joinRoomDto.room_name, message: response });
|
return res.status(HttpStatus.OK).json({ room_name: joinRoomDto.room_name, message: response });
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -9,13 +9,13 @@
|
|||||||
export let back = "";
|
export let back = "";
|
||||||
|
|
||||||
let allowed_chars = 'loading...';
|
let allowed_chars = 'loading...';
|
||||||
let regex;
|
//let regex;
|
||||||
onMount(async() => {
|
onMount(async() => {
|
||||||
let response = await fetch('/api/v2/chat/allowedchars');
|
let response = await fetch('/api/v2/chat/allowedchars');
|
||||||
let data = await response.json();
|
let data = await response.json();
|
||||||
console.log("data:", data);
|
console.log("data:", data);
|
||||||
allowed_chars = data.chars;
|
allowed_chars = data.chars;
|
||||||
regex = new RegExp(`^[a-zA-Z0-9\\s${allowed_chars}]+$`);
|
//regex = new RegExp(`^[a-zA-Z0-9\\s${allowed_chars}]+$`);
|
||||||
});
|
});
|
||||||
|
|
||||||
let room_name: string;
|
let room_name: string;
|
||||||
@@ -68,7 +68,10 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<!-- name: -->
|
<!-- name: -->
|
||||||
<label for="chat_name"><p>new room name :</p></label>
|
<label for="chat_name"><p>new room name :</p></label>
|
||||||
|
<!--
|
||||||
<input id="chat_name" bind:value={room_name} name="room_name" placeholder="allowed special characters: {allowed_chars}" pattern={regex} required>
|
<input id="chat_name" bind:value={room_name} name="room_name" placeholder="allowed special characters: {allowed_chars}" pattern={regex} required>
|
||||||
|
-->
|
||||||
|
<input id="chat_name" bind:value={room_name} name="room_name" placeholder="allowed special characters: {allowed_chars}" required>
|
||||||
<!-- [ ] pubic -->
|
<!-- [ ] pubic -->
|
||||||
<label for="chat_public" class="_radio">
|
<label for="chat_public" class="_radio">
|
||||||
<p>public</p>
|
<p>public</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user