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 { joinRoomDto } from './dto/joinRoom.dto';
|
||||
import { setCurrentRoomDto } from './dto/setCurrentRoom.dto';
|
||||
import { ChatGateway } from './chat.gateway';
|
||||
|
||||
@Controller('chat')
|
||||
export class ChatController {
|
||||
@@ -15,6 +16,7 @@ export class ChatController {
|
||||
|
||||
constructor(
|
||||
private chatService: ChatService,
|
||||
private chatGateway: ChatGateway,
|
||||
)
|
||||
{
|
||||
this.allowed_chars = "#!?-_";
|
||||
@@ -71,9 +73,13 @@ export class ChatController {
|
||||
{
|
||||
console.log("- in createRoom controller");
|
||||
|
||||
let regex = new RegExp("^[a-zA-Z0-9\\s" + this.allowed_chars + "]+$/");
|
||||
if (!regex.test(createRoomDto.room_name))
|
||||
throw new HttpException(`Onlly special characters accepted in room name: ${this.allowed_chars}`, HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
let regex_base = `[a-zA-Z0-9\\s${this.allowed_chars}]`;
|
||||
let test_regex = new RegExp(`^${regex_base}+$`);
|
||||
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);
|
||||
console.log("- out createRoom controller");
|
||||
@@ -88,6 +94,9 @@ export class ChatController {
|
||||
console.log("- in joinRoom controller");
|
||||
console.log("-- room_name", 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");
|
||||
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 = "";
|
||||
|
||||
let allowed_chars = 'loading...';
|
||||
let regex;
|
||||
//let regex;
|
||||
onMount(async() => {
|
||||
let response = await fetch('/api/v2/chat/allowedchars');
|
||||
let data = await response.json();
|
||||
console.log("data:", data);
|
||||
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;
|
||||
@@ -68,7 +68,10 @@
|
||||
{/if}
|
||||
<!-- name: -->
|
||||
<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}" required>
|
||||
<!-- [ ] pubic -->
|
||||
<label for="chat_public" class="_radio">
|
||||
<p>public</p>
|
||||
|
||||
Reference in New Issue
Block a user