quit + alert +addsesion
This commit is contained in:
parent
b61531d8d2
commit
322aecc182
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<boolean>(true);
|
||||
const [modalOpen, setModalOpen] = 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 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 () {
|
||||
<>
|
||||
<label htmlFor="file-input" className="edit_name"><MdOutlinePhotoLibrary/></label>
|
||||
<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>
|
||||
@ -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 () {
|
||||
):("")}
|
||||
</div>
|
||||
<div className="home">
|
||||
<motion.div
|
||||
<motion.div
|
||||
// style={{
|
||||
// backdropFilter: move ? "blur(10px)" : "none",
|
||||
// WebkitBackdropFilter: move ? "blur(10px)" : "none"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user