Site
- New way to manage profiles with url -> /profil/username Django - modification of the user info query
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/09/20 00:16:57 by edbernar #+# #+# #
|
# 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
|
@sync_to_async
|
||||||
def getUserInfo(socket, content):
|
def getUserInfo(socket, content):
|
||||||
user = User.objects.filter(id=content['id']).values().first()
|
try:
|
||||||
if (not user):
|
if (content.get('id')):
|
||||||
socket.sync_send({"type":"user_info", "content": None})
|
user = User.objects.filter(id=content['id']).values().first()
|
||||||
return
|
elif (content.get('username')):
|
||||||
socket.sync_send({"type":"user_info", "content":{'username': user['username'], 'pfp': user['pfp'], 'banner': user['banner']}})
|
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)
|
@ -26,7 +26,6 @@ urlpatterns = [
|
|||||||
path("waitingGamePage", views.waitingGamePage, name='waitingGamePage'),
|
path("waitingGamePage", views.waitingGamePage, name='waitingGamePage'),
|
||||||
path("profilPage", views.profilPage, name='profilPage'),
|
path("profilPage", views.profilPage, name='profilPage'),
|
||||||
path("game", views.game, name='game'),
|
path("game", views.game, name='game'),
|
||||||
path("profil", views.profil, name='profil'),
|
|
||||||
path("wait_game", views.game, name='wait_game'),
|
path("wait_game", views.game, name='wait_game'),
|
||||||
path("login42", views.login42, name='login42'),
|
path("login42", views.login42, name='login42'),
|
||||||
path("logout", views.logout, name='logout'),
|
path("logout", views.logout, name='logout'),
|
||||||
|
@ -59,10 +59,6 @@ def wait_game(request):
|
|||||||
# return lobbyPage(request)
|
# return lobbyPage(request)
|
||||||
return redirect('/lobby')
|
return redirect('/lobby')
|
||||||
|
|
||||||
def profil(request):
|
|
||||||
# return lobbyPage(request)
|
|
||||||
return redirect('/lobby')
|
|
||||||
|
|
||||||
def profilPage(request):
|
def profilPage(request):
|
||||||
if(request.method != "POST"):
|
if(request.method != "POST"):
|
||||||
return index(request)
|
return index(request)
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* Page.js :+: :+: :+: */
|
/* Page.js :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: marvin <marvin@student.42.fr> +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/25 00:00:21 by edbernar #+# #+# */
|
/* Created: 2024/08/25 00:00:21 by edbernar #+# #+# */
|
||||||
/* Updated: 2024/09/22 18:58:44 by marvin ### ########.fr */
|
/* Updated: 2024/09/23 00:59:54 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -21,12 +21,12 @@ class Page
|
|||||||
{
|
{
|
||||||
actualPage = null;
|
actualPage = null;
|
||||||
availablePages = [
|
availablePages = [
|
||||||
{url:'/', servUrl: '/homePage', class: HomePage, name: 'homePage', title: 'METH - Home'},
|
{suffix: false, url:'/', servUrl: '/homePage', class: HomePage, name: 'homePage', title: 'METH - Home'},
|
||||||
{url:'/lobby', servUrl: '/lobbyPage', class: LobbyPage, name: 'lobbyPage', title: 'METH - Lobby'},
|
{suffix: false, url:'/lobby', servUrl: '/lobbyPage', class: LobbyPage, name: 'lobbyPage', title: 'METH - Lobby'},
|
||||||
{url:'/game', servUrl: '/multiLocalGamePage', class: multiLocalGamePage, name: 'multiLocalGamePage', title: 'METH - Game'},
|
{suffix: false, url:'/game', servUrl: '/multiLocalGamePage', class: multiLocalGamePage, name: 'multiLocalGamePage', title: 'METH - Game'},
|
||||||
{url:'/wait_game', servUrl: '/waitingGamePage', class: WaitingGamePage, name: 'waitingGamePage', title: 'METH - Wait for a game'},
|
{suffix: false, url:'/wait_game', servUrl: '/waitingGamePage', class: WaitingGamePage, name: 'waitingGamePage', title: 'METH - Wait for a game'},
|
||||||
{url:'/game', servUrl: '/multiOnlineGamePage', class: MultiOnlineGamePage, name: 'multiOnlineGamePage', title: 'METH - Game'},
|
{suffix: false, url:'/game', servUrl: '/multiOnlineGamePage', class: MultiOnlineGamePage, name: 'multiOnlineGamePage', title: 'METH - Game'},
|
||||||
{url:'/profil', servUrl: '/profilPage', class: ProfilPage, name: 'profilPage', title: 'METH - Profil'},
|
{suffix: true, url:'/profil', servUrl: '/profilPage', class: ProfilPage, name: 'profilPage', title: 'METH - Profil'},
|
||||||
]
|
]
|
||||||
|
|
||||||
constructor()
|
constructor()
|
||||||
@ -35,25 +35,31 @@ class Page
|
|||||||
window.onpopstate = function(event) {
|
window.onpopstate = function(event) {
|
||||||
for (let i = 0; i < thisClass.availablePages.length; i++)
|
for (let i = 0; i < thisClass.availablePages.length; i++)
|
||||||
{
|
{
|
||||||
if (window.location.pathname == thisClass.availablePages[i].url)
|
if (window.location.pathname == thisClass.availablePages[i].url || (thisClass.availablePages[i].suffix && window.location.pathname.startsWith(thisClass.availablePages[i].url)))
|
||||||
{
|
{
|
||||||
thisClass.changePage(thisClass.availablePages[i].name, true);
|
let arg = window.location.pathname.slice(thisClass.availablePages[i].url.length + 1);
|
||||||
|
if (arg == "" || !thisClass.availablePages[i].suffix)
|
||||||
|
arg = null;
|
||||||
|
thisClass.changePage(thisClass.availablePages[i].name, true, arg, !thisClass.availablePages[i].suffix);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
for (let i = 0; i < this.availablePages.length; i++)
|
for (let i = 0; i < this.availablePages.length; i++)
|
||||||
{
|
{
|
||||||
if (window.location.pathname == this.availablePages[i].url)
|
if (window.location.pathname == this.availablePages[i].url || (thisClass.availablePages[i].suffix && window.location.pathname.startsWith(thisClass.availablePages[i].url)))
|
||||||
{
|
{
|
||||||
this.changePage(this.availablePages[i].name);
|
let arg = window.location.pathname.slice(thisClass.availablePages[i].url.length + 1);
|
||||||
|
if (arg == "" || !thisClass.availablePages[i].suffix)
|
||||||
|
arg = null;
|
||||||
|
this.changePage(this.availablePages[i].name, false, arg, !thisClass.availablePages[i].suffix);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.#showUnknownPage();
|
this.#showUnknownPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
changePage(name, isBack = false, arg = null)
|
changePage(name, isBack = false, arg = null, needToChangePath = true)
|
||||||
{
|
{
|
||||||
if (this.actualPage != null)
|
if (this.actualPage != null)
|
||||||
this.actualPage.dispose();
|
this.actualPage.dispose();
|
||||||
@ -75,7 +81,12 @@ class Page
|
|||||||
this.actualPage = this.availablePages[i].class;
|
this.actualPage = this.availablePages[i].class;
|
||||||
document.title = this.availablePages[i].title;
|
document.title = this.availablePages[i].title;
|
||||||
if (!isBack)
|
if (!isBack)
|
||||||
history.pushState({}, this.availablePages[i].title, this.availablePages[i].url);
|
{
|
||||||
|
if (needToChangePath)
|
||||||
|
history.pushState({}, this.availablePages[i].title, this.availablePages[i].url);
|
||||||
|
else
|
||||||
|
history.pushState({}, this.availablePages[i].title, window.location.pathname);
|
||||||
|
}
|
||||||
if (arg)
|
if (arg)
|
||||||
this.actualPage.create(arg);
|
this.actualPage.create(arg);
|
||||||
else
|
else
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/19 23:08:31 by edbernar #+# #+# */
|
/* Created: 2024/09/19 23:08:31 by edbernar #+# #+# */
|
||||||
/* Updated: 2024/09/22 23:47:16 by edbernar ### ########.fr */
|
/* Updated: 2024/09/23 00:59:35 by edbernar ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -16,10 +16,11 @@ import { showPrivateChat } from "/static/javascript/liveChat/showPrivateChat.js"
|
|||||||
import { LiveChat, showChatMenu } from "/static/javascript/liveChat/main.js";
|
import { LiveChat, showChatMenu } from "/static/javascript/liveChat/main.js";
|
||||||
import { userMeInfo } from "/static/javascript/typeResponse/typeLogin.js";
|
import { userMeInfo } from "/static/javascript/typeResponse/typeLogin.js";
|
||||||
import { sendRequest } from "/static/javascript/websocket.js";
|
import { sendRequest } from "/static/javascript/websocket.js";
|
||||||
|
import { pageRenderer } from '/static/javascript/main.js'
|
||||||
|
|
||||||
class ProfilPage
|
class ProfilPage
|
||||||
{
|
{
|
||||||
static create(userId)
|
static create(user)
|
||||||
{
|
{
|
||||||
const username = document.getElementsByTagName('h2')[0];
|
const username = document.getElementsByTagName('h2')[0];
|
||||||
const pfp = document.getElementsByClassName('profile-image')[0];
|
const pfp = document.getElementsByClassName('profile-image')[0];
|
||||||
@ -27,13 +28,20 @@ class ProfilPage
|
|||||||
const githubButton = document.getElementById('github');
|
const githubButton = document.getElementById('github');
|
||||||
const discordButton = document.getElementById('discord');
|
const discordButton = document.getElementById('discord');
|
||||||
const convButton = document.getElementById('newConv');
|
const convButton = document.getElementById('newConv');
|
||||||
let usernameText = null;
|
|
||||||
|
|
||||||
LiveChat.create();
|
LiveChat.create();
|
||||||
|
if (typeof(user) == 'string')
|
||||||
sendRequest("get_user_info", {id: userId});
|
sendRequest("get_user_info", {username: user});
|
||||||
|
else
|
||||||
|
sendRequest("get_user_info", {id: user});
|
||||||
waitForUserInfo().then((userInfo) => {
|
waitForUserInfo().then((userInfo) => {
|
||||||
usernameText = userInfo.username;
|
if (userInfo == null)
|
||||||
|
{
|
||||||
|
pageRenderer.changePage('homePage');
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (typeof(user) != 'string')
|
||||||
|
history.replaceState({}, document.title, window.location.pathname + '/' + userInfo.username);
|
||||||
username.innerText = userInfo.username + ' (status not implemented)';
|
username.innerText = userInfo.username + ' (status not implemented)';
|
||||||
pfp.style.backgroundImage = `url("${userInfo.pfp}")`
|
pfp.style.backgroundImage = `url("${userInfo.pfp}")`
|
||||||
pfp.style.backgroundSize = "cover";
|
pfp.style.backgroundSize = "cover";
|
||||||
@ -41,21 +49,21 @@ class ProfilPage
|
|||||||
banner.style.backgroundImage = `url("${userInfo.banner}")`
|
banner.style.backgroundImage = `url("${userInfo.banner}")`
|
||||||
banner.style.backgroundSize = "cover";
|
banner.style.backgroundSize = "cover";
|
||||||
banner.style.backgroundRepeat = "no-repeat";
|
banner.style.backgroundRepeat = "no-repeat";
|
||||||
if (userId == userMeInfo.id)
|
if (userInfo.id == userMeInfo.id)
|
||||||
{
|
{
|
||||||
pfp.innerHTML = `<div id='editPenPfpBg'><img class='editPenPfp' src='/static/img/profilPage/editPen.png'/></div>`
|
pfp.innerHTML = `<div id='editPenPfpBg'><img class='editPenPfp' src='/static/img/profilPage/editPen.png'/></div>`
|
||||||
banner.innerHTML = `<img class='editPen' src='/static/img/profilPage/editPen.png'/>`
|
banner.innerHTML = `<img class='editPen' src='/static/img/profilPage/editPen.png'/>`
|
||||||
}
|
}
|
||||||
|
if (userInfo.id != userMeInfo.id)
|
||||||
|
{
|
||||||
|
convButton.addEventListener('click', () => {
|
||||||
|
showChatMenu();
|
||||||
|
showPrivateChat({id: userInfo.id, name: userInfo.username});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
convButton.remove();
|
||||||
});
|
});
|
||||||
if (userId != userMeInfo.id)
|
|
||||||
{
|
|
||||||
convButton.addEventListener('click', () => {
|
|
||||||
showChatMenu();
|
|
||||||
showPrivateChat({id: userId, name: usernameText});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
convButton.remove();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static dispose()
|
static dispose()
|
||||||
|
Reference in New Issue
Block a user