protected room working at least
This commit is contained in:
@@ -30,6 +30,8 @@ export class ChatController {
|
||||
new_room.owner = room.owner;
|
||||
if (room.users)
|
||||
new_room.users = room.users;
|
||||
if (room.allowed)
|
||||
new_room.allowed = room.allowed;
|
||||
return new_room;
|
||||
}
|
||||
|
||||
@@ -48,9 +50,19 @@ export class ChatController {
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
let fields = ["name", "type", "users", "protection"];
|
||||
let fields = ["name", "type", "users", "protection", "allowed_users"];
|
||||
const rooms = await this.chatService.getMyRooms(req.user.username, fields);
|
||||
|
||||
rooms.forEach(room => {
|
||||
if (room.protection)
|
||||
{
|
||||
if (room.allowed_users.includes(req.user.username))
|
||||
room.allowed = true;
|
||||
else
|
||||
room.allowed = false;
|
||||
}
|
||||
});
|
||||
|
||||
const ret_rooms = rooms.map(room => this.format_room(room));
|
||||
res.status(HttpStatus.OK).json({ rooms: ret_rooms });
|
||||
printCaller("- out ");
|
||||
@@ -107,7 +119,7 @@ export class ChatController {
|
||||
if (test_regex.test(room.name) === false)
|
||||
{
|
||||
let forbidden_chars = room.name.replace(new RegExp(regex_base, "g"), "");
|
||||
console.log(`throw error: error: true, code: 'FORBIDDEN_CHARACTERS', message: 'Your room name can not contains these characters : ${forbidden_chars}'`);
|
||||
printCaller(`throw error: error: true, code: 'FORBIDDEN_CHARACTERS', message: 'Your room name can not contains these characters : ${forbidden_chars}'`);
|
||||
throw new HttpException({ error: true, code: 'FORBIDDEN_CHARACTERS', message: `Your room name can not contains these characters : ${forbidden_chars}` }, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -117,7 +129,7 @@ export class ChatController {
|
||||
{
|
||||
if (!room.password || room.password.length === 0)
|
||||
{
|
||||
console.log(`throw error: error: true, code: 'PASSWORD_TOO_SHORT', message: 'your password is too short'`);
|
||||
printCaller(`throw error: error: true, code: 'PASSWORD_TOO_SHORT', message: 'your password is too short'`);
|
||||
throw new HttpException({ error: true, code: 'PASSWORD_TOO_SHORT', message: `your password is too short` }, HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -221,6 +233,9 @@ export class ChatController {
|
||||
if (!room_db.allowed_users.includes(req.user.username))
|
||||
await this.chatService.setPasswordValidation(req.user.username, room);
|
||||
}
|
||||
|
||||
const ret_room = this.format_room(room);
|
||||
res.status(HttpStatus.OK).json({ room: ret_room });
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ export class ChatService {
|
||||
const is_match = await bcrypt.compare(room.password, room_db.hash);
|
||||
if (!is_match)
|
||||
{
|
||||
console.log(`throw error: error: true, code: 'BAD_PASSWORD', message: 'bad password'`);
|
||||
printCaller(`throw error: error: true, code: 'BAD_PASSWORD', message: 'bad password'`);
|
||||
throw new HttpException({ error: true, code: 'BAD_PASSWORD', message: `bad password` }, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,6 @@ export function printCaller(prefix: string = "") {
|
||||
Error.captureStackTrace(e);
|
||||
let stack = e.stack.split('\n');
|
||||
let caller = stack[2].trim();
|
||||
console.log(prefix + caller);
|
||||
console.log(prefix + ' ' + caller);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,10 @@ export class roomDto
|
||||
@IsBoolean()
|
||||
protection: boolean;
|
||||
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
allowed?: boolean;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
password?: string;
|
||||
|
||||
@@ -25,6 +25,11 @@ export class Chatroom
|
||||
@IsBoolean()
|
||||
protection: boolean = false;
|
||||
|
||||
@Column({ nullable: true })
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
allowed?: boolean;
|
||||
|
||||
@Column({ nullable: true })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
|
||||
Reference in New Issue
Block a user