add html pages for invalid mail token and mail verified, remove useless print, fix ball direction after a point, check if token already exists in mail verification (just to be sure), translate mail content to english, disable debug mode in websocket
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/06 03:24:10 by tomoron #+# #+# #
|
||||
# Updated: 2024/10/22 14:53:55 by tomoron ### ########.fr #
|
||||
# Updated: 2024/11/19 16:38:30 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -23,7 +23,7 @@ class Ball:
|
||||
self.speed = GameSettings.startSpeed
|
||||
self.vel[0] = self.speed * (random.randint(-50, 50) / 100)
|
||||
self.vel[1] = self.speed - abs(self.vel[0])
|
||||
if(inv == 2):
|
||||
if(inv):
|
||||
self.vel[1] = -self.vel[1]
|
||||
|
||||
def default(self):
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/19 18:29:36 by tomoron #+# #+# #
|
||||
# Updated: 2024/10/22 16:35:59 by tomoron ### ########.fr #
|
||||
# Updated: 2024/11/19 16:18:45 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -33,7 +33,6 @@ class Bot(Player):
|
||||
if(GameSettings.BotMovement):
|
||||
asyncio.create_task(self.updateLoop())
|
||||
asyncio.create_task(self.goToObjectiveLoop())
|
||||
print("I am a bot, boop boop beep boop")
|
||||
|
||||
def isTournamentReady(self):
|
||||
return(True);
|
||||
@ -76,10 +75,7 @@ class Bot(Player):
|
||||
leftLimit = GameSettings.mapLimits["left"] + (GameSettings.playerLength / 2)
|
||||
rightLimit = GameSettings.mapLimits["right"] - (GameSettings.playerLength / 2)
|
||||
if(self.objective["pos"] < leftLimit or self.objective["pos"] > rightLimit):
|
||||
print("objective out of bound , set objective to limit")
|
||||
print("prev objective : ", self.objective["pos"])
|
||||
self.objective["pos"] = leftLimit if self.objective["pos"] < 0 else rightLimit
|
||||
print("new objective : ", self.objective["pos"])
|
||||
|
||||
def isEnd(self):
|
||||
if(self.tournament != None):
|
||||
@ -102,13 +98,11 @@ class Bot(Player):
|
||||
self.pos["up"] = self.objective["up"]
|
||||
|
||||
maxDistance = GameSettings.maxPlayerSpeed * (time.time() - lastUpdate)
|
||||
print("maxDistance :", maxDistance)
|
||||
travel = self.objective["pos"] - self.pos["pos"]
|
||||
if(travel >= 0):
|
||||
travel = min(self.objective["pos"] - self.pos["pos"], maxDistance)
|
||||
else:
|
||||
travel = max(self.objective["pos"] - self.pos["pos"], -maxDistance)
|
||||
print("travel :", travel)
|
||||
self.game.move(self.socket, self.pos["pos"] + travel, self.pos["up"])
|
||||
lastUpdate = time.time()
|
||||
await asyncio.sleep(1 / 20)
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/11/13 16:21:18 by tomoron #+# #+# #
|
||||
# Updated: 2024/11/15 17:08:23 by tomoron ### ########.fr #
|
||||
# Updated: 2024/11/19 16:38:26 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -43,7 +43,6 @@ class Game:
|
||||
self.tournamentCode = tournamentCode
|
||||
p1.setGame(self)
|
||||
p2.setGame(self)
|
||||
print("game created with ", p1.socket.username, "vs", p2.socket.username)
|
||||
|
||||
def lookForRankedGame(self, socket):
|
||||
for x in Game.rankedWaitingForPlayer:
|
||||
@ -91,9 +90,6 @@ class Game:
|
||||
Game.waitingForPlayer.join(socket, skinId, goalId)
|
||||
Game.waitingForPlayer = None
|
||||
|
||||
def __del__(self):
|
||||
print("game destroy")
|
||||
|
||||
def initAttributes(self):
|
||||
self.p1 = None
|
||||
self.p2 = None
|
||||
@ -147,7 +143,6 @@ class Game:
|
||||
def join(self, socket, skin = 0, goal = 0):
|
||||
try:
|
||||
if(self.p1 == None):
|
||||
print("game created, set as player 1")
|
||||
self.p1 = Player(socket)
|
||||
self.p1.setGame(self)
|
||||
self.p1.skin = skin
|
||||
@ -156,13 +151,11 @@ class Game:
|
||||
if(self.opponentLock != None and self.opponentLock != socket.id):
|
||||
socket.sendError("You are not invited to this game", 9103)
|
||||
return
|
||||
print("joined game, set as player 2")
|
||||
self.p2 = Player(socket)
|
||||
self.p2.setGame(self)
|
||||
self.p2.skin = skin
|
||||
self.p2.goal = goal
|
||||
if(self.p2 != None and self.p1 != None):
|
||||
print("both players here, send opponent to both players")
|
||||
self.p1.socket.sync_send({"type":"game", "content":{"action":1,"id":self.p2.socket.id,"username":self.p2.socket.username, "skin":self.p2.skin, "goal":self.p2.goal, 'pfpOpponent':self.p2.socket.pfp, 'pfpSelf':self.p1.socket.pfp}})
|
||||
self.p2.socket.sync_send({"type":"game", "content":{"action":1,"id":self.p1.socket.id,"username":self.p1.socket.username, "skin":self.p1.skin, "goal":self.p1.goal, 'pfpOpponent':self.p1.socket.pfp, 'pfpSelf':self.p2.socket.pfp}})
|
||||
except Exception as e:
|
||||
@ -176,9 +169,7 @@ class Game:
|
||||
else:
|
||||
return(0)
|
||||
if(self.p1.ready and self.p2.ready):
|
||||
print("both players are ready, starting game")
|
||||
self.genObstacles()
|
||||
print("obstacles generated :", self.obstacles)
|
||||
asyncio.create_task(self.gameLoop())
|
||||
return(1)
|
||||
|
||||
@ -228,7 +219,6 @@ class Game:
|
||||
opponent.sync_send({"type":"game","content":{"action":3, "pos":-pos, "up":up, "is_opponent":True}})
|
||||
|
||||
def sendNewBallInfo(self, reset = False):
|
||||
print("send new ball info")
|
||||
if(reset):
|
||||
self.gameTime = 0
|
||||
if(self.p1.socket):
|
||||
@ -247,17 +237,13 @@ class Game:
|
||||
def checkGameEndGoal(self):
|
||||
if(self.score[0] < GameSettings.maxScore and self.score[1] < GameSettings.maxScore):
|
||||
return(False)
|
||||
print("someone won the game")
|
||||
winner = 1 if self.score[0] == GameSettings.maxScore else 2
|
||||
print("player", winner,"won the game")
|
||||
self.endGame(winner)
|
||||
return(True)
|
||||
|
||||
async def scoreGoal(self, player):
|
||||
self.lastWin = player
|
||||
print("a player suffured from a major skill issue")
|
||||
self.score[player-1] += 1
|
||||
print("new score :", self.score)
|
||||
self.p1.socket.sync_send({"type":"game","content":{"action":6, "is_opponent": player == 2}})
|
||||
self.p2.socket.sync_send({"type":"game","content":{"action":6, "is_opponent": player == 1}})
|
||||
self.prepareGame(True);
|
||||
@ -293,7 +279,6 @@ class Game:
|
||||
await asyncio.sleep(3)
|
||||
self.prepareGame()
|
||||
continue
|
||||
print("sleep time : " , sleep_time)
|
||||
if((time.time() - self.gameStart) - self.gameTime < sleep_time):
|
||||
await asyncio.sleep(sleep_time - ((time.time() - self.gameStart) - self.gameTime))
|
||||
self.gameTime += sleep_time
|
||||
@ -302,7 +287,6 @@ class Game:
|
||||
await self.scoreGoal(goal)
|
||||
else:
|
||||
self.sendNewBallInfo()
|
||||
print("game end")
|
||||
if(self.p1.socket.game == self):
|
||||
self.p1.setGame(None)
|
||||
if(self.p2.socket.game == self):
|
||||
@ -324,7 +308,6 @@ class Game:
|
||||
def updateElo(self):
|
||||
try:
|
||||
if(self.winner == None):
|
||||
print("unkown winner, setting to 1")
|
||||
self.winner = 1
|
||||
if(self.left != None):
|
||||
self.score[self.left - 1] = 0
|
||||
@ -356,9 +339,7 @@ class Game:
|
||||
def saveResults(self):
|
||||
try:
|
||||
if(self.winner == None):
|
||||
print("unkown winner, setting to 1")
|
||||
self.winner = 1
|
||||
print("saving results")
|
||||
p1DbUser = User.objects.get(id=self.p1.socket.id)
|
||||
p2DbUser = User.objects.get(id=self.p2.socket.id)
|
||||
results = GameResults.objects.create(
|
||||
@ -370,7 +351,6 @@ class Game:
|
||||
forfeit = self.left != None
|
||||
)
|
||||
results.save()
|
||||
print("results saved")
|
||||
except Exception as e:
|
||||
self.p1.socket.sendError("Couldn't save last game results", 9104, e)
|
||||
self.p2.socket.sendError("Couldn't save last game results", 9104, e)
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/05 03:22:32 by tomoron #+# #+# #
|
||||
# Updated: 2024/11/15 16:43:28 by tomoron ### ########.fr #
|
||||
# Updated: 2024/11/19 16:53:31 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -24,7 +24,6 @@ class Player():
|
||||
self.goal = 0
|
||||
|
||||
def __del__(self):
|
||||
print("player destroy")
|
||||
|
||||
def isTournamentReady(self):
|
||||
return(self.tournamentReady)
|
||||
@ -36,7 +35,6 @@ class Player():
|
||||
leftLimit = GameSettings.mapLimits["left"] + (GameSettings.playerLength / 2)
|
||||
rightLimit = GameSettings.mapLimits["right"] - (GameSettings.playerLength / 2)
|
||||
if(newPos < leftLimit - GameSettings.OOBTolerance or newPos > rightLimit + GameSettings.OOBTolerance):
|
||||
print("\033[31mplayer out of the map")
|
||||
newPos = leftLimit if newPos < 0 else rightLimit
|
||||
return(newPos)
|
||||
|
||||
@ -44,12 +42,8 @@ class Player():
|
||||
newMove = GameSettings.maxPlayerSpeed * deltaTime
|
||||
if(newPos - self.pos["pos"] < 0):
|
||||
newMove = -newMove
|
||||
print("\033[31mplayer is too fast")
|
||||
print("speed :", abs(newPos - self.pos["pos"]) * (1 / deltaTime))
|
||||
print("time : ", deltaTime)
|
||||
newPos = self.pos["pos"] + newMove
|
||||
return(newPos)
|
||||
print("no problem")
|
||||
return(newPos)
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/04 17:17:07 by tomoron #+# #+# #
|
||||
# Updated: 2024/11/14 14:35:32 by tomoron ### ########.fr #
|
||||
# Updated: 2024/11/19 16:18:58 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -142,4 +142,3 @@ class Tournament:
|
||||
for x in self.players:
|
||||
x.socket.tournament = None
|
||||
self.players = []
|
||||
print("tournament done, winner is ", self.finalGame.winner.socket.username)
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/22 01:37:00 by tomoron #+# #+# #
|
||||
# Updated: 2024/11/14 13:59:35 by tomoron ### ########.fr #
|
||||
# Updated: 2024/11/19 16:51:38 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -26,7 +26,6 @@ class TournamentGame:
|
||||
async def startGame(self):
|
||||
l = None
|
||||
r = None
|
||||
print("start new game")
|
||||
if(isinstance(self.left,TournamentGame)):
|
||||
l = self.left.winner
|
||||
r = self.right.winner
|
||||
@ -35,11 +34,9 @@ class TournamentGame:
|
||||
r = self.right
|
||||
nbLoop = 0
|
||||
while (not l.isTournamentReady() or not r.isTournamentReady()) and nbLoop < GameSettings.maxTimePlayerWait * 10:
|
||||
print("waiting for player")
|
||||
nbLoop += 1
|
||||
await asyncio.sleep(0.1)
|
||||
if(not l.socket.tournament == self.tournament or not r.socket.tournament == self.tournament):
|
||||
print("player is not online, opponent is winner")
|
||||
self.winner = l if l.socket.online else r
|
||||
return;
|
||||
await asyncio.sleep(3)
|
||||
@ -73,7 +70,6 @@ class TournamentGame:
|
||||
await self.startGame()
|
||||
else:
|
||||
if(self.game.winner != None):
|
||||
print("game ended, winner is", self.game.pWinner.socket.username)
|
||||
p1Id = self.tournament.playerFromSocket(self.game.p1.socket)
|
||||
p2Id = self.tournament.playerFromSocket(self.game.p2.socket)
|
||||
self.tournament.addHistory(p1Id, p2Id, self.game.winner == 1)
|
||||
|
@ -9,7 +9,6 @@ class User(models.Model):
|
||||
pfp = models.CharField(max_length=1024, default="/static/img/default_pfp.jpg")
|
||||
banner = models.CharField(max_length=1024, default="/static/img/default_banner.jpg")
|
||||
mail_verified = models.BooleanField(default=True)
|
||||
print("A" * 1000)
|
||||
github_link = models.CharField(max_length=1024, null=True, blank=True, default=None)
|
||||
discord_username = models.CharField(max_length=1024, null=True, blank=True, default=None)
|
||||
last_login = models.DateTimeField()
|
||||
|
@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>error</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
couldn't verify the email, the token is invalid.
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>mail verified !</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
the mail address has been verified. you will be redirected in 3 seconds
|
||||
</body>
|
||||
</html>
|
@ -6,7 +6,7 @@
|
||||
# By: marvin <marvin@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/08/09 08:08:00 by edbernar #+# #+# #
|
||||
# Updated: 2024/10/22 15:57:27 by tomoron ### ########.fr #
|
||||
# Updated: 2024/11/19 16:53:40 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -30,7 +30,6 @@ URLMAIL = SERVER_URL + "/verify?token="
|
||||
|
||||
@sync_to_async
|
||||
def createAccount(socket, content):
|
||||
print("create account")
|
||||
if (socket.logged_in):
|
||||
socket.sendError("Already logged in", 9012)
|
||||
return;
|
||||
@ -45,13 +44,13 @@ def createAccount(socket, content):
|
||||
new_user = User.objects.create(username=content["username"], mail=content["mail"], password=password, last_login=timezone.now())
|
||||
new_user.save()
|
||||
verif_str = genString(200)
|
||||
while(MailVerify.objects.filter(token=verif_str).exists()):
|
||||
verif_str = genString(200)
|
||||
MailVerify.objects.create(uid=new_user, token=verif_str).save()
|
||||
print("send")
|
||||
socket.sync_send(json.dumps({"type": "create_account", "content": "Account created"}))
|
||||
thread = Thread(target = sendVerifMail, args = (verif_str, content["mail"], content["username"]))
|
||||
thread.start()
|
||||
except Exception as e:
|
||||
print("error")
|
||||
socket.sendError("An error occured while creating the account", 9024, e)
|
||||
|
||||
def sendVerifMail(verif_str, mail, username):
|
||||
@ -60,84 +59,84 @@ def sendVerifMail(verif_str, mail, username):
|
||||
msg['To'] = mail
|
||||
msg['Subject'] = 'Account verification'
|
||||
msg.attach(MIMEText('''
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #1e1e1e;
|
||||
color: #ffffff;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background-color: #2c2c2c;
|
||||
border-radius: 8px;
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
font-size: 24px;
|
||||
margin-bottom: 50px;
|
||||
background-color: #1e1e1e;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
color: #ffffff;
|
||||
}
|
||||
p {
|
||||
color: #cccccc;
|
||||
font-size: 16px;
|
||||
}
|
||||
.button {
|
||||
display: inline-block;
|
||||
padding: 10px 20px;
|
||||
font-size: 16px;
|
||||
color: #ffffff;
|
||||
background-color: #0f0f0f;
|
||||
border-radius: 5px;
|
||||
text-decoration: none;
|
||||
margin: 20px;
|
||||
margin-left: 25%;
|
||||
margin-right: 25%;
|
||||
width: 50%;
|
||||
text-align: center;
|
||||
}
|
||||
.footer {
|
||||
font-size: 12px;
|
||||
background-color: #1e1e1e;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
border-radius: 8px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table class="container" role="presentation">
|
||||
<tr>
|
||||
<td>
|
||||
<h1>Bienvenue chez METH !</h1>
|
||||
<p>Bonjour ''' + username + ''',</p>
|
||||
<p>Merci d'avoir créé un compte avec METH ! Nous sommes ravis de vous accueillir parmi nous.</p>
|
||||
<p>Pour compléter votre inscription, veuillez vérifier votre adresse e-mail en cliquant sur le bouton ci-dessous :</p>
|
||||
<p><a href="''' + URLMAIL + verif_str +'''" class="button">Confirmer mon adresse e-mail</a></p>
|
||||
<p>Si vous n'avez pas demandé cette inscription, vous pouvez ignorer cet e-mail.</p>
|
||||
<p>Merci,</p>
|
||||
<p>L'équipe METH</p>
|
||||
<div class="footer">
|
||||
<p>42, 49 Bd Besson Bey, 16000 Angoulême, France</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
''', 'html'))
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #1e1e1e;
|
||||
color: #ffffff;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background-color: #2c2c2c;
|
||||
border-radius: 8px;
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
font-size: 24px;
|
||||
margin-bottom: 50px;
|
||||
background-color: #1e1e1e;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
color: #ffffff;
|
||||
}
|
||||
p {
|
||||
color: #cccccc;
|
||||
font-size: 16px;
|
||||
}
|
||||
.button {
|
||||
display: inline-block;
|
||||
padding: 10px 20px;
|
||||
font-size: 16px;
|
||||
color: #ffffff;
|
||||
background-color: #0f0f0f;
|
||||
border-radius: 5px;
|
||||
text-decoration: none;
|
||||
margin: 20px;
|
||||
margin-left: 25%;
|
||||
margin-right: 25%;
|
||||
width: 50%;
|
||||
text-align: center;
|
||||
}
|
||||
.footer {
|
||||
font-size: 12px;
|
||||
background-color: #1e1e1e;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
border-radius: 8px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table class="container" role="presentation">
|
||||
<tr>
|
||||
<td>
|
||||
<h1>Welcome to METH!</h1>
|
||||
<p>Hello ''' + username + ''',</p>
|
||||
<p>Thank you for creating an account with METH! We are excited to have you with us.</p>
|
||||
<p>To complete your registration, please verify your email address by clicking the button below:</p>
|
||||
<p><a href="''' + URLMAIL + verif_str +'''" class="button">Confirm my email address</a></p>
|
||||
<p>If you did not request this registration, you can safely ignore this email.</p>
|
||||
<p>Thank you,</p>
|
||||
<p>The METH Team</p>
|
||||
<div class="footer">
|
||||
<p>42, 49 Bd Besson Bey, 16000 Angoulême, France</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
''', 'html'))
|
||||
try:
|
||||
server = smtplib.SMTP('smtp.mail.me.com', 587)
|
||||
server.ehlo()
|
||||
@ -146,8 +145,6 @@ def sendVerifMail(verif_str, mail, username):
|
||||
server.login(ICLOUD_USER, ICLOUD_PASS)
|
||||
server.sendmail(ICLOUD_USER, mail, msg.as_string())
|
||||
server.quit()
|
||||
print("E-mail envoyé avec succès !")
|
||||
return(74725)
|
||||
except Exception as e:
|
||||
print(f"Erreur lors de l'envoi de l'e-mail : {e}")
|
||||
return(0)
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/09/20 00:16:57 by edbernar #+# #+# #
|
||||
# Updated: 2024/11/18 16:10:54 by tomoron ### ########.fr #
|
||||
# Updated: 2024/11/19 16:59:00 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -37,7 +37,7 @@ def getHistory(user, games):
|
||||
})
|
||||
return(res)
|
||||
|
||||
def getStats(user, socket):
|
||||
def getStats(user):
|
||||
try:
|
||||
games = GameResults.objects.filter(Q(player1=user) | Q(player2=user))
|
||||
nbGames = games.count()
|
||||
@ -71,9 +71,6 @@ def getStats(user, socket):
|
||||
res["nbGames30Days"] = int(nbGames30Days)
|
||||
res["history"] = history
|
||||
return(res)
|
||||
except Exception as e:
|
||||
socket.sendError("invalid request", 9005, e)
|
||||
|
||||
|
||||
@sync_to_async
|
||||
def getUserInfo(socket, content):
|
||||
|
@ -6,12 +6,11 @@
|
||||
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/04 18:05:07 by tomoron #+# #+# #
|
||||
# Updated: 2024/10/05 02:28:42 by tomoron ### ########.fr #
|
||||
# Updated: 2024/11/19 16:53:47 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
async def tournamentLeave(socket, content):
|
||||
print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" * 100)
|
||||
if(socket.tournament == None):
|
||||
socket.sendError("you're not in a tournament", 9037)
|
||||
return;
|
||||
|
@ -70,17 +70,17 @@ def profilPage(request):
|
||||
def verify(request):
|
||||
req_token = request.GET.get('token', None)
|
||||
if(req_token == None):
|
||||
return(HttpResponse("token param missing"))
|
||||
return(render(request, "invalidTokenPage.html", {}))
|
||||
user_code = MailVerify.objects.filter(token=req_token)
|
||||
if(not user_code.exists()):
|
||||
return(HttpResponse("token not found (PS : il faudrais peut-être faire une page avec un petit peu css pour ça mais moi ça me va là) ( PSS: il faudrait peut-être faire une page aussi pour quand il manque le parametre token, flemme de mettre ce message dans sa réponse c'est genre 3 lignes au dessus, c'est trop loin) (PSSS: peut-être une page d'erreur générique qu'on peut remplir avec des variables pour les messages d'erreur"))
|
||||
return(render(request, "invalidTokenPage.html", {}))
|
||||
user_code = user_code[0]
|
||||
if(user_code.uid.mail_verified):
|
||||
return(HttpResponse("your mail is already verified, you can now login (PS: voir erreur token not found)"))
|
||||
return(HttpResponse("your mail is already verified, you can now login"))
|
||||
user_code.uid.mail_verified = True
|
||||
user_code.uid.save()
|
||||
user_code.delete()
|
||||
return(HttpResponse("your mail has been verified ! (et pourquoi pas une page pour dire que l'email a été verifié, sinon je peut juste redirect vers la page principale)"))
|
||||
return(render(request, "mailVerifiedPage.html", {}))
|
||||
|
||||
def login42(request):
|
||||
if(request.session.get("logged_in", False)):
|
||||
@ -96,18 +96,16 @@ def login42(request):
|
||||
'code': code,
|
||||
'redirect_uri': SERVER_URL+"/login42"
|
||||
}
|
||||
print("\033[31m",data)
|
||||
response = requests.post('https://api.intra.42.fr/oauth/token', data=data)
|
||||
if (response.status_code != 200):
|
||||
print(response.json())
|
||||
return HttpResponse("couln't get authorization token, likely invalid code")
|
||||
return HttpResponse("couln't get authorization token, likely invalid code or secret expired")
|
||||
response = response.json()
|
||||
headers = {
|
||||
'Authorization': f'Bearer {response["access_token"]}',
|
||||
}
|
||||
response = requests.get('https://api.intra.42.fr/v2/me', headers=headers)
|
||||
if (response.status_code != 200):
|
||||
return HttpResponse("couln't get user info... what, why ?")
|
||||
return HttpResponse("couln't get user info... what, why ? Probably rate limited, try at the next hour")
|
||||
response = response.json()
|
||||
id42 = response['id']
|
||||
login42 = response['login']
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/09/09 14:31:30 by tomoron #+# #+# #
|
||||
# Updated: 2024/10/22 17:12:14 by tomoron ### ########.fr #
|
||||
# Updated: 2024/11/19 16:52:23 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -53,7 +53,7 @@ functionRequest = [login, getPrivateListUser, getPrivateListMessage,
|
||||
from random import randint
|
||||
|
||||
class WebsocketHandler(AsyncWebsocketConsumer):
|
||||
debugMode = True
|
||||
debugMode = False
|
||||
|
||||
# format : {id : socket, ...}
|
||||
onlinePlayers = {}
|
||||
@ -82,12 +82,10 @@ class WebsocketHandler(AsyncWebsocketConsumer):
|
||||
if(uid not in self.onlinePlayers):
|
||||
self.onlinePlayers[uid] = self
|
||||
return(1)
|
||||
print("\033[32monline : ", self.onlinePlayers)
|
||||
return(0)
|
||||
|
||||
async def login(self, uid: int, username: str, pfp : str, elo : int) -> int:
|
||||
if(await self.session_get("logged_in", False)):
|
||||
print("already logged in")
|
||||
return(0)
|
||||
if(not self.add_to_online(uid)):
|
||||
self.sendError("Already logged in", 9012)
|
||||
@ -130,10 +128,8 @@ class WebsocketHandler(AsyncWebsocketConsumer):
|
||||
"id":await self.session_get("id",0),
|
||||
"haveUnredMessage":await getUnreadStatus(self.id)
|
||||
}}))
|
||||
print("new client")
|
||||
|
||||
async def disconnect(self, close_code):
|
||||
print("you can go, i am not mad, we never wanted you anyway")
|
||||
self.online = False
|
||||
if(not self.logged_in):
|
||||
return ;
|
||||
@ -172,7 +168,6 @@ class WebsocketHandler(AsyncWebsocketConsumer):
|
||||
@multimethod
|
||||
def sync_send(self, data: Union[dict,str]):
|
||||
if(not self.online):
|
||||
print("cancel send, socket not online")
|
||||
return
|
||||
txt_data = None
|
||||
if(type(data) is dict):
|
||||
|
Reference in New Issue
Block a user