Merge remote-tracking branch 'origin/phoenix' into reborn

This commit is contained in:
Alexandre POMMIER 2023-06-26 07:46:36 +02:00
commit 0d80c118b4
9 changed files with 579 additions and 572 deletions

View File

@ -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);
@ -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);
@ -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);
@ -455,6 +443,8 @@ export class AppController {
user.sessionNumber--; user.sessionNumber--;
if (!user.sessionNumber) if (!user.sessionNumber)
user.status = 0; user.status = 0;
console.log("quit sessionNUmber :", user.sessionNumber);
await this.userService.save(user); await this.userService.save(user);
console.log("User quit"); console.log("User quit");
} }
@ -464,7 +454,11 @@ 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;
if (user.status !== 2) //super
user.status = 1;
console.log("addSession sessionNUmber :", user.sessionNumber);
await this.userService.save(user); await this.userService.save(user);
} }

View File

@ -78,10 +78,6 @@ export class loginClass {
}; };
await this.usersService.create(user); await this.usersService.create(user);
} }
// if (user.status !== 2 || user.status === 0) //super
// user.status = 1;
// user.sessionNumber++;
// 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}`)

View File

@ -58,7 +58,7 @@ export class UsersService {
async getFriends(username: string) { async getFriends(username: string) {
const user = await this.findOne(username) const user = await this.findOne(username)
let friendsTab = user.friends let friendsTab = user.friends || []
console.log(friendsTab) console.log(friendsTab)
// friendsTab = ['apommier', 'syd'] // friendsTab = ['apommier', 'syd']
const friends = await this.userRepository.query("SELECT * FROM \"User\" WHERE username = ANY ($1);", [friendsTab]); const friends = await this.userRepository.query("SELECT * FROM \"User\" WHERE username = ANY ($1);", [friendsTab]);

View File

@ -16,6 +16,7 @@ export interface User {
partyInvite: Record<string, string>[]; partyInvite: Record<string, string>[];
friends: string[]; friends: string[];
blocked: string[]; blocked: string[];
sessionNumber: number;
} }
export interface Conv { export interface Conv {

View File

@ -36,16 +36,25 @@ function AnimatedRoute () {
} }
}; };
window.addEventListener('beforeunload', handleBeforeUnload); const handleLoad = async () => {
if (!localStorage.getItem('token'))
return;
try {
await api.post("/addSession");
} catch (err) {
console.log(err);
}
};
handleLoad();
window.addEventListener('beforeunload', handleBeforeUnload);
return () => { return () => {
window.removeEventListener('beforeunload', handleBeforeUnload); window.removeEventListener('beforeunload', handleBeforeUnload);
}; };
}, []); }, []);
const location = useLocation(); const location = useLocation();
if (!localStorage.getItem('token')) if (!localStorage.getItem('token')) {
{
return ( return (
<AnimatePresence> <AnimatePresence>
<Routes location={location} key={location.pathname}> <Routes location={location} key={location.pathname}>

View File

@ -79,10 +79,6 @@ const GameModal = ({ handleClose }: ModalGame) => {
path += 'superpower=true&'; path += 'superpower=true&';
} }
const obstacleCheckbox = document.querySelector<HTMLInputElement>('input[value="obstacle"]');
if (obstacleCheckbox && obstacleCheckbox.checked) {
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) {
@ -132,10 +128,9 @@ const GameModal = ({ handleClose }: ModalGame) => {
{/* <button onClick={handleButtonClick}>Draw on Canvas</button> */} {/* <button onClick={handleButtonClick}>Draw on Canvas</button> */}
<div className='checkbox'> <div className='checkbox'>
<p><input type="checkbox" value="superpower"/> Super Power </p> <p><input type="checkbox" value="superpower"/> Super Power </p>
<p><input type="checkbox" value="obstacle"/> Obstacle </p>
<p><input type="checkbox" value="speed"/> Faster and Faster </p> <p><input type="checkbox" value="speed"/> Faster and Faster </p>
</div> </div>
<button className="submit" onClick={handleButtonClick} >Play</button> <button className="playInvite" onClick={handleButtonClick} >Play</button>
{/* <button className="submit" onClick={handleClose}>Cancel</button> */} {/* <button className="submit" onClick={handleClose}>Cancel</button> */}
</div> </div>

View File

@ -66,6 +66,8 @@ export default function Friend({currentUser}: UserProps)
function getStatus(friend: User) function getStatus(friend: User)
{ {
let status = friend.status let status = friend.status
let session =friend.sessionNumber
console.log(`session= ${session}`)
console.log(`status= ${status}`) console.log(`status= ${status}`)
let statusColor; let statusColor;

View File

@ -94,7 +94,7 @@ export default function Friend({currentUser}: UserProps)
} }
return ( return (
<UserChat> <UserChat className="centermargin">
{profilePicture ? ( {profilePicture ? (
<img className="pic-user" src={`data:image/jpeg;base64,${profilePicture}`} /> <img className="pic-user" src={`data:image/jpeg;base64,${profilePicture}`} />
) : ( ) : (

View File

@ -222,6 +222,16 @@ p {
height: 25px; height: 25px;
} }
.playInvite{
margin: 5%;
color: ghostwhite;
outline: 0;
border-radius: 100px;
padding: 3%;
background-image: linear-gradient(90deg, #5843e4, #5a0760);
width: 42%;
font-size: x-large;
}
.darkSubmit{ .darkSubmit{
display: inline-block; display: inline-block;
color: white; color: white;