add apommier commit without messages/modal.tsx change and with useEffect in canvas commented

This commit is contained in:
Lara REALI 2023-06-26 17:32:02 +02:00
parent c5957c4813
commit e09324025d
9 changed files with 377 additions and 543 deletions

View File

@ -46,6 +46,20 @@ export class AppController {
return await this.userService.findOne(req.user.username);
}
@UseGuards(JwtAuthGuard)
@Post('/logout')
async logout(@Request() req, @Body() data: any) {
const user = await this.userService.findOne(req.user.username)
// return await this.userService.refuseInvite(user, data.username);
if (!user)
return;
if (user.sessionNumber === 1) {
user.status = 0;
}
user.sessionNumber--;
this.userService.save(user);
}
@UseGuards(JwtAuthGuard)
@Post('/user')
async getUser(@Body() data: any) {
@ -204,6 +218,7 @@ export class AppController {
async addLoss(@Request() req, @Body() data: any) {
const user = await this.userService.findOne(req.user.username);
user.loss++;
user.status = 1;
const Esp = 1 / (1 + Math.pow(10, (data.opRank - user.rank) / this.scaleFactor))
const newRank = user.rank + this.kFactor * (0 - Esp);
user.rank = newRank;
@ -223,15 +238,13 @@ export class AppController {
}
@Get('/ranking')
async getRanking()
{
async getRanking() {
return await this.userService.getRanking();
}
@UseGuards(JwtAuthGuard)
@Post('/partyInvite')
async partyInvite(@Request() req, @Body() data: any)
{
async partyInvite(@Request() req, @Body() data: any) {
const user = await this.userService.findOne(data.username);
user.partyInvite = user.partyInvite || [];
user.partyInvite.push({ username: req.user.username, gameId: data.gameId });
@ -240,8 +253,7 @@ export class AppController {
@UseGuards(JwtAuthGuard)
@Get('/partyInvite')
async getPartyInvite(@Request() req)
{
async getPartyInvite(@Request() req) {
const user = await this.userService.findOne(req.user.username);
user.partyInvite = user.partyInvite || [];
return user.partyInvite;
@ -249,8 +261,7 @@ export class AppController {
@UseGuards(JwtAuthGuard)
@Post('/deleteInvite')
async deleteInvite(@Request() req, @Body() data: any)
{
async deleteInvite(@Request() req, @Body() data: any) {
const user = await this.userService.findOne(req.user.username);
user.partyInvite = user.partyInvite.filter((item) => Object.values(item)[1] !== data.username);
this.userService.save(user);
@ -258,8 +269,7 @@ export class AppController {
@UseGuards(JwtAuthGuard)
@Post('/history')
async getHistory(@Body() data: any)
{
async getHistory(@Body() data: any) {
return await this.userService.getHistory(data.username);
}
@ -267,6 +277,8 @@ export class AppController {
@Post('/quit')
async setOffline(@Request() req) {
const user = await this.userService.findOne(req.user.username);
if (!user)
return;
user.sessionNumber--;
if (!user.sessionNumber)
user.status = 0;
@ -294,16 +306,14 @@ export class AppController {
@UseGuards(JwtAuthGuard)
@Get('/2fa')
async get2fa(@Request() req)
{
async get2fa(@Request() req) {
const user = await this.userService.findOne(req.user.username);
return user.otp_enabled;
}
@UseGuards(JwtAuthGuard)
@Post('/otp')
async createOTP(@Request() req)
{
async createOTP(@Request() req) {
const user = await this.userService.findOne(req.user.username);
const res = await generateOTP(user);
await this.userService.save(user);
@ -312,8 +322,7 @@ export class AppController {
@UseGuards(JwtAuthGuard)
@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 res = await VerifyOTP(user, data.token)
await this.userService.save(user);
@ -322,8 +331,7 @@ export class AppController {
@UseGuards(JwtAuthGuard)
@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 res = await ValidateOTP(user, data.token)
return res
@ -331,8 +339,7 @@ export class AppController {
@UseGuards(JwtAuthGuard)
@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);
user.otp_verified = false;
await this.userService.save(user);
@ -418,9 +425,12 @@ export class AppController {
@UseGuards(JwtAuthGuard)
@Post('/verifyPassword')
async verifyPassword(@Body() data: any) {
return await this.chatService.verifyPassword(data.convId, data.password)
async verifyPassword(@Request() req, @Body() data: any) {
return await this.chatService.verifyPassword(data.convId, data.password, req.user.username)
}
// async verifyPassword(@Body() data: any) {
// return await this.chatService.verifyPassword(data.convId, data.password)
// }
@UseGuards(JwtAuthGuard)
@Post('/inviteConv')

View File

@ -77,8 +77,7 @@ async banUser(convId: number, username: string) {
if (conv.owner === username)
return (0);
conv.banned = conv.banned || [];
if (conv.banned.find(item => item === username))
{
if (conv.banned.find(item => item === username)) {
conv.banned = conv.banned.filter((item) => item !== username);
this.save(conv);
return (2);
@ -108,10 +107,19 @@ async setPassword(convId: number, password: string) {
this.save(conv);
}
async verifyPassword(convId: number, password: string) {
// async verifyPassword(convId: number, password: string) {
async verifyPassword(convId: number, password: string, username: string) {
const conv = await this.findConv(convId);
return await bcrypt.compare(password, conv.password);
// return await bcrypt.compare(password, conv.password);
const ret = await bcrypt.compare(password, conv.password);
if (ret === true) {
conv.members = conv.members || [];
conv.members.push(username);
this.save(conv);
}
return ret;
}
yy
async muteUser(convId: number, username: string, time: string) {
const conv = await this.findConv(convId);

View File

@ -1,58 +0,0 @@
export const Rank = [
{
rank: '1',
name: 'jean',
},
{
rank: '2',
name: 'marc',
},
{
rank: '3',
name: 'dujardain',
},
{
rank: '4',
name: 'mom',
},
{
rank: '5',
name: 'fary',
},
{
rank: '6',
name: 'aba',
},
{
rank: '7',
name: 'preach',
},
{
rank: '1',
name: 'jean',
},
{
rank: '2',
name: 'marc',
},
{
rank: '3',
name: 'dujardain',
},
{
rank: '4',
name: 'mom',
},
{
rank: '5',
name: 'fary',
},
{
rank: '6',
name: 'aba',
},
{
rank: '7',
name: 'preach',
},
]

View File

@ -1,8 +0,0 @@
import DefaultPic from '../assets/profile.jpg';
export const UserProfile = {
Pic: DefaultPic,
UserName: 'Dipper Ratman',
}
// export default UserProfile

View File

@ -1,37 +0,0 @@
export const DBWinLoss = [
{
title: 'Victory',
score: '10 - 6',
opponent: 'chef bandit'
},
{
title: 'Defeat',
score: '9 - 10',
opponent: 'ex tueur'
},
{
title: 'Victory',
score: '10 - 0',
opponent: 'tueur'
},
{
title: 'Victory',
score: '10 - 9',
opponent: 'boulanger'
},
{
title: 'Defeat',
score: '3 - 10',
opponent: 'charcutier'
},
{
title: 'Deafet',
score: '9 - 10',
opponent: 'preach'
},
{
title: 'Victory',
score: '10 - 9',
opponent: 'aba'
},
]

View File

@ -1,9 +1,18 @@
import React from "react";
import api from "../../script/axiosApi"
function Logout(){
const logout = async () =>{
try {
await api.post("/logout")
} catch (err) {
console.log(err);
}
}
logout();
localStorage.clear();
const path = 'http://' + process.env.REACT_APP_BASE_URL + '/';
// history(path, { replace: true });

View File

@ -1,112 +1,17 @@
import React, { useCallback, useState, useEffect } from 'react';
import React, { useState, useEffect } from 'react';
import api from '../script/axiosApi.tsx';
// function DoubleAuth() {
// // const enabled = await api.get("/2fa");
// // const response = await api.get("/2fa");
// // const enabled = response.data;
// // console.log(`enable= ${enabled.data}`)
// // const enabled = 0;
// let enabled;
// useEffect(() => {
// async function get2fa()
// {
// const response = await api.get("/2fa");
// const enabled = response.data;
// console.log(`enable= ${enabled.data}`)
// }
// // const enabled = 0;
// }, [])
// useEffect(() => {
// async function get2fa()
// {
// api.get('/api/QRcode', { responseType: 'blob' })
// .then(response => {
// const reader = new FileReader();
// reader.onloadend = () => {
// setImageSrc(reader.result);
// };
// reader.readAsDataURL(response.data);
// })
// .catch(error => {
// console.error(error);
// });
// } }, []);
// // const [verificationCode, setVerificationCode] = useState('');
// // const [invalidCode, setInvalidCode] = useState(false);
// const handleSubmit = () => {
// // async (e) => {
// // e.preventDefault();
// // const result = await verifyOtp(verificationCode);
// // if (result) return (window.location = '/');
// // setInvalidCode(true);
// // },
// // [verificationCode]
// };
// let sourceCode
// if (!enabled)
// {
// api.get('/QRcode')
// .then(response => {
// sourceCode = response.data;
// console.log(sourceCode);
// })
// .catch(error => {
// console.error(error);
// });
// }
// return (
// <div>
// {!enabled && (
// <div>
// <p>Scan the QR code on your authenticator app</p>
// <img src={sourceCode} />
// </div>
// )}
// <form onSubmit={handleSubmit}>
// {/* <Input
// id="verificationCode"
// label="Verification code"
// type="text"
// value={verificationCode}
// onChange={(e) => setVerificationCode(e.target.value)}
// /> */}
// <button type="submit">Confirm</button>
// {/* {invalidCode && <p>Invalid verification code</p>} */}
// </form>
// </div>
// );
// }
// import { toFileStream } from 'qrcode';
const DoubleAuth = () => {
const [imageSrc, setImageSrc] = useState('');
// const [imageSrc, setImageSrc] = useState('');
const [imageSrc, setImageSrc] = useState<string | ArrayBuffer | null>('');
useEffect(() => {
async function getCode() {
await api.get('/QRcode', { responseType: 'blob' })
.then(response => {
const reader = new FileReader();
if (!reader)
return;
reader.onloadend = () => {
setImageSrc(reader.result);
};
@ -119,27 +24,14 @@ const DoubleAuth = () => {
getCode();
}, []);
// return (
// <div>
// {imageSrc && <img src={imageSrc} alt="QR Code" />}
// </div>
// );
// <img src={sourceCode} />
return (
<div>
<div>
<p>Scan the QR code on your authenticator app</p>
{imageSrc && <img src={imageSrc} alt="QR Code" />}
</div>
{/* <form onSubmit={handleSubmit}>
<button type="submit">Confirm</button>
</form> */}
{/* {imageSrc && <img src={imageSrc} alt="QR Code" />} */}
{imageSrc && <img src={imageSrc.toString()} alt="QR Code" />}</div>
</div>
);
};

View File

@ -1,9 +0,0 @@
import React from "react";
function Social (){
return (
<div>je suis la partie social</div>
)
}
export default Social

View File

@ -1,3 +1,4 @@
import { useEffect } from 'react';
import api from '../script/axiosApi.tsx';
import io from 'socket.io-client';
@ -9,6 +10,21 @@ interface GameProps {
function DrawCanvas(option: number, gameParam: GameProps) {
// useEffect(() => {
// const handleBeforeUnload = async (event: { preventDefault: () => void; returnValue: string; }) => {
// try {
// await api.post("/status", {status: 1});
// } catch (err) {
// console.log(err);
// }
// };
// window.addEventListener('beforeunload', handleBeforeUnload);
// return () => {
// window.removeEventListener('beforeunload', handleBeforeUnload);
// };
// }, []);
console.log(`option= ${option}`);
const superpowerModifier = option & 1; // Retrieves the superpower modifier
const obstacleModifier = (option >> 1) & 1; // Retrieves the obstacle modifier
@ -38,7 +54,7 @@ function DrawCanvas(option: number, gameParam: GameProps) {
}
console.log("start function");
const canvas = document.getElementById('myCanvas') as HTMLCanvasElement | null;;
const canvas = document.getElementById('myCanvas') as HTMLCanvasElement | null;
if (!canvas)
return ;
@ -433,6 +449,17 @@ socket.on('pong:hisPoint', (data) => {
console.log(err)
}
}
else
{
const data = {
myScore: myScore,
opScore: 5,
opName: opName,
opRank: opRank,
};
await api.post('/loss', data);
// await api.post('/status', {status: 1});
}
socket.emit('pong:disconnect', {id: myId});
window.location.replace("http://" + process.env.REACT_APP_BASE_URL + "/pong");
};