diff --git a/site/interface/site/login/createConnectDiv.js b/site/interface/site/login/createConnectDiv.js index f5a6d88..fd75f33 100644 --- a/site/interface/site/login/createConnectDiv.js +++ b/site/interface/site/login/createConnectDiv.js @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* createConnectDiv.js :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: edbernar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/07 18:14:53 by edbernar #+# #+# */ -/* Updated: 2024/08/07 22:33:39 by edbernar ### ########.fr */ +/* Updated: 2024/08/08 17:27:14 by edbernar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,12 +14,13 @@ import { userMeInfo, waitForLogin } from "../typeResponse/typeLogin.js"; import { createNotification as CN } from "../notification/main.js"; import { sendRequest } from "../websocket.js"; -function createConnectDiv() +function createConnectDiv(divLogin) { - const divConnect = document.createElement("div"); - const inputLogin = document.createElement("input"); - const inputPass = document.createElement("input"); - const buttonLogin = createButton(inputLogin, inputPass); + const divConnect = document.createElement("div"); + const inputLogin = document.createElement("input"); + const inputPass = document.createElement("input"); + const buttonLogin = createButton(inputLogin, inputPass); + const buttonNewAcc = createButtonNewAcc(divConnect, divLogin); addGlobalBg(); divConnect.setAttribute("id", "connectDiv"); @@ -31,6 +32,7 @@ function createConnectDiv() divConnect.appendChild(inputLogin); divConnect.appendChild(inputPass); divConnect.appendChild(buttonLogin); + divConnect.appendChild(buttonNewAcc); return (divConnect); } @@ -42,25 +44,82 @@ function addGlobalBg() document.body.appendChild(globalBg); } +async function hashPassword(password) +{ + const encoder = new TextEncoder(); + const data = encoder.encode(password); + const hash = await crypto.subtle.digest('SHA-256', data); + const hashArray = Array.from(new Uint8Array(hash)); + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + + return (hashHex); +} + function createButton(inputLogin, inputPass) { const loginButton = document.getElementById('loginButton'); const pLoginButton = loginButton.getElementsByTagName('p')[0]; const button = document.createElement("button"); let usernameNode = null; + let hashedPass = null; button.addEventListener('click', () => { - sendRequest("login", {type: "byPass", mail: inputLogin.value, password: inputPass.value}); - waitForLogin().then((token) => { - usernameNode = document.createTextNode(userMeInfo.username); - loginButton.replaceChild(usernameNode, pLoginButton); - CN.new("Connected successfully", "Welcome " + userMeInfo.username, CN.defaultIcon.success); - document.getElementById("loginDiv").remove(); - document.getElementById("globalBg").remove(); - document.cookie = "token={" + token + "}; path=/; Secure; SameSite=Strict; max-age=3600"; + hashPassword(inputPass.value).then((hash) => { + hashedPass = hash; + sendRequest("login", {type: "byPass", mail: inputLogin.value, password: hashedPass}); + waitForLogin().then((token) => { + usernameNode = document.createTextNode(userMeInfo.username); + loginButton.replaceChild(usernameNode, pLoginButton); + CN.new("Connected successfully", "Welcome " + userMeInfo.username, CN.defaultIcon.success); + document.getElementById("loginDiv").remove(); + document.getElementById("globalBg").remove(); + document.cookie = "token={" + token + "}; path=/; Secure; SameSite=Strict; max-age=3600"; + }); + }).catch((err) => { + CN.new("Error", "An error occured while trying to connect", CN.defaultIcon.error); }); }); return (button); } +function createButtonNewAcc(divConnect, divLogin) +{ + const button = document.createElement("button"); + const newDiv = document.createElement("div"); + const inputUsername = document.createElement("input"); + const inputMail = document.createElement("input"); + const inputPass = document.createElement("input"); + const buttonCreate = document.createElement("button"); + + button.innerHTML = "Create a new account"; + newDiv.setAttribute("id", "connectDiv"); + button.addEventListener('click', () => { + inputUsername.setAttribute("type", "text"); + inputUsername.setAttribute("placeholder", "username"); + inputMail.setAttribute("type", "text"); + inputMail.setAttribute("placeholder", "mail"); + inputPass.setAttribute("type", "password"); + inputPass.setAttribute("placeholder", "password"); + buttonCreate.innerHTML = "Create"; + newDiv.appendChild(inputUsername); + newDiv.appendChild(inputMail); + newDiv.appendChild(inputPass); + newDiv.appendChild(buttonCreate); + button.addEventListener('click', createNewAccount); + divConnect.remove(); + divLogin.appendChild(newDiv); + }); + return (button); +} + +function createNewAccount() +{ + const inputUsername = document.getElementsByTagName("input")[0]; + const inputMail = document.getElementsByTagName("input")[1]; + const inputPass = document.getElementsByTagName("input")[2]; + + console.warn("Faire la requete pour creer un compte"); +} + + export { createConnectDiv }; \ No newline at end of file diff --git a/site/interface/site/login/main.js b/site/interface/site/login/main.js index e10cecf..a467f9b 100644 --- a/site/interface/site/login/main.js +++ b/site/interface/site/login/main.js @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* main.js :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: edbernar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/07 17:40:15 by edbernar #+# #+# */ -/* Updated: 2024/08/07 22:31:31 by edbernar ### ########.fr */ +/* Updated: 2024/08/08 17:07:12 by edbernar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,7 +35,7 @@ function showLoginDiv() { const divLogin = document.createElement("div"); const threeDiv = createThreeDiv(); - const connectDiv = createConnectDiv(); + const connectDiv = createConnectDiv(divLogin); divLogin.setAttribute("id", "loginDiv"); divLogin.appendChild(threeDiv); diff --git a/websocket-server/Class/__pycache__/User.cpython-310.pyc b/websocket-server/Class/__pycache__/User.cpython-310.pyc deleted file mode 100644 index 4a2a25b..0000000 Binary files a/websocket-server/Class/__pycache__/User.cpython-310.pyc and /dev/null differ diff --git a/websocket-server/typeRequets/__pycache__/getPrivateListMessage.cpython-310.pyc b/websocket-server/typeRequets/__pycache__/getPrivateListMessage.cpython-310.pyc deleted file mode 100644 index 0d47c91..0000000 Binary files a/websocket-server/typeRequets/__pycache__/getPrivateListMessage.cpython-310.pyc and /dev/null differ diff --git a/websocket-server/typeRequets/__pycache__/getPrivateListUser.cpython-310.pyc b/websocket-server/typeRequets/__pycache__/getPrivateListUser.cpython-310.pyc deleted file mode 100644 index 23ce98c..0000000 Binary files a/websocket-server/typeRequets/__pycache__/getPrivateListUser.cpython-310.pyc and /dev/null differ diff --git a/websocket-server/typeRequets/__pycache__/login.cpython-310.pyc b/websocket-server/typeRequets/__pycache__/login.cpython-310.pyc deleted file mode 100644 index b7fd735..0000000 Binary files a/websocket-server/typeRequets/__pycache__/login.cpython-310.pyc and /dev/null differ diff --git a/websocket-server/typeRequets/__pycache__/sendPrivateMessage.cpython-310.pyc b/websocket-server/typeRequets/__pycache__/sendPrivateMessage.cpython-310.pyc deleted file mode 100644 index ef1faae..0000000 Binary files a/websocket-server/typeRequets/__pycache__/sendPrivateMessage.cpython-310.pyc and /dev/null differ diff --git a/websocket-server/typeRequets/login.py b/websocket-server/typeRequets/login.py index 31c3657..7e37f34 100644 --- a/websocket-server/typeRequets/login.py +++ b/websocket-server/typeRequets/login.py @@ -3,10 +3,10 @@ # ::: :::::::: # # login.py :+: :+: :+: # # +:+ +:+ +:+ # -# By: edbernar +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/08/03 08:10:38 by edbernar #+# #+# # -# Updated: 2024/08/07 22:21:58 by edbernar ### ########.fr # +# Updated: 2024/08/08 16:42:43 by edbernar ### ########.fr # # # # **************************************************************************** # @@ -25,13 +25,14 @@ userList = [ "token": "IDSNCSDAd465sd13215421", "mail": "eddy@ediwor.fr", "password": "ABC123", - "id": 9999999 + "id": 9999999, + 'id42': 123456 }, { "username": "Eddy", "token": "54dsadw8f4a6w5f4a62s4f984fa62f4as65", "mail": "aaaaa", - "password": "aaaaa", + "password": "ed968e840d10d2d313a870bc131a4e2c311d7ad09bdf32b3418147221f51a6e2", # not hashed : aaaaa "id": 2135421 }, { @@ -45,7 +46,7 @@ userList = [ "username": "Mathis", "token": "8cb1qjlfndc12mn2l1mn654xzkkhad54cxz", "mail": "ccccc", - "password": "ccccc", + "password": "6304fbfe2b22557c34c42a70056616786a733b3d09fb326308c813d6ab712ec0", # not hashed : ccccc "id": 2371234 }, {