merge
This commit is contained in:
commit
9026a81680
2
.env
2
.env
@ -44,4 +44,4 @@ REACT_HOST=0.0.0.0
|
|||||||
JWT_SECRET=secrethere
|
JWT_SECRET=secrethere
|
||||||
# REDIRECT_URI=http://localhost:80/api/auth/login
|
# REDIRECT_URI=http://localhost:80/api/auth/login
|
||||||
API_SECRET=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
|
API_SECRET=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
|
||||||
CLIENT_UID=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41
|
CLIENT_UID=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/06/17 01:00:00 by apommier #+# #+# */
|
/* Created: 2023/06/17 01:00:00 by apommier #+# #+# */
|
||||||
/* Updated: 2023/06/26 02:19:48 by sadjigui ### ########.fr */
|
/* Updated: 2023/06/26 02:57:07 by sadjigui ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ import { formatWithOptions } from 'util';
|
|||||||
|
|
||||||
@Controller('/api')
|
@Controller('/api')
|
||||||
export class AppController {
|
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, ) {}
|
||||||
@ -53,7 +53,7 @@ export class AppController {
|
|||||||
|
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
// User
|
// User
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ export class AppController {
|
|||||||
await this.chatService.createConv(conv);
|
await this.chatService.createConv(conv);
|
||||||
|
|
||||||
return await this.userService.addFriend(user, data.username);
|
return await this.userService.addFriend(user, data.username);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@ -167,7 +167,7 @@ export class AppController {
|
|||||||
async refuseInvite(@Request() req, @Body() data: any) {
|
async refuseInvite(@Request() req, @Body() data: any) {
|
||||||
// return await this.userService.getFriends(req.user.username);
|
// return await this.userService.getFriends(req.user.username);
|
||||||
// console.log(`useawdawd\n\n\nr= ${req.user.username}`)
|
// console.log(`useawdawd\n\n\nr= ${req.user.username}`)
|
||||||
const user = await this.userService.findOne(req.user.username)
|
const user = await this.userService.findOne(req.user.username)
|
||||||
return await this.userService.refuseInvite(user, data.username);
|
return await this.userService.refuseInvite(user, data.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ export class AppController {
|
|||||||
|
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
// Pong
|
// Pong
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
|
|
||||||
@ -260,7 +260,7 @@ export class AppController {
|
|||||||
|
|
||||||
const Esp = 1 / (1 + Math.pow(10, (data.opRank - user.rank) / this.scaleFactor))
|
const Esp = 1 / (1 + Math.pow(10, (data.opRank - user.rank) / this.scaleFactor))
|
||||||
const newRank = user.rank + this.kFactor * (0 - Esp);
|
const newRank = user.rank + this.kFactor * (0 - Esp);
|
||||||
|
|
||||||
user.rank = newRank;
|
user.rank = newRank;
|
||||||
console.log(`loss new rank= ${newRank}`);
|
console.log(`loss new rank= ${newRank}`);
|
||||||
console.log(`data loss = ${data}`)
|
console.log(`data loss = ${data}`)
|
||||||
@ -323,8 +323,8 @@ export class AppController {
|
|||||||
{
|
{
|
||||||
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);
|
||||||
|
|
||||||
|
|
||||||
// user.partyInvite = user.partyInvite.filter(item => Object.values(item)[1] !== req.user.username);
|
// user.partyInvite = user.partyInvite.filter(item => Object.values(item)[1] !== req.user.username);
|
||||||
console.log("user.partyInvite before", user.partyInvite)
|
console.log("user.partyInvite before", user.partyInvite)
|
||||||
user.partyInvite = user.partyInvite.filter((item) => Object.values(item)[1] !== data.username);
|
user.partyInvite = user.partyInvite.filter((item) => Object.values(item)[1] !== data.username);
|
||||||
@ -339,10 +339,10 @@ export class AppController {
|
|||||||
// 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);
|
||||||
|
|
||||||
// if (user) {
|
// if (user) {
|
||||||
// const children = user.children;
|
// const children = user.children;
|
||||||
// console.log(user);
|
// console.log(user);
|
||||||
// console.log(user.children); // or perform any operations with the children
|
// console.log(user.children); // or perform any operations with the children
|
||||||
// return children;
|
// return children;
|
||||||
// // You can also access specific properties of each child
|
// // You can also access specific properties of each child
|
||||||
@ -357,7 +357,7 @@ export class AppController {
|
|||||||
|
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
// Auth
|
// Auth
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
|
|
||||||
@ -380,7 +380,7 @@ export class AppController {
|
|||||||
console.log(`all data json version= ${myJSON}`);
|
console.log(`all data json version= ${myJSON}`);
|
||||||
console.log(`data in api = ${(await data).access_token}`);
|
console.log(`data in api = ${(await data).access_token}`);
|
||||||
// console.log(`data i = ${(await data).access_token}`)
|
// console.log(`data i = ${(await data).access_token}`)
|
||||||
const token = (await data).access_token;
|
const token = (await data).access_token;
|
||||||
// console
|
// console
|
||||||
await this.userService.save(user);
|
await this.userService.save(user);
|
||||||
return { url: 'http://' + process.env.BASE_URL + `/token?data=${encodeURIComponent(JSON.stringify(token))}` };
|
return { url: 'http://' + process.env.BASE_URL + `/token?data=${encodeURIComponent(JSON.stringify(token))}` };
|
||||||
@ -451,18 +451,26 @@ export class AppController {
|
|||||||
@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.status = 0;
|
if (!user.sessionNumber)
|
||||||
|
user.status = 0;
|
||||||
await this.userService.save(user);
|
await this.userService.save(user);
|
||||||
console.log("User quit");
|
console.log("User quit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(JwtAuthGuard)
|
||||||
|
@Post('/addSession')
|
||||||
|
async addSession(@Request() req) {
|
||||||
|
|
||||||
|
const user = await this.userService.findOne(req.user.username);
|
||||||
|
user.sessionNumber++ ;
|
||||||
|
await this.userService.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
// Chat
|
// Chat
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
//========================================================================================================
|
//========================================================================================================
|
||||||
|
|
||||||
@ -510,7 +518,7 @@ export class AppController {
|
|||||||
@Post('/message')
|
@Post('/message')
|
||||||
async postMessage(@Request() req, @Body() data: any) {
|
async postMessage(@Request() req, @Body() data: any) {
|
||||||
//if i can post post ?
|
//if i can post post ?
|
||||||
let message =
|
let message =
|
||||||
{
|
{
|
||||||
convid: data.convId,
|
convid: data.convId,
|
||||||
sender: data.sender,
|
sender: data.sender,
|
||||||
@ -521,7 +529,7 @@ export class AppController {
|
|||||||
console.log(data);
|
console.log(data);
|
||||||
return await this.chatService.createMessage(message, req.user.username);
|
return await this.chatService.createMessage(message, req.user.username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post('/member')
|
@Post('/member')
|
||||||
async getMember(@Body() data: any) {
|
async getMember(@Body() data: any) {
|
||||||
@ -529,7 +537,7 @@ export class AppController {
|
|||||||
console.log(`get member= ${data.convId}`);
|
console.log(`get member= ${data.convId}`);
|
||||||
return await this.chatService.findConv(data.convId);
|
return await this.chatService.findConv(data.convId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post('/getMessage')
|
@Post('/getMessage')
|
||||||
async getMessage(@Body() data: any) {
|
async getMessage(@Body() data: any) {
|
||||||
@ -541,11 +549,11 @@ export class AppController {
|
|||||||
|
|
||||||
return await this.chatService.getMessages(data.convId);
|
return await this.chatService.getMessages(data.convId);
|
||||||
// return await this.chatService.getConv(req.user.username);
|
// return await this.chatService.getConv(req.user.username);
|
||||||
|
|
||||||
|
|
||||||
// res.json(messages);
|
// res.json(messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post('/name')
|
@Post('/name')
|
||||||
async setName(@Body() data: any) {
|
async setName(@Body() data: any) {
|
||||||
@ -553,13 +561,13 @@ export class AppController {
|
|||||||
// data.convId
|
// data.convId
|
||||||
return await this.chatService.setName(data.convId, data.name)
|
return await this.chatService.setName(data.convId, data.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post('/password')
|
@Post('/password')
|
||||||
async setPassword(@Body() data: any) {
|
async setPassword(@Body() data: any) {
|
||||||
return await this.chatService.setPassword(data.convId, data.password)
|
return await this.chatService.setPassword(data.convId, data.password)
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post('/verifyPassword')
|
@Post('/verifyPassword')
|
||||||
async verifyPassword(@Body() data: any) {
|
async verifyPassword(@Body() data: any) {
|
||||||
@ -579,7 +587,7 @@ export class AppController {
|
|||||||
return ;
|
return ;
|
||||||
return await this.chatService.banUser(data.convId, data.username)
|
return await this.chatService.banUser(data.convId, data.username)
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post('/admin')
|
@Post('/admin')
|
||||||
async setAdmin(@Body() data: any) {
|
async setAdmin(@Body() data: any) {
|
||||||
@ -587,7 +595,7 @@ export class AppController {
|
|||||||
return ;
|
return ;
|
||||||
return await this.chatService.setAdmin(data.convId, data.username)
|
return await this.chatService.setAdmin(data.convId, data.username)
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post('/mute')
|
@Post('/mute')
|
||||||
async muteUser(@Body() data: any) {
|
async muteUser(@Body() data: any) {
|
||||||
@ -595,14 +603,14 @@ export class AppController {
|
|||||||
return ;
|
return ;
|
||||||
return await this.chatService.muteUser(data.convId, data.username, data.time)
|
return await this.chatService.muteUser(data.convId, data.username, data.time)
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post('/isAdmin')
|
@Post('/isAdmin')
|
||||||
async isAdmin(@Request() req, @Body() data: any) {
|
async isAdmin(@Request() req, @Body() data: any) {
|
||||||
console.log("isdamin= ", req.user.username, " id=", data.convId)
|
console.log("isdamin= ", req.user.username, " id=", data.convId)
|
||||||
return await this.chatService.isAdmin(data.convId, req.user.username)
|
return await this.chatService.isAdmin(data.convId, req.user.username)
|
||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Post('/private')
|
@Post('/private')
|
||||||
async setPrivate(@Body() data: any) {
|
async setPrivate(@Body() data: any) {
|
||||||
@ -627,4 +635,4 @@ export class AppController {
|
|||||||
return await this.chatService.joinChannel(data.convId, req.user.username)
|
return await this.chatService.joinChannel(data.convId, req.user.username)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,9 +16,7 @@ export class loginClass {
|
|||||||
let token = null;
|
let token = null;
|
||||||
let userId = null;
|
let userId = null;
|
||||||
let userName = null;
|
let userName = null;
|
||||||
// let = null;
|
|
||||||
|
|
||||||
|
|
||||||
const params = new URLSearchParams(url.split('?')[1]);
|
const params = new URLSearchParams(url.split('?')[1]);
|
||||||
const code = params.get('code');
|
const code = params.get('code');
|
||||||
|
|
||||||
@ -62,11 +60,11 @@ export class loginClass {
|
|||||||
password: null,
|
password: null,
|
||||||
username: userName,
|
username: userName,
|
||||||
nickname: userName,
|
nickname: userName,
|
||||||
win: 0,
|
win: 0,
|
||||||
loss: 0,
|
loss: 0,
|
||||||
rank: 1200,
|
rank: 1200,
|
||||||
userId: userId,
|
userId: userId,
|
||||||
otp_base32: null,
|
otp_base32: null,
|
||||||
children: null,
|
children: null,
|
||||||
status: 1,
|
status: 1,
|
||||||
// doubleAuth: 0,
|
// doubleAuth: 0,
|
||||||
@ -76,15 +74,16 @@ export class loginClass {
|
|||||||
friends: null,
|
friends: null,
|
||||||
blocked: null,
|
blocked: null,
|
||||||
photo: null,
|
photo: null,
|
||||||
|
sessionNumber: 1,
|
||||||
};
|
};
|
||||||
await this.usersService.create(user);
|
await this.usersService.create(user);
|
||||||
}
|
}
|
||||||
// console.log(`in login42 user= ${user}`)
|
// console.log(`in login42 user= ${user}`)
|
||||||
const myJSON = JSON.stringify(user);
|
const myJSON = JSON.stringify(user);
|
||||||
console.log(`in login42 user= ${myJSON}`)
|
console.log(`in login42 user= ${myJSON}`)
|
||||||
|
|
||||||
console.log("end of login");
|
console.log("end of login");
|
||||||
return (user);
|
return (user);
|
||||||
// return (await this.usersService.findOne(userName));
|
// return (await this.usersService.findOne(userName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/06/17 01:00:25 by apommier #+# #+# */
|
/* Created: 2023/06/17 01:00:25 by apommier #+# #+# */
|
||||||
/* Updated: 2023/06/26 02:21:38 by sadjigui ### ########.fr */
|
/* Updated: 2023/06/26 03:01:23 by sadjigui ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,7 @@ export class User {
|
|||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
nickname: string;
|
nickname: string;
|
||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
username: string;
|
username: string;
|
||||||
|
|
||||||
@ -46,22 +46,25 @@ export class User {
|
|||||||
|
|
||||||
@Column({ default: 0 })
|
@Column({ default: 0 })
|
||||||
win: number;
|
win: number;
|
||||||
|
|
||||||
@Column({ default: 0 })
|
@Column({ default: 0 })
|
||||||
loss: number;
|
loss: number;
|
||||||
|
|
||||||
|
@Column({ default: 0 })
|
||||||
|
sessionNumber: number;
|
||||||
|
|
||||||
@Column({ default: 0 })
|
@Column({ default: 0 })
|
||||||
rank: number;
|
rank: number;
|
||||||
|
|
||||||
@Column({ default: 0 }) //0 = offline | 1 = connected | 2 = in game
|
@Column({ default: 0 }) //0 = offline | 1 = connected | 2 = in game
|
||||||
status: number;
|
status: number;
|
||||||
|
|
||||||
@Column({ default: 0 })
|
@Column({ default: 0 })
|
||||||
userId: number;
|
userId: number;
|
||||||
|
|
||||||
// @Column({ default: 0 })
|
// @Column({ default: 0 })
|
||||||
// doubleAuth: number;
|
// doubleAuth: number;
|
||||||
|
|
||||||
@Column('text', { array: true, nullable: true })
|
@Column('text', { array: true, nullable: true })
|
||||||
friendRequest: string[];
|
friendRequest: string[];
|
||||||
|
|
||||||
@ -98,4 +101,4 @@ export class MatchLog {
|
|||||||
|
|
||||||
@ManyToOne(() => User, parent => parent.children)
|
@ManyToOne(() => User, parent => parent.children)
|
||||||
parent: User;
|
parent: User;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,4 +4,8 @@ REACT_APP_API_SECRET=s-s4t2ud-c7e83fdcac3fbd028f3eaa6cc8616c3c478d67cc1fcfcea088
|
|||||||
REACT_APP_CLIENT_UID=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41
|
REACT_APP_CLIENT_UID=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41
|
||||||
|
|
||||||
# REACT_APP_BASE_URL=92.143.191.152
|
# REACT_APP_BASE_URL=92.143.191.152
|
||||||
# REACT_APP_BASE_URL=192.168.1.19
|
# REACT_APP_BASE_URL=192.168.1.19
|
||||||
|
REACT_APP_INTRA_URL="https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fapi%2Fauth%2Flogin&response_type=code"
|
||||||
|
|
||||||
|
# REACT_APP_BASE_URL=92.143.191.152
|
||||||
|
# REACT_APP_BASE_URL=192.168.1.19
|
||||||
|
|||||||
@ -1,26 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import {Routes, Route} from 'react-router-dom';
|
|
||||||
import Home from "../pages/Home.jsx";
|
|
||||||
import PlayButton from "./Game/PlayButton.tsx";
|
|
||||||
import Field from "../pages/Field";
|
|
||||||
import Login42 from "../pages/Login42.js";
|
|
||||||
import Messages from "../pages/Messages.jsx";
|
|
||||||
import { useLocation } from "react-router-dom";
|
|
||||||
import {AnimatePresence} from "framer-motion";
|
|
||||||
|
|
||||||
function AnimatedRoute () {
|
|
||||||
const location = useLocation();
|
|
||||||
return (
|
|
||||||
<AnimatePresence>
|
|
||||||
<Routes location={location} key={location.pathname}>
|
|
||||||
<Route path="/" element={<Home/>}/>
|
|
||||||
<Route path="/game" element={<PlayButton />}/>
|
|
||||||
<Route path="/pong/play" element={<Field />}/>
|
|
||||||
<Route path="/login42" element={<Login42 />}/>
|
|
||||||
<Route path="/messages" element={<Messages />}/>
|
|
||||||
</Routes>
|
|
||||||
</AnimatePresence>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default AnimatedRoute
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import {Routes, Route, Navigate} from 'react-router-dom';
|
import {Routes, Route, Navigate} from 'react-router-dom';
|
||||||
import HomeLogin from "../pages/Home.js";
|
import HomeLogin from "../pages/LoginButton.tsx";
|
||||||
|
|
||||||
import Home from "../pages/Home.tsx";
|
import Home from "../pages/Home.tsx";
|
||||||
|
|
||||||
@ -19,9 +19,35 @@ import DoubleAuth from "../pages/2fa.tsx";
|
|||||||
import Game from "../pages/Game.tsx";
|
import Game from "../pages/Game.tsx";
|
||||||
import Social from "./Social/Social.tsx";
|
import Social from "./Social/Social.tsx";
|
||||||
import Logout from "./Profile/Logout.tsx";
|
import Logout from "./Profile/Logout.tsx";
|
||||||
|
import api from "../script/axiosApi.tsx"
|
||||||
|
|
||||||
|
|
||||||
function AnimatedRoute () {
|
function AnimatedRoute () {
|
||||||
// const location = useLocation();
|
// const location = useLocation();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handleBeforeUnload = async (event: { preventDefault: () => void; returnValue: string; }) => {
|
||||||
|
event.preventDefault(); // Cancel the default event behavior if needed
|
||||||
|
event.returnValue = ''; // Chrome requires a return value to display a custom message
|
||||||
|
if (!localStorage.getItem('token'))
|
||||||
|
return ;
|
||||||
|
try {
|
||||||
|
await api.post("/quit");
|
||||||
|
} catch(err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform your desired actions before the user leaves the page
|
||||||
|
// For example, you can show a confirmation dialog or save user data
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('beforeunload', handleBeforeUnload);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('beforeunload', handleBeforeUnload);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
if (!localStorage.getItem('token'))
|
if (!localStorage.getItem('token'))
|
||||||
{
|
{
|
||||||
@ -37,7 +63,7 @@ function AnimatedRoute () {
|
|||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
<Routes location={location} key={location.pathname}>
|
<Routes location={location} key={location.pathname}>
|
||||||
@ -47,7 +73,7 @@ function AnimatedRoute () {
|
|||||||
<Route path="/profile" element={<Home/>}/>
|
<Route path="/profile" element={<Home/>}/>
|
||||||
<Route path="/profile/:username" element={<Home/>}/>
|
<Route path="/profile/:username" element={<Home/>}/>
|
||||||
<Route path="/qr" element={<QrCode/>}/>
|
<Route path="/qr" element={<QrCode/>}/>
|
||||||
|
|
||||||
<Route path="/2fa" element={<DoubleAuth/>}/>
|
<Route path="/2fa" element={<DoubleAuth/>}/>
|
||||||
<Route path="/Social" element={<Social/>}/>
|
<Route path="/Social" element={<Social/>}/>
|
||||||
|
|
||||||
@ -68,4 +94,4 @@ function AnimatedRoute () {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AnimatedRoute
|
export default AnimatedRoute
|
||||||
|
|||||||
@ -19,10 +19,10 @@ function PlayButton() {
|
|||||||
path += 'superpower=true&';
|
path += 'superpower=true&';
|
||||||
}
|
}
|
||||||
|
|
||||||
const obstacleCheckbox = document.querySelector<HTMLInputElement>('input[value="obstacle"]');
|
// const obstacleCheckbox = document.querySelector<HTMLInputElement>('input[value="obstacle"]');
|
||||||
if (obstacleCheckbox && obstacleCheckbox.checked) {
|
// if (obstacleCheckbox && obstacleCheckbox.checked) {
|
||||||
path += 'obstacle=true&';
|
// path += 'obstacle=true&';
|
||||||
}
|
// }
|
||||||
|
|
||||||
const speedCheckbox = document.querySelector<HTMLInputElement>('input[value="speed"]');
|
const speedCheckbox = document.querySelector<HTMLInputElement>('input[value="speed"]');
|
||||||
if (speedCheckbox && speedCheckbox.checked) {
|
if (speedCheckbox && speedCheckbox.checked) {
|
||||||
@ -41,7 +41,8 @@ function PlayButton() {
|
|||||||
{/* !buttonClicked && <button onClick={handleButtonClick}>Draw on Canvas</button> */}
|
{/* !buttonClicked && <button onClick={handleButtonClick}>Draw on Canvas</button> */}
|
||||||
<div className='checkbox'>
|
<div className='checkbox'>
|
||||||
<p><input className="inside_checkbox" type="checkbox" value="superpower"/> Super Power <br/> ( w = wall power ) </p>
|
<p><input className="inside_checkbox" type="checkbox" value="superpower"/> Super Power <br/> ( w = wall power ) </p>
|
||||||
<p><input className="inside_checkbox" type="checkbox" value="obstacle"/> Obstacle </p>
|
|
||||||
|
<p><input className="inside_checkbox" type="checkbox" value="superpower"/> Super Power</p>
|
||||||
<p><input className="inside_checkbox" type="checkbox" value="speed"/> Faster and Faster </p>
|
<p><input className="inside_checkbox" type="checkbox" value="speed"/> Faster and Faster </p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/06/01 18:24:46 by apommier #+# #+# */
|
/* Created: 2023/06/01 18:24:46 by apommier #+# #+# */
|
||||||
/* Updated: 2023/06/24 16:00:48 by apommier ### ########.fr */
|
/* Updated: 2023/06/25 23:24:46 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ function MessageMe({message, own}: MessageMeProps){
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchProfilePicture();
|
fetchProfilePicture();
|
||||||
}, [])
|
}, []);
|
||||||
|
|
||||||
const handleButtonClick = () => {
|
const handleButtonClick = () => {
|
||||||
if (!sender)
|
if (!sender)
|
||||||
|
|||||||
@ -27,7 +27,7 @@ const dropIn = {
|
|||||||
// )
|
// )
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const ModalEdit = (handleClose) => {
|
const ModalEdit = () => {
|
||||||
// let new_name = "";
|
// let new_name = "";
|
||||||
const [nickname, setNickname] = useState("");
|
const [nickname, setNickname] = useState("");
|
||||||
const [errTaken, setErrTaken] = useState(false);
|
const [errTaken, setErrTaken] = useState(false);
|
||||||
@ -35,7 +35,7 @@ const ModalEdit = (handleClose) => {
|
|||||||
const [errTooShort, setErrTooShort] = useState(false);
|
const [errTooShort, setErrTooShort] = useState(false);
|
||||||
const closeTooShort = () => setErrTooShort(false);
|
const closeTooShort = () => setErrTooShort(false);
|
||||||
|
|
||||||
const handler = e => {
|
const handler = (e: { target: { value: React.SetStateAction<string>; }; }) => {
|
||||||
setNickname(e.target.value);
|
setNickname(e.target.value);
|
||||||
console.log("testeeeee")
|
console.log("testeeeee")
|
||||||
const postNickname = async () => {
|
const postNickname = async () => {
|
||||||
|
|||||||
@ -13,6 +13,8 @@
|
|||||||
// import { React, useState } from "react";
|
// import { React, useState } from "react";
|
||||||
import '../styles/Profile.css'
|
import '../styles/Profile.css'
|
||||||
// import '../styles/App.css'
|
// import '../styles/App.css'
|
||||||
|
import RedAlert from "../components/Alert/RedAlert.tsx";
|
||||||
|
|
||||||
import DefaultPicture from "../assets/profile.jpg";
|
import DefaultPicture from "../assets/profile.jpg";
|
||||||
import WinLoss from "../components/Profile/Win_Loss.tsx";
|
import WinLoss from "../components/Profile/Win_Loss.tsx";
|
||||||
import { motion, AnimatePresence } from 'framer-motion'
|
import { motion, AnimatePresence } from 'framer-motion'
|
||||||
@ -52,7 +54,10 @@ function Profile () {
|
|||||||
const [isLoading, setIsLoading] = useState<boolean>(true);
|
const [isLoading, setIsLoading] = useState<boolean>(true);
|
||||||
const [modalOpen, setModalOpen] = useState<boolean>(false);
|
const [modalOpen, setModalOpen] = useState<boolean>(false);
|
||||||
const [mine, setMine] = useState<boolean>(false);
|
const [mine, setMine] = useState<boolean>(false);
|
||||||
|
const [error, setError] = useState<boolean>(false);
|
||||||
|
// const [visible, setVisible] = useState<boolean>(false);
|
||||||
const close = () => setModalOpen(false);
|
const close = () => setModalOpen(false);
|
||||||
|
const closeError = () => setError(false);
|
||||||
const open = () => setModalOpen(true);
|
const open = () => setModalOpen(true);
|
||||||
|
|
||||||
const { username } = useParams();
|
const { username } = useParams();
|
||||||
@ -76,6 +81,7 @@ function Profile () {
|
|||||||
console.log('File uploaded successfully');
|
console.log('File uploaded successfully');
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
setError(true);
|
||||||
console.error('Error uploading file:', error);
|
console.error('Error uploading file:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,6 +152,14 @@ function Profile () {
|
|||||||
<>
|
<>
|
||||||
<label htmlFor="file-input" className="edit_name"><MdOutlinePhotoLibrary/></label>
|
<label htmlFor="file-input" className="edit_name"><MdOutlinePhotoLibrary/></label>
|
||||||
<input type="file" id="file-input" className="file-input" accept="image/*" onChange={handleFileChange} />
|
<input type="file" id="file-input" className="file-input" accept="image/*" onChange={handleFileChange} />
|
||||||
|
<AnimatePresence initial={false} onExitComplete={() => null}>
|
||||||
|
{error ? (
|
||||||
|
<RedAlert handleClose={closeError} text={'Error : upload failed'} />
|
||||||
|
): ("")}
|
||||||
|
|
||||||
|
</AnimatePresence>
|
||||||
|
|
||||||
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</motion.div>
|
</motion.div>
|
||||||
@ -191,7 +205,7 @@ function Home () {
|
|||||||
const tmpUser = await api.get("/profile");
|
const tmpUser = await api.get("/profile");
|
||||||
setUser(tmpUser.data);
|
setUser(tmpUser.data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const tmpUser = await api.post("/user", {username: username});
|
const tmpUser = await api.post("/user", {username: username});
|
||||||
setUser(tmpUser.data);
|
setUser(tmpUser.data);
|
||||||
@ -224,7 +238,7 @@ function Home () {
|
|||||||
):("")}
|
):("")}
|
||||||
</div>
|
</div>
|
||||||
<div className="home">
|
<div className="home">
|
||||||
<motion.div
|
<motion.div
|
||||||
// style={{
|
// style={{
|
||||||
// backdropFilter: move ? "blur(10px)" : "none",
|
// backdropFilter: move ? "blur(10px)" : "none",
|
||||||
// WebkitBackdropFilter: move ? "blur(10px)" : "none"
|
// WebkitBackdropFilter: move ? "blur(10px)" : "none"
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import '../styles/field.css';
|
|||||||
|
|
||||||
import { useLocation } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
import api from '../script/axiosApi.tsx';
|
import api from '../script/axiosApi.tsx';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
function HomeLogin()
|
function HomeLogin()
|
||||||
{
|
{
|
||||||
@ -25,9 +26,11 @@ function HomeLogin()
|
|||||||
console.log(`already token= ${localStorage.getItem('token')}`)
|
console.log(`already token= ${localStorage.getItem('token')}`)
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
console.log("yrah im here bitch");
|
||||||
|
console.log("lien = ", process.env.REACT_APP_INTRA_URL);
|
||||||
// else
|
// else
|
||||||
// let path = "https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41&redirect_uri=http%3A%2F%2F" + process.env.REACT_APP_BASE_URL + "%3A80%2Fapi%2Fauth%2Flogin&response_type=code";
|
// let path = "https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41&redirect_uri=http%3A%2F%2F" + process.env.REACT_APP_BASE_URL + "%3A80%2Fapi%2Fauth%2Flogin&response_type=code";
|
||||||
let path = "https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41&redirect_uri=http%3A%2F%2F" + process.env.REACT_APP_BASE_URL + "%2Fapi%2Fauth%2Flogin&response_type=code"
|
let path = process.env.REACT_APP_INTRA_URL || "";
|
||||||
window.location.replace(path);
|
window.location.replace(path);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -197,12 +197,12 @@ socket.on('pong:gameId', async (data) => {
|
|||||||
if (data.id === myId)
|
if (data.id === myId)
|
||||||
{
|
{
|
||||||
console.log("myId= true")
|
console.log("myId= true")
|
||||||
vX = 0.0001;
|
vX = 0.0005;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
console.log("myId= false")
|
console.log("myId= false")
|
||||||
vX = -0.0001;
|
vX = -0.0005;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@ -268,7 +268,7 @@ socket.on('pong:point', (data) => {
|
|||||||
// console.log("up point");
|
// console.log("up point");
|
||||||
myScore = data.point;
|
myScore = data.point;
|
||||||
// }
|
// }
|
||||||
vX = -0.0001;
|
vX = -0.0005;
|
||||||
vY = 0;
|
vY = 0;
|
||||||
ballX = canvas.width / 2;
|
ballX = canvas.width / 2;
|
||||||
ballY = canvas.height / 2;
|
ballY = canvas.height / 2;
|
||||||
@ -282,7 +282,7 @@ socket.on('pong:hisPoint', (data) => {
|
|||||||
// console.log("up point");
|
// console.log("up point");
|
||||||
hisScore = data.point;
|
hisScore = data.point;
|
||||||
// }
|
// }
|
||||||
vX = -0.0001;
|
vX = -0.0005;
|
||||||
vY = 0;
|
vY = 0;
|
||||||
ballX = canvas.width / 2;
|
ballX = canvas.width / 2;
|
||||||
ballY = canvas.height / 2;
|
ballY = canvas.height / 2;
|
||||||
@ -355,7 +355,7 @@ socket.on('pong:hisPoint', (data) => {
|
|||||||
point: hisScore,
|
point: hisScore,
|
||||||
}
|
}
|
||||||
socket.emit('pong:point', info);
|
socket.emit('pong:point', info);
|
||||||
vX = 0.0001;
|
vX = 0.0005;
|
||||||
}
|
}
|
||||||
|
|
||||||
function send_my_point()
|
function send_my_point()
|
||||||
@ -370,7 +370,7 @@ socket.on('pong:hisPoint', (data) => {
|
|||||||
}
|
}
|
||||||
socket.emit('pong:myPoint', info);
|
socket.emit('pong:myPoint', info);
|
||||||
myScore++;
|
myScore++;
|
||||||
vX = 0.0001;
|
vX = 0.0005;
|
||||||
vY = 0;
|
vY = 0;
|
||||||
ballX = canvas.width / 2;
|
ballX = canvas.width / 2;
|
||||||
ballY = canvas.height / 2;
|
ballY = canvas.height / 2;
|
||||||
@ -494,6 +494,7 @@ socket.on('pong:hisPoint', (data) => {
|
|||||||
// option: option,
|
// option: option,
|
||||||
// };
|
// };
|
||||||
// await api.post("status", {status: 1});
|
// await api.post("status", {status: 1});
|
||||||
|
await api.post('/status', {status: 1});
|
||||||
await api.post("deleteInvite", {username: gameParam.username})
|
await api.post("deleteInvite", {username: gameParam.username})
|
||||||
}
|
}
|
||||||
catch (err){
|
catch (err){
|
||||||
@ -648,7 +649,7 @@ async function draw(timestamp: number)
|
|||||||
}
|
}
|
||||||
ballX = canvas.width / 2;
|
ballX = canvas.width / 2;
|
||||||
ballY = canvas.height / 2;
|
ballY = canvas.height / 2;
|
||||||
vX = 0.0001;
|
vX = 0.0005;
|
||||||
vY = 0;
|
vY = 0;
|
||||||
hisScore += 1;
|
hisScore += 1;
|
||||||
send_point();
|
send_point();
|
||||||
|
|||||||
@ -16,7 +16,7 @@ function SuccessToken() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
console.log("No data");
|
console.log("No data");
|
||||||
return;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleanData = data.slice(1, -1); // Declare cleanData here
|
const cleanData = data.slice(1, -1); // Declare cleanData here
|
||||||
@ -94,7 +94,7 @@ function SuccessToken() {
|
|||||||
return <h1>Loading...</h1>;
|
return <h1>Loading...</h1>;
|
||||||
}
|
}
|
||||||
if (!data)
|
if (!data)
|
||||||
return ;
|
return (<></>);
|
||||||
const cleanData = data.slice(1, -1); // Declare cleanData here as well
|
const cleanData = data.slice(1, -1); // Declare cleanData here as well
|
||||||
|
|
||||||
if (!user.otp_verified) {
|
if (!user.otp_verified) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user