From 415135016259ea0c7217389b726dc3e88e9f9afc Mon Sep 17 00:00:00 2001 From: Alexandre POMMIER Date: Mon, 26 Jun 2023 01:31:46 +0200 Subject: [PATCH 1/4] fix login with other app, pong greater speed at start, fix in game status ?, rename home.js to loginbutton.tsx --- .env | 21 ++++++------ containers/api/src/app.controller.ts | 4 +-- containers/api/src/auth/login42.ts | 4 +-- containers/react/.env | 9 +++--- .../react/src/components/AnimatedRoute.tsx | 26 --------------- containers/react/src/components/App.tsx | 32 +++++++++++++++++-- .../react/src/components/Game/PlayButton.tsx | 16 +++++----- .../react/src/components/Messages/Message.tsx | 4 +-- .../react/src/components/Profile/EditName.tsx | 4 +-- .../src/pages/{Home.js => LoginButton.tsx} | 5 ++- containers/react/src/pages/canvas.tsx | 15 +++++---- containers/react/src/script/tokenSuccess.tsx | 4 +-- 12 files changed, 75 insertions(+), 69 deletions(-) delete mode 100644 containers/react/src/components/AnimatedRoute.tsx rename containers/react/src/pages/{Home.js => LoginButton.tsx} (86%) diff --git a/.env b/.env index d5dc4963..8f4c4911 100644 --- a/.env +++ b/.env @@ -7,17 +7,18 @@ # POSTGRES_PASSWORD=pass # POSTGRES_DB=postgreDB # POSTGRES_ROOT_PASSWORD=pass -# POSTGRES_HOST=localhost +# POSTGRES_HOST=bess-f2r5s13 # POSTGRES_HOST_AUTH_METHOD=trust #URL NGINX_ENVSUBST_TEMPLATE_SUFFIX=".conf" -# BASE_URL=http://localhost -# SOCKET_URL=localhost:8080 -BASE_URL=localhost:8080 -REACT_APP_BASE_URL=localhost:8080 -REDIRECT_URI=http://localhost:8080/api/auth/login +# BASE_URL=http://bess-f2r5s13 +# SOCKET_URL=bess-f2r5s13:8080 +BASE_URL=bess-f2r5s13:8080 +REACT_APP_BASE_URL=bess-f2r5s13:8080 +REDIRECT_URI=http://bess-f2r5s13:8080/api/auth/login +INTRA_URL="https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-2bd3c5d4f41e776f2e3d5d699d2a8421f6d0c0468ec882516d9ca89b0c211789&redirect_uri=http%3A%2F%2Fbess-f2r5s13%3A8080%2Fapi%2Fauth%2Flogin&response_type=code" #postgres var # POSTGRES_HOST=127.0.0.1 # DB_TYPE=postgres @@ -34,7 +35,7 @@ NGINX_PORT=8080 PONG_PORT=4000 CHAT_PORT=4001 POSTGRES_PORT=5432 - + #???? RUN_MIGRATIONS=true REACT_HOST=0.0.0.0 @@ -42,6 +43,6 @@ REACT_HOST=0.0.0.0 #auth var JWT_SECRET=secrethere -# REDIRECT_URI=http://localhost:80/api/auth/login -API_SECRET=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 -CLIENT_UID=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41 \ No newline at end of file +# REDIRECT_URI=http://bess-f2r5s13:80/api/auth/login +API_SECRET=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 +CLIENT_UID=u-s4t2ud-2bd3c5d4f41e776f2e3d5d699d2a8421f6d0c0468ec882516d9ca89b0c211789 diff --git a/containers/api/src/app.controller.ts b/containers/api/src/app.controller.ts index c522a655..403506c0 100644 --- a/containers/api/src/app.controller.ts +++ b/containers/api/src/app.controller.ts @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/17 01:00:00 by apommier #+# #+# */ -/* Updated: 2023/06/25 00:10:18 by apommier ### ########.fr */ +/* Updated: 2023/06/26 00:47:07 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -380,7 +380,7 @@ export class AppController { console.log(`all data json version= ${myJSON}`); console.log(`data in api = ${(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 await this.userService.save(user); return { url: 'http://' + process.env.BASE_URL + `/token?data=${encodeURIComponent(JSON.stringify(token))}` }; diff --git a/containers/api/src/auth/login42.ts b/containers/api/src/auth/login42.ts index 165bd7fb..6bdbdc1d 100644 --- a/containers/api/src/auth/login42.ts +++ b/containers/api/src/auth/login42.ts @@ -16,9 +16,9 @@ export class loginClass { let token = null; let userId = null; let userName = null; - // let = null; - + console.log("process.env.REDIRECT_URI=", process.env.REDIRECT_URI) + const params = new URLSearchParams(url.split('?')[1]); const code = params.get('code'); diff --git a/containers/react/.env b/containers/react/.env index 191f18bd..0ad277ad 100644 --- a/containers/react/.env +++ b/containers/react/.env @@ -1,7 +1,8 @@ -REACT_APP_BASE_URL=localhost:8080 -REACT_APP_SOCKET_URL=localhost -REACT_APP_API_SECRET=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 -REACT_APP_CLIENT_UID=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41 +REACT_APP_BASE_URL=bess-f2r5s13:8080 +REACT_APP_SOCKET_URL=bess-f2r5s13 +REACT_APP_API_SECRET=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 +REACT_APP_CLIENT_UID=u-s4t2ud-2bd3c5d4f41e776f2e3d5d699d2a8421f6d0c0468ec882516d9ca89b0c211789 +REACT_APP_INTRA_URL="https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-2bd3c5d4f41e776f2e3d5d699d2a8421f6d0c0468ec882516d9ca89b0c211789&redirect_uri=http%3A%2F%2Fbess-f2r5s13%3A8080%2Fapi%2Fauth%2Flogin&response_type=code" # REACT_APP_BASE_URL=92.143.191.152 # REACT_APP_BASE_URL=192.168.1.19 \ No newline at end of file diff --git a/containers/react/src/components/AnimatedRoute.tsx b/containers/react/src/components/AnimatedRoute.tsx deleted file mode 100644 index 7201aacc..00000000 --- a/containers/react/src/components/AnimatedRoute.tsx +++ /dev/null @@ -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 ( - - - }/> - }/> - }/> - }/> - }/> - - - ) -} - -export default AnimatedRoute \ No newline at end of file diff --git a/containers/react/src/components/App.tsx b/containers/react/src/components/App.tsx index 37d07f0b..a2d017a2 100644 --- a/containers/react/src/components/App.tsx +++ b/containers/react/src/components/App.tsx @@ -1,6 +1,6 @@ -import React from "react"; +import React, { useEffect } from "react"; 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"; @@ -20,8 +20,34 @@ import Game from "../pages/Game.tsx"; import Social from "./Social/Social.tsx"; import Logout from "./Profile/Logout.tsx"; + + function AnimatedRoute () { // const location = useLocation(); + + useEffect(() => { + const handleBeforeUnload = (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 { + + } 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(); if (!localStorage.getItem('token')) { @@ -37,7 +63,7 @@ function AnimatedRoute () { ) } - + return ( diff --git a/containers/react/src/components/Game/PlayButton.tsx b/containers/react/src/components/Game/PlayButton.tsx index c42523c2..28010cdd 100644 --- a/containers/react/src/components/Game/PlayButton.tsx +++ b/containers/react/src/components/Game/PlayButton.tsx @@ -18,12 +18,12 @@ function PlayButton() { if (superpowerCheckbox && superpowerCheckbox.checked) { path += 'superpower=true&'; } - - const obstacleCheckbox = document.querySelector('input[value="obstacle"]'); - if (obstacleCheckbox && obstacleCheckbox.checked) { - path += 'obstacle=true&'; - } - + + // const obstacleCheckbox = document.querySelector('input[value="obstacle"]'); + // if (obstacleCheckbox && obstacleCheckbox.checked) { + // path += 'obstacle=true&'; + // } + const speedCheckbox = document.querySelector('input[value="speed"]'); if (speedCheckbox && speedCheckbox.checked) { path += 'speed=true&'; @@ -40,8 +40,8 @@ function PlayButton() { {/* !buttonClicked && */}
-

Super Power

-

Obstacle

+

Super Power

+ {/*

Obstacle

*/}

Faster and Faster

diff --git a/containers/react/src/components/Messages/Message.tsx b/containers/react/src/components/Messages/Message.tsx index 53437504..7483bb16 100644 --- a/containers/react/src/components/Messages/Message.tsx +++ b/containers/react/src/components/Messages/Message.tsx @@ -6,7 +6,7 @@ /* 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(); - }, []) + }, []); const handleButtonClick = () => { if (!sender) diff --git a/containers/react/src/components/Profile/EditName.tsx b/containers/react/src/components/Profile/EditName.tsx index da364971..823b1bd7 100644 --- a/containers/react/src/components/Profile/EditName.tsx +++ b/containers/react/src/components/Profile/EditName.tsx @@ -27,7 +27,7 @@ const dropIn = { // ) // } -const ModalEdit = (handleClose) => { +const ModalEdit = () => { // let new_name = ""; const [nickname, setNickname] = useState(""); const [errTaken, setErrTaken] = useState(false); @@ -35,7 +35,7 @@ const ModalEdit = (handleClose) => { const [errTooShort, setErrTooShort] = useState(false); const closeTooShort = () => setErrTooShort(false); - const handler = e => { + const handler = (e: { target: { value: React.SetStateAction; }; }) => { setNickname(e.target.value); console.log("testeeeee") const postNickname = async () => { diff --git a/containers/react/src/pages/Home.js b/containers/react/src/pages/LoginButton.tsx similarity index 86% rename from containers/react/src/pages/Home.js rename to containers/react/src/pages/LoginButton.tsx index b848c466..1b13b74e 100644 --- a/containers/react/src/pages/Home.js +++ b/containers/react/src/pages/LoginButton.tsx @@ -3,6 +3,7 @@ import '../styles/field.css'; import { useLocation } from 'react-router-dom'; import api from '../script/axiosApi.tsx'; +import React from 'react'; function HomeLogin() { @@ -25,9 +26,11 @@ function HomeLogin() console.log(`already token= ${localStorage.getItem('token')}`) return ; } + console.log("yrah im here bitch"); + console.log("lien = ", process.env.REACT_APP_INTRA_URL); // 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 + "%2Fapi%2Fauth%2Flogin&response_type=code" + let path = process.env.REACT_APP_INTRA_URL || ""; window.location.replace(path); }; diff --git a/containers/react/src/pages/canvas.tsx b/containers/react/src/pages/canvas.tsx index a5884189..b80ee308 100644 --- a/containers/react/src/pages/canvas.tsx +++ b/containers/react/src/pages/canvas.tsx @@ -197,12 +197,12 @@ socket.on('pong:gameId', async (data) => { if (data.id === myId) { console.log("myId= true") - vX = 0.0001; + vX = 0.0005; } else { console.log("myId= false") - vX = -0.0001; + vX = -0.0005; } } catch (error) { console.log(error); @@ -268,7 +268,7 @@ socket.on('pong:point', (data) => { // console.log("up point"); myScore = data.point; // } - vX = -0.0001; + vX = -0.0005; vY = 0; ballX = canvas.width / 2; ballY = canvas.height / 2; @@ -282,7 +282,7 @@ socket.on('pong:hisPoint', (data) => { // console.log("up point"); hisScore = data.point; // } - vX = -0.0001; + vX = -0.0005; vY = 0; ballX = canvas.width / 2; ballY = canvas.height / 2; @@ -355,7 +355,7 @@ socket.on('pong:hisPoint', (data) => { point: hisScore, } socket.emit('pong:point', info); - vX = 0.0001; + vX = 0.0005; } function send_my_point() @@ -370,7 +370,7 @@ socket.on('pong:hisPoint', (data) => { } socket.emit('pong:myPoint', info); myScore++; - vX = 0.0001; + vX = 0.0005; vY = 0; ballX = canvas.width / 2; ballY = canvas.height / 2; @@ -494,6 +494,7 @@ socket.on('pong:hisPoint', (data) => { // option: option, // }; // await api.post("status", {status: 1}); + await api.post('/status', {status: 1}); await api.post("deleteInvite", {username: gameParam.username}) } catch (err){ @@ -648,7 +649,7 @@ async function draw(timestamp: number) } ballX = canvas.width / 2; ballY = canvas.height / 2; - vX = 0.0001; + vX = 0.0005; vY = 0; hisScore += 1; send_point(); diff --git a/containers/react/src/script/tokenSuccess.tsx b/containers/react/src/script/tokenSuccess.tsx index 8c3a5f09..4f7ff0ed 100644 --- a/containers/react/src/script/tokenSuccess.tsx +++ b/containers/react/src/script/tokenSuccess.tsx @@ -16,7 +16,7 @@ function SuccessToken() { useEffect(() => { if (!data) { console.log("No data"); - return; + return ; } const cleanData = data.slice(1, -1); // Declare cleanData here @@ -94,7 +94,7 @@ function SuccessToken() { return

Loading...

; } if (!data) - return ; + return (<>); const cleanData = data.slice(1, -1); // Declare cleanData here as well if (!user.otp_verified) { From 322aecc1828c16528ee28f776416e33d31d81af3 Mon Sep 17 00:00:00 2001 From: Lara REALI Date: Mon, 26 Jun 2023 02:22:47 +0200 Subject: [PATCH 2/4] quit + alert +addsesion --- containers/api/src/app.controller.ts | 65 ++++++++++++++----------- containers/api/src/auth/login42.ts | 11 +++-- containers/api/src/model/user.entity.ts | 15 +++--- containers/react/src/pages/Home.tsx | 18 ++++++- 4 files changed, 68 insertions(+), 41 deletions(-) diff --git a/containers/api/src/app.controller.ts b/containers/api/src/app.controller.ts index c522a655..bd274e02 100644 --- a/containers/api/src/app.controller.ts +++ b/containers/api/src/app.controller.ts @@ -42,7 +42,7 @@ import { formatWithOptions } from 'util'; @Controller('/api') export class AppController { - constructor(private authService: AuthService, + constructor(private authService: AuthService, private loginClass: loginClass, private chatService: ChatService, private userService: UsersService, ) {} @@ -53,7 +53,7 @@ export class AppController { //======================================================================================================== //======================================================================================================== -// User +// User //======================================================================================================== //======================================================================================================== @@ -127,7 +127,7 @@ export class AppController { await this.chatService.createConv(conv); return await this.userService.addFriend(user, data.username); - + } @UseGuards(JwtAuthGuard) @@ -167,7 +167,7 @@ export class AppController { async refuseInvite(@Request() req, @Body() data: any) { // return await this.userService.getFriends(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); } @@ -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 newRank = user.rank + this.kFactor * (0 - Esp); - + user.rank = newRank; console.log(`loss new rank= ${newRank}`); console.log(`data loss = ${data}`) @@ -323,8 +323,8 @@ export class AppController { { console.log("delete invite user= ", data.username) const user = await this.userService.findOne(req.user.username); - - + + // user.partyInvite = user.partyInvite.filter(item => Object.values(item)[1] !== req.user.username); console.log("user.partyInvite before", user.partyInvite) 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); // return user.rank; return await this.userService.getHistory(data.username); - + // if (user) { // const children = user.children; - // console.log(user); + // console.log(user); // console.log(user.children); // or perform any operations with the children // return children; // // You can also access specific properties of each child @@ -357,7 +357,7 @@ export class AppController { //======================================================================================================== //======================================================================================================== -// Auth +// Auth //======================================================================================================== //======================================================================================================== @@ -451,18 +451,27 @@ export class AppController { @UseGuards(JwtAuthGuard) @Post('/quit') async setOffline(@Request() req) { - - const user = await this.userService.findOne(req.user.username); - user.status = 0; + const user = await this.userService.findOne(req.user.username); + user.sessionNumber-- ; + if (!user.sessionNumber) + user.status = 0; await this.userService.save(user); 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 +519,7 @@ export class AppController { @Post('/message') async postMessage(@Request() req, @Body() data: any) { //if i can post post ? - let message = + let message = { convid: data.convId, sender: data.sender, @@ -521,7 +530,7 @@ export class AppController { console.log(data); return await this.chatService.createMessage(message, req.user.username); } - + @UseGuards(JwtAuthGuard) @Post('/member') async getMember(@Body() data: any) { @@ -529,7 +538,7 @@ export class AppController { console.log(`get member= ${data.convId}`); return await this.chatService.findConv(data.convId); } - + @UseGuards(JwtAuthGuard) @Post('/getMessage') async getMessage(@Body() data: any) { @@ -541,11 +550,11 @@ export class AppController { return await this.chatService.getMessages(data.convId); // return await this.chatService.getConv(req.user.username); - - + + // res.json(messages); } - + @UseGuards(JwtAuthGuard) @Post('/name') async setName(@Body() data: any) { @@ -553,13 +562,13 @@ export class AppController { // data.convId return await this.chatService.setName(data.convId, data.name) } - + @UseGuards(JwtAuthGuard) @Post('/password') async setPassword(@Body() data: any) { return await this.chatService.setPassword(data.convId, data.password) } - + @UseGuards(JwtAuthGuard) @Post('/verifyPassword') async verifyPassword(@Body() data: any) { @@ -579,7 +588,7 @@ export class AppController { return ; return await this.chatService.banUser(data.convId, data.username) } - + @UseGuards(JwtAuthGuard) @Post('/admin') async setAdmin(@Body() data: any) { @@ -587,7 +596,7 @@ export class AppController { return ; return await this.chatService.setAdmin(data.convId, data.username) } - + @UseGuards(JwtAuthGuard) @Post('/mute') async muteUser(@Body() data: any) { @@ -595,14 +604,14 @@ export class AppController { return ; return await this.chatService.muteUser(data.convId, data.username, data.time) } - + @UseGuards(JwtAuthGuard) @Post('/isAdmin') async isAdmin(@Request() req, @Body() data: any) { console.log("isdamin= ", req.user.username, " id=", data.convId) return await this.chatService.isAdmin(data.convId, req.user.username) } - + @UseGuards(JwtAuthGuard) @Post('/private') async setPrivate(@Body() data: any) { @@ -627,4 +636,4 @@ export class AppController { return await this.chatService.joinChannel(data.convId, req.user.username) } -} \ No newline at end of file +} diff --git a/containers/api/src/auth/login42.ts b/containers/api/src/auth/login42.ts index 165bd7fb..6bb2c1a0 100644 --- a/containers/api/src/auth/login42.ts +++ b/containers/api/src/auth/login42.ts @@ -18,7 +18,7 @@ export class loginClass { let userName = null; // let = null; - + const params = new URLSearchParams(url.split('?')[1]); const code = params.get('code'); @@ -62,11 +62,11 @@ export class loginClass { password: null, username: userName, nickname: userName, - win: 0, + win: 0, loss: 0, rank: 1200, userId: userId, - otp_base32: null, + otp_base32: null, children: null, status: 1, // doubleAuth: 0, @@ -76,15 +76,16 @@ export class loginClass { friends: null, blocked: null, photo: null, + sessionNumber: 1, }; await this.usersService.create(user); } // console.log(`in login42 user= ${user}`) const myJSON = JSON.stringify(user); console.log(`in login42 user= ${myJSON}`) - + console.log("end of login"); return (user); // return (await this.usersService.findOne(userName)); } -} \ No newline at end of file +} diff --git a/containers/api/src/model/user.entity.ts b/containers/api/src/model/user.entity.ts index 55d93f59..cac928c5 100644 --- a/containers/api/src/model/user.entity.ts +++ b/containers/api/src/model/user.entity.ts @@ -34,7 +34,7 @@ export class User { @Column({ nullable: true }) nickname: string; - + @Column({ nullable: true }) username: string; @@ -46,22 +46,25 @@ export class User { @Column({ default: 0 }) win: number; - + @Column({ default: 0 }) loss: number; - + + @Column({ default: 0 }) + sessionNumber: number; + @Column({ default: 0 }) rank: number; @Column({ default: 0 }) //0 = offline | 1 = connected | 2 = in game status: number; - + @Column({ default: 0 }) userId: number; // @Column({ default: 0 }) // doubleAuth: number; - + @Column('text', { array: true, nullable: true }) friendRequest: string[]; @@ -98,4 +101,4 @@ export class MatchLog { @ManyToOne(() => User, parent => parent.children) parent: User; -} \ No newline at end of file +} diff --git a/containers/react/src/pages/Home.tsx b/containers/react/src/pages/Home.tsx index bbbae267..4e6f1dd3 100644 --- a/containers/react/src/pages/Home.tsx +++ b/containers/react/src/pages/Home.tsx @@ -13,6 +13,8 @@ // import { React, useState } from "react"; import '../styles/Profile.css' // import '../styles/App.css' +import RedAlert from "../components/Alert/RedAlert.tsx"; + import DefaultPicture from "../assets/profile.jpg"; import WinLoss from "../components/Profile/Win_Loss.tsx"; import { motion, AnimatePresence } from 'framer-motion' @@ -52,7 +54,10 @@ function Profile () { const [isLoading, setIsLoading] = useState(true); const [modalOpen, setModalOpen] = useState(false); const [mine, setMine] = useState(false); + const [error, setError] = useState(false); + // const [visible, setVisible] = useState(false); const close = () => setModalOpen(false); + const closeError = () => setError(false); const open = () => setModalOpen(true); const { username } = useParams(); @@ -76,6 +81,7 @@ function Profile () { console.log('File uploaded successfully'); window.location.reload(); } catch (error) { + setError(true); console.error('Error uploading file:', error); } } @@ -146,6 +152,14 @@ function Profile () { <> + null}> + {error ? ( + + ): ("")} + + + + )} @@ -191,7 +205,7 @@ function Home () { const tmpUser = await api.get("/profile"); setUser(tmpUser.data); } - else + else { const tmpUser = await api.post("/user", {username: username}); setUser(tmpUser.data); @@ -224,7 +238,7 @@ function Home () { ):("")}
- Date: Mon, 26 Jun 2023 02:27:43 +0200 Subject: [PATCH 3/4] add useeffect app for return --- containers/api/src/app.controller.ts | 4 ++-- containers/api/src/chat/chat.service.ts | 2 +- containers/react/src/components/App.tsx | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/containers/api/src/app.controller.ts b/containers/api/src/app.controller.ts index 403506c0..b503c806 100644 --- a/containers/api/src/app.controller.ts +++ b/containers/api/src/app.controller.ts @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/17 01:00:00 by apommier #+# #+# */ -/* Updated: 2023/06/26 00:47:07 by apommier ### ########.fr */ +/* Updated: 2023/06/26 02:23:56 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -451,7 +451,7 @@ export class AppController { @UseGuards(JwtAuthGuard) @Post('/quit') async setOffline(@Request() req) { - + console.log("cc quit here"); const user = await this.userService.findOne(req.user.username); user.status = 0; diff --git a/containers/api/src/chat/chat.service.ts b/containers/api/src/chat/chat.service.ts index d69bad68..3825f32f 100644 --- a/containers/api/src/chat/chat.service.ts +++ b/containers/api/src/chat/chat.service.ts @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/17 01:00:25 by apommier #+# #+# */ -/* Updated: 2023/06/24 18:47:59 by apommier ### ########.fr */ +/* Updated: 2023/06/26 02:07:45 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/containers/react/src/components/App.tsx b/containers/react/src/components/App.tsx index a2d017a2..6c22aa80 100644 --- a/containers/react/src/components/App.tsx +++ b/containers/react/src/components/App.tsx @@ -19,20 +19,20 @@ import DoubleAuth from "../pages/2fa.tsx"; import Game from "../pages/Game.tsx"; import Social from "./Social/Social.tsx"; import Logout from "./Profile/Logout.tsx"; - +import api from "../script/axiosApi.tsx" function AnimatedRoute () { // const location = useLocation(); useEffect(() => { - const handleBeforeUnload = (event: { preventDefault: () => void; returnValue: string; }) => { + 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); } From 26b3c8279027deeecdb9dcb6b2e8f9814691b5b5 Mon Sep 17 00:00:00 2001 From: Lara REALI Date: Mon, 26 Jun 2023 02:54:48 +0200 Subject: [PATCH 4/4] merge error --- .env | 21 +++++++++---------- containers/api/src/app.controller.ts | 3 --- containers/react/.env | 15 +++++++------ containers/react/src/components/App.tsx | 8 +++---- .../react/src/components/Game/PlayButton.tsx | 6 +----- 5 files changed, 24 insertions(+), 29 deletions(-) diff --git a/.env b/.env index 8f4c4911..fcdde945 100644 --- a/.env +++ b/.env @@ -7,18 +7,17 @@ # POSTGRES_PASSWORD=pass # POSTGRES_DB=postgreDB # POSTGRES_ROOT_PASSWORD=pass -# POSTGRES_HOST=bess-f2r5s13 +# POSTGRES_HOST=localhost # POSTGRES_HOST_AUTH_METHOD=trust #URL NGINX_ENVSUBST_TEMPLATE_SUFFIX=".conf" -# BASE_URL=http://bess-f2r5s13 -# SOCKET_URL=bess-f2r5s13:8080 -BASE_URL=bess-f2r5s13:8080 -REACT_APP_BASE_URL=bess-f2r5s13:8080 -REDIRECT_URI=http://bess-f2r5s13:8080/api/auth/login -INTRA_URL="https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-2bd3c5d4f41e776f2e3d5d699d2a8421f6d0c0468ec882516d9ca89b0c211789&redirect_uri=http%3A%2F%2Fbess-f2r5s13%3A8080%2Fapi%2Fauth%2Flogin&response_type=code" +# BASE_URL=http://localhost +# SOCKET_URL=localhost:8080 +BASE_URL=localhost:8080 +REACT_APP_BASE_URL=localhost:8080 +REDIRECT_URI=http://localhost:8080/api/auth/login #postgres var # POSTGRES_HOST=127.0.0.1 # DB_TYPE=postgres @@ -35,7 +34,7 @@ NGINX_PORT=8080 PONG_PORT=4000 CHAT_PORT=4001 POSTGRES_PORT=5432 - + #???? RUN_MIGRATIONS=true REACT_HOST=0.0.0.0 @@ -43,6 +42,6 @@ REACT_HOST=0.0.0.0 #auth var JWT_SECRET=secrethere -# REDIRECT_URI=http://bess-f2r5s13:80/api/auth/login -API_SECRET=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 -CLIENT_UID=u-s4t2ud-2bd3c5d4f41e776f2e3d5d699d2a8421f6d0c0468ec882516d9ca89b0c211789 +# REDIRECT_URI=http://localhost:80/api/auth/login +API_SECRET=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 +CLIENT_UID=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41 diff --git a/containers/api/src/app.controller.ts b/containers/api/src/app.controller.ts index fa3e5a91..19c05aa6 100644 --- a/containers/api/src/app.controller.ts +++ b/containers/api/src/app.controller.ts @@ -451,9 +451,6 @@ export class AppController { @UseGuards(JwtAuthGuard) @Post('/quit') async setOffline(@Request() req) { - console.log("cc quit here"); - const user = await this.userService.findOne(req.user.username); - const user = await this.userService.findOne(req.user.username); user.sessionNumber-- ; if (!user.sessionNumber) diff --git a/containers/react/.env b/containers/react/.env index 0ad277ad..0e54b8cc 100644 --- a/containers/react/.env +++ b/containers/react/.env @@ -1,8 +1,11 @@ -REACT_APP_BASE_URL=bess-f2r5s13:8080 -REACT_APP_SOCKET_URL=bess-f2r5s13 -REACT_APP_API_SECRET=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 -REACT_APP_CLIENT_UID=u-s4t2ud-2bd3c5d4f41e776f2e3d5d699d2a8421f6d0c0468ec882516d9ca89b0c211789 -REACT_APP_INTRA_URL="https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-2bd3c5d4f41e776f2e3d5d699d2a8421f6d0c0468ec882516d9ca89b0c211789&redirect_uri=http%3A%2F%2Fbess-f2r5s13%3A8080%2Fapi%2Fauth%2Flogin&response_type=code" +REACT_APP_BASE_URL=localhost:8080 +REACT_APP_SOCKET_URL=localhost +REACT_APP_API_SECRET=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 +REACT_APP_CLIENT_UID=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41 # REACT_APP_BASE_URL=92.143.191.152 -# REACT_APP_BASE_URL=192.168.1.19 \ No newline at end of file +# 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 diff --git a/containers/react/src/components/App.tsx b/containers/react/src/components/App.tsx index 6c22aa80..ece4ec07 100644 --- a/containers/react/src/components/App.tsx +++ b/containers/react/src/components/App.tsx @@ -40,9 +40,9 @@ function AnimatedRoute () { // 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); }; @@ -73,7 +73,7 @@ function AnimatedRoute () { }/> }/> }/> - + }/> }/> @@ -94,4 +94,4 @@ function AnimatedRoute () { ) } -export default AnimatedRoute \ No newline at end of file +export default AnimatedRoute diff --git a/containers/react/src/components/Game/PlayButton.tsx b/containers/react/src/components/Game/PlayButton.tsx index 94f323cd..e6bc50ad 100644 --- a/containers/react/src/components/Game/PlayButton.tsx +++ b/containers/react/src/components/Game/PlayButton.tsx @@ -40,13 +40,9 @@ function PlayButton() { {/* !buttonClicked && */}
-<<<<<<< HEAD

Super Power
( w = wall power )

-

Obstacle

-======= +

Super Power

- {/*

Obstacle

*/} ->>>>>>> apommier

Faster and Faster