- New way to manage profiles with url -> /profil/username
Django
    - modification of the user info query
This commit is contained in:
Kum1ta
2024-09-23 01:11:05 +02:00
parent aee57affaa
commit 6729cfc421
5 changed files with 64 additions and 43 deletions

View File

@ -6,7 +6,7 @@
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/09/20 00:16:57 by edbernar #+# #+# #
# Updated: 2024/09/20 01:08:45 by edbernar ### ########.fr #
# Updated: 2024/09/23 00:47:12 by edbernar ### ########.fr #
# #
# **************************************************************************** #
@ -16,9 +16,16 @@ import json
@sync_to_async
def getUserInfo(socket, content):
user = User.objects.filter(id=content['id']).values().first()
if (not user):
socket.sync_send({"type":"user_info", "content": None})
return
socket.sync_send({"type":"user_info", "content":{'username': user['username'], 'pfp': user['pfp'], 'banner': user['banner']}})
try:
if (content.get('id')):
user = User.objects.filter(id=content['id']).values().first()
elif (content.get('username')):
user = User.objects.filter(username=content['username']).values().first()
else:
user = None
if (not user):
socket.sync_send({"type":"user_info", "content": None})
return
socket.sync_send({"type":"user_info", "content":{'username': user['username'], 'pfp': user['pfp'], 'banner': user['banner'], 'id': user['id']}})
except Exception as e:
socket.sendError("invalid request", 9005, e)

View File

@ -26,7 +26,6 @@ urlpatterns = [
path("waitingGamePage", views.waitingGamePage, name='waitingGamePage'),
path("profilPage", views.profilPage, name='profilPage'),
path("game", views.game, name='game'),
path("profil", views.profil, name='profil'),
path("wait_game", views.game, name='wait_game'),
path("login42", views.login42, name='login42'),
path("logout", views.logout, name='logout'),

View File

@ -59,10 +59,6 @@ def wait_game(request):
# return lobbyPage(request)
return redirect('/lobby')
def profil(request):
# return lobbyPage(request)
return redirect('/lobby')
def profilPage(request):
if(request.method != "POST"):
return index(request)