wip password protected
This commit is contained in:
@@ -115,10 +115,16 @@ export class ChatController {
|
|||||||
throw new HttpException( `Your room name can not contains these characters : ${forbidden_chars}`, HttpStatus.UNPROCESSABLE_ENTITY);
|
throw new HttpException( `Your room name can not contains these characters : ${forbidden_chars}`, HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!room.password || room.password.length === 0)
|
if (typeof room.protection === 'undefined')
|
||||||
room.protection = false;
|
room.protection = false;
|
||||||
else
|
else if (room.protection === true)
|
||||||
room.protection = true;
|
{
|
||||||
|
if (!room.password || room.password.length === 0)
|
||||||
|
{
|
||||||
|
console.log(`throw error: code: 'PASSWORD_BAD_FORMAT', message: 'your password is too short'`);
|
||||||
|
throw new HttpException({ code: 'PASSWORD_BAD_FORMAT', message: `your password is too short` }, HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
}
|
||||||
room.users = [req.user.username];
|
room.users = [req.user.username];
|
||||||
await this.chatService.addUserToNewRoom(req.user.username, room);
|
await this.chatService.addUserToNewRoom(req.user.username, room);
|
||||||
|
|
||||||
@@ -191,7 +197,7 @@ export class ChatController {
|
|||||||
console.log("throw error: code: 'PASSWORD_MISSING', message: 'this room is protected, you need to provide a password'");
|
console.log("throw error: code: 'PASSWORD_MISSING', message: 'this room is protected, you need to provide a password'");
|
||||||
throw new HttpException({ code: 'PASSWORD_MISSING', message: `this room is protected, you need to provide a password` }, HttpStatus.BAD_REQUEST);
|
throw new HttpException({ code: 'PASSWORD_MISSING', message: `this room is protected, you need to provide a password` }, HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
if (!room_db.allowed_users.contains(req.user.username))
|
if (!room_db.allowed_users.includes(req.user.username))
|
||||||
await this.chatService.setPasswordValidation(req.user.username, room);
|
await this.chatService.setPasswordValidation(req.user.username, room);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ export class ChatService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const rooms = await queryBuilder.getMany();
|
const rooms = await queryBuilder.getMany();
|
||||||
console.log("--- rooms:", rooms);
|
|
||||||
|
|
||||||
console.log("-- out getMyRooms service");
|
console.log("-- out getMyRooms service");
|
||||||
return rooms;
|
return rooms;
|
||||||
@@ -69,7 +68,6 @@ export class ChatService {
|
|||||||
const rooms = await this.chatroomRepository
|
const rooms = await this.chatroomRepository
|
||||||
.createQueryBuilder('chatroom')
|
.createQueryBuilder('chatroom')
|
||||||
.getMany();
|
.getMany();
|
||||||
console.log("--- rooms:", rooms);
|
|
||||||
|
|
||||||
console.log("-- out getAllRooms service");
|
console.log("-- out getAllRooms service");
|
||||||
return rooms;
|
return rooms;
|
||||||
@@ -85,7 +83,6 @@ export class ChatService {
|
|||||||
.where('chatroom.type NOT IN (:...type)', { type: ['private', 'direct'] })
|
.where('chatroom.type NOT IN (:...type)', { type: ['private', 'direct'] })
|
||||||
.andWhere('chatroom.users NOT LIKE :user_name', { user_name: `%${username}%` })
|
.andWhere('chatroom.users NOT LIKE :user_name', { user_name: `%${username}%` })
|
||||||
.getMany();
|
.getMany();
|
||||||
console.log("--- rooms:", rooms);
|
|
||||||
|
|
||||||
console.log("-- out getAllNotMyRooms service");
|
console.log("-- out getAllNotMyRooms service");
|
||||||
return rooms;
|
return rooms;
|
||||||
@@ -95,11 +92,6 @@ export class ChatService {
|
|||||||
{
|
{
|
||||||
console.log("-- in getAllOtherRoomsAndUsers service");
|
console.log("-- in getAllOtherRoomsAndUsers service");
|
||||||
|
|
||||||
const temp = await this.chatroomRepository
|
|
||||||
.createQueryBuilder('chatroom')
|
|
||||||
.getMany();
|
|
||||||
console.log("all rooms:", temp);
|
|
||||||
|
|
||||||
const all_rooms = await this.getAllNotMyRooms(username);
|
const all_rooms = await this.getAllNotMyRooms(username);
|
||||||
const all_users = await this.getAllUsersNotMyRooms(username);
|
const all_users = await this.getAllUsersNotMyRooms(username);
|
||||||
|
|
||||||
@@ -116,7 +108,6 @@ export class ChatService {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
let rooms: roomDto[] = row_rooms.concat(users);
|
let rooms: roomDto[] = row_rooms.concat(users);
|
||||||
console.log("--- rooms:", rooms);
|
|
||||||
|
|
||||||
console.log("-- in getAllOtherRoomsAndUsers service");
|
console.log("-- in getAllOtherRoomsAndUsers service");
|
||||||
return rooms;
|
return rooms;
|
||||||
@@ -140,9 +131,7 @@ export class ChatService {
|
|||||||
{
|
{
|
||||||
console.log("-- in getCurrentRoomName service");
|
console.log("-- in getCurrentRoomName service");
|
||||||
|
|
||||||
console.log("username:", username);
|
|
||||||
const user_db = await this.getUserByName(username);
|
const user_db = await this.getUserByName(username);
|
||||||
console.log("user_db:", user_db);
|
|
||||||
|
|
||||||
console.log("-- out getCurrentRoomName service");
|
console.log("-- out getCurrentRoomName service");
|
||||||
return user_db.currentRoom;
|
return user_db.currentRoom;
|
||||||
@@ -152,7 +141,6 @@ export class ChatService {
|
|||||||
{
|
{
|
||||||
console.log("-- in getRoomByName service");
|
console.log("-- in getRoomByName service");
|
||||||
|
|
||||||
console.log("room_name:", room_name);
|
|
||||||
const queryBuilder = this.chatroomRepository
|
const queryBuilder = this.chatroomRepository
|
||||||
.createQueryBuilder('chatroom')
|
.createQueryBuilder('chatroom')
|
||||||
.where('chatroom.name = :name', { name: room_name });
|
.where('chatroom.name = :name', { name: room_name });
|
||||||
@@ -164,7 +152,6 @@ export class ChatService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const room = await queryBuilder.getOne();
|
const room = await queryBuilder.getOne();
|
||||||
console.log("room:", room);
|
|
||||||
|
|
||||||
console.log("-- out getRoomByName service");
|
console.log("-- out getRoomByName service");
|
||||||
return room;
|
return room;
|
||||||
@@ -235,6 +222,7 @@ export class ChatService {
|
|||||||
let hash;
|
let hash;
|
||||||
if (room.protection)
|
if (room.protection)
|
||||||
{
|
{
|
||||||
|
console.log("in room protection hash");
|
||||||
if (room.type === 'direct')
|
if (room.type === 'direct')
|
||||||
{
|
{
|
||||||
console.log("throw error: code: 'DIRECT_PASSWORD_FORBIDDEN', message: 'you cannot set a password in a direct message room'");
|
console.log("throw error: code: 'DIRECT_PASSWORD_FORBIDDEN', message: 'you cannot set a password in a direct message room'");
|
||||||
@@ -361,7 +349,6 @@ export class ChatService {
|
|||||||
.createQueryBuilder('user')
|
.createQueryBuilder('user')
|
||||||
.where('user.username NOT IN (:...usernames)', { usernames: usernames })
|
.where('user.username NOT IN (:...usernames)', { usernames: usernames })
|
||||||
.getMany();
|
.getMany();
|
||||||
console.log("--- users:", users);
|
|
||||||
|
|
||||||
console.log("-- out getAllUsersNotMyRooms service");
|
console.log("-- out getAllUsersNotMyRooms service");
|
||||||
return users;
|
return users;
|
||||||
@@ -379,7 +366,6 @@ export class ChatService {
|
|||||||
.createQueryBuilder('user')
|
.createQueryBuilder('user')
|
||||||
.where('user.username NOT IN (:...usernames)', { usernames: usernames })
|
.where('user.username NOT IN (:...usernames)', { usernames: usernames })
|
||||||
.getMany();
|
.getMany();
|
||||||
console.log("--- users:", users);
|
|
||||||
|
|
||||||
console.log("-- out getAllUsersNotInRoom service");
|
console.log("-- out getAllUsersNotInRoom service");
|
||||||
return users;
|
return users;
|
||||||
@@ -413,7 +399,7 @@ export class ChatService {
|
|||||||
|
|
||||||
async socketJoinRoom(socket: socketDto, room_name: string): Promise<void>
|
async socketJoinRoom(socket: socketDto, room_name: string): Promise<void>
|
||||||
{
|
{
|
||||||
console.log('- in socketJoinRoom service');
|
console.log('-- in socketJoinRoom service');
|
||||||
|
|
||||||
socket.leave(socket.room);
|
socket.leave(socket.room);
|
||||||
socket.join(room_name);
|
socket.join(room_name);
|
||||||
@@ -422,7 +408,7 @@ export class ChatService {
|
|||||||
await socket.to(socket.room).emit('message', "SERVER", message);
|
await socket.to(socket.room).emit('message', "SERVER", message);
|
||||||
await this.addMessageToRoom(room_name, "SERVER", message);
|
await this.addMessageToRoom(room_name, "SERVER", message);
|
||||||
|
|
||||||
console.log('- out socketJoinRoom service');
|
console.log('-- out socketJoinRoom service');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export class roomDto
|
|||||||
@IsArray()
|
@IsArray()
|
||||||
@IsString({ each: true })
|
@IsString({ each: true })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
allowed_users: string[]; // usernames
|
allowed_users?: string[]; // usernames
|
||||||
|
|
||||||
@IsArray()
|
@IsArray()
|
||||||
//@IsInstance(messagesDto, { each: true })
|
//@IsInstance(messagesDto, { each: true })
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export class Chatroom
|
|||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
protection: boolean = false;
|
protection: boolean = false;
|
||||||
|
|
||||||
@Column()
|
@Column({ nullable: true })
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
hash?: string;
|
hash?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user