fix log color

This commit is contained in:
Lara REALI 2023-06-26 07:26:27 +02:00
parent 49d73b92d3
commit 53106b33bc
3 changed files with 522 additions and 546 deletions

View File

@ -10,7 +10,7 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
import { Controller, Request, Req, Get, Post, UseGuards, Redirect, Res, Body, UploadedFile, UseInterceptors} from '@nestjs/common'; import { Controller, Request, Req, Get, Post, UseGuards, Redirect, Res, Body, UploadedFile, UseInterceptors } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express'; import { FileInterceptor } from '@nestjs/platform-express';
import { JwtAuthGuard } from './auth/jwt-auth.guard'; import { JwtAuthGuard } from './auth/jwt-auth.guard';
import { AuthService } from './auth/auth.service'; import { AuthService } from './auth/auth.service';
@ -44,17 +44,17 @@ export class AppController {
constructor(private authService: AuthService, constructor(private authService: AuthService,
private loginClass: loginClass, private loginClass: loginClass,
private chatService: ChatService, private chatService: ChatService,
private userService: UsersService, ) {} private userService: UsersService,) { }
kFactor = 36; kFactor = 36;
scaleFactor = 400; scaleFactor = 400;
//======================================================================================================== //========================================================================================================
//======================================================================================================== //========================================================================================================
// User // User
//======================================================================================================== //========================================================================================================
//======================================================================================================== //========================================================================================================
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Get('/profile') @Get('/profile')
@ -68,14 +68,14 @@ export class AppController {
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Post('/user') @Post('/user')
async getUser( @Body() data: any) { async getUser(@Body() data: any) {
console.log(`usernamewwww= ${data.username}`) console.log(`usernamewwww= ${data.username}`)
return await this.userService.findOne(data.username); return await this.userService.findOne(data.username);
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Get('/users') @Get('/users')
async getUsers( @Body() data: any) { async getUsers(@Body() data: any) {
console.log(`usernamewwww= ${data.username}`) console.log(`usernamewwww= ${data.username}`)
return await this.userService.findAll(); return await this.userService.findAll();
} }
@ -95,8 +95,7 @@ export class AppController {
const user = await this.userService.findOne(req.user.username) const user = await this.userService.findOne(req.user.username)
if (!user) if (!user)
return (0); return (0);
if (user.friends.find(item => item === data.username)) if (user.friends.find(item => item === data.username)) {
{
user.friendRequest = user.friendRequest.filter((item) => item !== data.username); user.friendRequest = user.friendRequest.filter((item) => item !== data.username);
this.userService.save(user); this.userService.save(user);
return (1); return (1);
@ -220,11 +219,11 @@ export class AppController {
// return await this.userService.save(user); // return await this.userService.save(user);
} }
//======================================================================================================== //========================================================================================================
//======================================================================================================== //========================================================================================================
// Pong // Pong
//======================================================================================================== //========================================================================================================
//======================================================================================================== //========================================================================================================
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Post('/win') @Post('/win')
@ -276,23 +275,20 @@ export class AppController {
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Get('/rank') @Get('/rank')
async getRank(@Request() req) async getRank(@Request() req) {
{
const user = await this.userService.findOne(req.user.username); const user = await this.userService.findOne(req.user.username);
return user.rank; return user.rank;
} }
// @UseGuards(JwtAuthGuard) // @UseGuards(JwtAuthGuard)
@Get('/ranking') @Get('/ranking')
async getRanking() async getRanking() {
{
return await this.userService.getRanking(); return await this.userService.getRanking();
} }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Post('/partyInvite') @Post('/partyInvite')
async partyInvite(@Request() req, @Body() data: any) async partyInvite(@Request() req, @Body() data: any) {
{
//find data.username and add invite to list //find data.username and add invite to list
console.log("data post priv invite=", data); console.log("data post priv invite=", data);
const user = await this.userService.findOne(data.username); const user = await this.userService.findOne(data.username);
@ -306,8 +302,7 @@ export class AppController {
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Get('/partyInvite') @Get('/partyInvite')
async getPartyInvite(@Request() req, @Body() data: any) async getPartyInvite(@Request() req, @Body() data: any) {
{
//find data.username and add invite to list //find data.username and add invite to list
const user = await this.userService.findOne(req.user.username); const user = await this.userService.findOne(req.user.username);
user.partyInvite = user.partyInvite || []; user.partyInvite = user.partyInvite || [];
@ -319,8 +314,7 @@ export class AppController {
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Post('/deleteInvite') @Post('/deleteInvite')
async deleteInvite(@Request() req, @Body() data: any) async deleteInvite(@Request() req, @Body() data: any) {
{
console.log("delete invite user= ", data.username) console.log("delete invite user= ", data.username)
const user = await this.userService.findOne(req.user.username); const user = await this.userService.findOne(req.user.username);
@ -334,8 +328,7 @@ export class AppController {
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Post('/history') @Post('/history')
async getHistory(@Body() data: any) async getHistory(@Body() data: any) {
{
// const user = await this.userService.findOne(req.user.username); // const user = await this.userService.findOne(req.user.username);
// return user.rank; // return user.rank;
return await this.userService.getHistory(data.username); return await this.userService.getHistory(data.username);
@ -355,20 +348,20 @@ export class AppController {
} }
//======================================================================================================== //========================================================================================================
//======================================================================================================== //========================================================================================================
// Auth // Auth
//======================================================================================================== //========================================================================================================
//======================================================================================================== //========================================================================================================
// import { Prisma } from "@prisma/client"; // import { Prisma } from "@prisma/client";
// import { Request, Response, NextFunction } from "express"; // import { Request, Response, NextFunction } from "express";
// import { prisma } from "../server"; // import { prisma } from "../server";
@Redirect('http://' + process.env.BASE_URL + '/token', 302) @Redirect('http://' + process.env.BASE_URL + '/token', 302)
@Get('auth/login') @Get('auth/login')
async login2(@Req() request: Request) { async login2(@Req() request: Request) {
const url = request.url; const url = request.url;
const user = await this.loginClass.Login42(url); const user = await this.loginClass.Login42(url);
@ -388,8 +381,7 @@ export class AppController {
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Get('/2fa') @Get('/2fa')
async get2fa(@Request() req) async get2fa(@Request() req) {
{
const user = await this.userService.findOne(req.user.username); const user = await this.userService.findOne(req.user.username);
return user.otp_enabled; return user.otp_enabled;
} }
@ -397,8 +389,7 @@ export class AppController {
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Post('/otp') @Post('/otp')
async createOTP(@Request() req) async createOTP(@Request() req) {
{
const user = await this.userService.findOne(req.user.username); const user = await this.userService.findOne(req.user.username);
// const user2 = await this.userService.findOne(req.user.username); // const user2 = await this.userService.findOne(req.user.username);
const res = await generateOTP(user); const res = await generateOTP(user);
@ -409,8 +400,7 @@ export class AppController {
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Post('/verifyOtp') @Post('/verifyOtp')
async verifyOTP(@Request() req, @Body() data: any) async verifyOTP(@Request() req, @Body() data: any) {
{
const user = await this.userService.findOne(req.user.username); const user = await this.userService.findOne(req.user.username);
const res = await VerifyOTP(user, data.token) const res = await VerifyOTP(user, data.token)
console.log('token in verify=', data.token) console.log('token in verify=', data.token)
@ -421,8 +411,7 @@ export class AppController {
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Post('/validateOtp') @Post('/validateOtp')
async validateOTP(@Request() req, @Body() data: any) async validateOTP(@Request() req, @Body() data: any) {
{
const user = await this.userService.findOne(req.user.username); const user = await this.userService.findOne(req.user.username);
const res = await ValidateOTP(user, data.token) const res = await ValidateOTP(user, data.token)
// await this.userService.save(user); // await this.userService.save(user);
@ -431,8 +420,7 @@ export class AppController {
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Post('/deleteOtp') @Post('/deleteOtp')
async deleteOTP(@Request() req, @Body() data: any) async deleteOTP(@Request() req, @Body() data: any) {
{
const user = await this.userService.findOne(req.user.username); const user = await this.userService.findOne(req.user.username);
user.otp_verified = false; user.otp_verified = false;
await this.userService.save(user); await this.userService.save(user);
@ -441,21 +429,21 @@ export class AppController {
// return res // return res
} }
// @UseGuards(JwtAuthGuard) // @UseGuards(JwtAuthGuard)
// @Get('/QRcode') // @Get('/QRcode')
// async createQrCode(@Request() req) // async createQrCode(@Request() req)
// { // {
// return (await generateQRcode(req)); // return (await generateQRcode(req));
// } // }
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Post('/quit') @Post('/quit')
async setOffline(@Request() req) { async setOffline(@Request() req) {
const user = await this.userService.findOne(req.user.username); const user = await this.userService.findOne(req.user.username);
user.sessionNumber-- ; user.sessionNumber--;
if (!user.sessionNumber) if (!user.sessionNumber)
user.status = 0; user.status = 0;
console.log("quit sessionNUmber :",user.sessionNumber); console.log("quit sessionNUmber :", user.sessionNumber);
await this.userService.save(user); await this.userService.save(user);
console.log("User quit"); console.log("User quit");
@ -466,17 +454,19 @@ export class AppController {
async addSession(@Request() req) { async addSession(@Request() req) {
const user = await this.userService.findOne(req.user.username); const user = await this.userService.findOne(req.user.username);
user.sessionNumber++ ; user.sessionNumber += 1;
console.log("addSession sessionNUmber :",user.sessionNumber); if (user.status !== 2) //super
user.status = 1;
console.log("addSession sessionNUmber :", user.sessionNumber);
await this.userService.save(user); await this.userService.save(user);
} }
//======================================================================================================== //========================================================================================================
//======================================================================================================== //========================================================================================================
// Chat // Chat
//======================================================================================================== //========================================================================================================
//======================================================================================================== //========================================================================================================
@UseGuards(JwtAuthGuard) @UseGuards(JwtAuthGuard)
@Post('/conv') @Post('/conv')
@ -588,7 +578,7 @@ export class AppController {
@Post('/ban') @Post('/ban')
async banUser(@Body() data: any) { async banUser(@Body() data: any) {
if (!data.username) if (!data.username)
return ; return;
return await this.chatService.banUser(data.convId, data.username) return await this.chatService.banUser(data.convId, data.username)
} }
@ -596,7 +586,7 @@ export class AppController {
@Post('/admin') @Post('/admin')
async setAdmin(@Body() data: any) { async setAdmin(@Body() data: any) {
if (!data.username) if (!data.username)
return ; return;
return await this.chatService.setAdmin(data.convId, data.username) return await this.chatService.setAdmin(data.convId, data.username)
} }
@ -604,7 +594,7 @@ export class AppController {
@Post('/mute') @Post('/mute')
async muteUser(@Body() data: any) { async muteUser(@Body() data: any) {
if (!data.username) if (!data.username)
return ; return;
return await this.chatService.muteUser(data.convId, data.username, data.time) return await this.chatService.muteUser(data.convId, data.username, data.time)
} }

View File

@ -74,14 +74,10 @@ export class loginClass {
friends: null, friends: null,
blocked: null, blocked: null,
photo: null, photo: null,
sessionNumber: 1, sessionNumber: 0,
}; };
await this.usersService.create(user); await this.usersService.create(user);
} }
// if (user.status !== 2) //super
// user.status = 1;
// user.sessionNumber++;
console.log(user.sessionNumber);
const myJSON = JSON.stringify(user); const myJSON = JSON.stringify(user);
console.log(`in login42 user= ${myJSON}`) console.log(`in login42 user= ${myJSON}`)

View File

@ -36,18 +36,7 @@ function AnimatedRoute() {
} }
}; };
window.addEventListener('beforeunload', handleBeforeUnload);
return () => {
window.removeEventListener('beforeunload', handleBeforeUnload);
};
}, []);
useEffect(() => {
const handleLoad = async () => { const handleLoad = async () => {
console.log('Page loaded');
console.log("je suis a addSession");
if (!localStorage.getItem('token')) if (!localStorage.getItem('token'))
return; return;
try { try {
@ -57,9 +46,10 @@ function AnimatedRoute() {
} }
}; };
window.addEventListener('load', handleLoad); handleLoad();
window.addEventListener('beforeunload', handleBeforeUnload);
return () => { return () => {
window.removeEventListener('load', handleLoad); window.removeEventListener('beforeunload', handleBeforeUnload);
}; };
}, []); }, []);