Fix feedback @moufmou
This commit is contained in:
parent
a7398fa851
commit
74d0594246
@ -177,9 +177,8 @@ export class IoSocketController {
|
||||
characterLayers = [ characterLayers ];
|
||||
}
|
||||
|
||||
const userUuid = await jwtTokenManager.getUserUuidFromToken(token);
|
||||
//TODO send ban message
|
||||
await jwtTokenManager.verifyBanUser(userUuid, IPAddress, roomId);
|
||||
const userUuid = await jwtTokenManager.getUserUuidFromToken(token, IPAddress, roomId);
|
||||
|
||||
let memberTags: string[] = [];
|
||||
let memberTextures: CharacterTexture[] = [];
|
||||
const room = await socketManager.getOrCreateRoom(roomId);
|
||||
|
@ -10,7 +10,7 @@ class JWTTokenManager {
|
||||
return Jwt.sign({userUuid: userUuid}, SECRET_KEY, {expiresIn: '200d'}); //todo: add a mechanic to refresh or recreate token
|
||||
}
|
||||
|
||||
public async getUserUuidFromToken(token: unknown): Promise<string> {
|
||||
public async getUserUuidFromToken(token: unknown, ipAddress?: string, room?: string): Promise<string> {
|
||||
|
||||
if (!token) {
|
||||
throw new Error('An authentication error happened, a user tried to connect without a token.');
|
||||
@ -50,14 +50,22 @@ class JWTTokenManager {
|
||||
|
||||
if (ADMIN_API_URL) {
|
||||
//verify user in admin
|
||||
adminApi.fetchCheckUserByToken(tokenInterface.userUuid).then(() => {
|
||||
resolve(tokenInterface.userUuid);
|
||||
}).catch((err) => {
|
||||
//anonymous user
|
||||
if (err.response && err.response.status && err.response.status === 404) {
|
||||
let promise = new Promise((resolve) => resolve());
|
||||
if(ipAddress && room) {
|
||||
promise = this.verifyBanUser(tokenInterface.userUuid, ipAddress, room);
|
||||
}
|
||||
promise.then(() => {
|
||||
adminApi.fetchCheckUserByToken(tokenInterface.userUuid).then(() => {
|
||||
resolve(tokenInterface.userUuid);
|
||||
return;
|
||||
}
|
||||
}).catch((err) => {
|
||||
//anonymous user
|
||||
if (err.response && err.response.status && err.response.status === 404) {
|
||||
resolve(tokenInterface.userUuid);
|
||||
return;
|
||||
}
|
||||
reject(err);
|
||||
});
|
||||
}).catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
} else {
|
||||
@ -67,12 +75,13 @@ class JWTTokenManager {
|
||||
});
|
||||
}
|
||||
|
||||
public async verifyBanUser(userUuid: string, ipAddress: string, room: string): Promise<unknown> {
|
||||
private verifyBanUser(userUuid: string, ipAddress: string, room: string): Promise<AdminBannedData> {
|
||||
room = room.split('/').join('_');
|
||||
return adminApi.verifyBanUser(userUuid, ipAddress, room).then((data: AdminBannedData) => {
|
||||
if (data && data.is_banned) {
|
||||
throw new Error('User was banned');
|
||||
}
|
||||
return data;
|
||||
}).catch((err) => {
|
||||
throw err;
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user