From 33026f6a9e7ec97b2e37b882fb5c929d0c799380 Mon Sep 17 00:00:00 2001 From: Modo Date: Sun, 15 Oct 2023 01:31:54 +0530 Subject: [PATCH] Finish Login Data Request --- frontend/index.html | 6 ++++ frontend/index.js | 74 +++++++++++++++++++++++++++++++++++++++++++++ frontend/style.css | 22 ++++++++++++++ 3 files changed, 102 insertions(+) diff --git a/frontend/index.html b/frontend/index.html index d3bb402..7aa86f3 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -31,6 +31,10 @@ +
+ +
+
@@ -39,4 +43,6 @@ + + diff --git a/frontend/index.js b/frontend/index.js index e69de29..3009ebc 100644 --- a/frontend/index.js +++ b/frontend/index.js @@ -0,0 +1,74 @@ +let loginb = document.getElementById("loginb"); +let _username; +let _password; + +loginb.addEventListener("click", validateLogin); + +function validateName() { +var name = document.getElementById("username").value; + if(name=='' || name==null){ + // console.log("falsevn"); + document.getElementById("errlabel").innerHTML = "Enter Username!"; + setTimeout(()=> { + document.getElementById("errlabel").innerHTML = ""; + },3000) + return false; + } else { + // console.log("truevn"); + return true; + } +} + +function validatePass() { + var pass = document.getElementById("password").value; + if(pass=='' || pass==null){ + // console.log("falsevp"); + document.getElementById("errlabel").innerHTML = "Enter Password!"; + setTimeout(()=> { + document.getElementById("errlabel").innerHTML = ""; + },3000) + return false; + } else { + // console.log("truevp"); + return true; + } + } + +function validateLogin() { + if(validateName() && validatePass()) { + getLD(); + return; + } +} + +function getLD() { + _username = document.getElementById("username").value; + _mpassword = document.getElementById("password").value; + let loginData = { + user_name: _username, + password: _password + } + fetch('http://127.0.0.1:5000', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(loginData) + }) + .then(res => { + return res.json() + }) + .then(data => { + handleAuthRes(data); + }) + .catch(error => console.log(`You have ${error}`)) +} + +function handleAuthRes(data) { + if(data.token){ + localStorage.setItem('token', token.data); + console.log("Logged In...") + } else { + console.error('Login Failed:', data.error) + } +} \ No newline at end of file diff --git a/frontend/style.css b/frontend/style.css index 12faaf7..604591b 100644 --- a/frontend/style.css +++ b/frontend/style.css @@ -11,6 +11,7 @@ body { background-image: url("bg.jpg"); background-size: cover; background-position: center; + background-repeat: no-repeat; } .wrapper { @@ -117,12 +118,25 @@ body { } + .help div{ display: flex; width: 50%; justify-content: center; } +.error label { + position: absolute; + display: block; + justify-content: center; + translate: -50% 3px; + color: rgba(184, 156, 255, 0.9); + font-family: Arial, Helvetica, sans-serif; + font-size: 12px; + font-style: bold; + font-weight: bold; +} + a { text-decoration: none; color: rgba(255, 255, 255, 0.5); @@ -133,4 +147,12 @@ a { a:active { color: rgb(196, 196, 196, 10); +} + +footer{ + position: fixed; + bottom: 0px; + background-color: rgb(12, 12, 12); + height: 50px; + width: 100vw; } \ No newline at end of file