Skip to content

Commit 72f9e58

Browse files
committed
feat: enhance login page
1 parent 10dfcc8 commit 72f9e58

1 file changed

Lines changed: 39 additions & 37 deletions

File tree

login.html

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<!DOCTYPE html>
22
<html lang="it">
3+
34
<head>
4-
<meta charset="UTF-8">
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6-
<title>Log in</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Log in</title>
78

8-
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
9-
<link href="assets/css/style.css" rel="stylesheet">
9+
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
10+
<link href="assets/css/style.css" rel="stylesheet">
1011
</head>
1112

1213
<body>
@@ -31,12 +32,12 @@ <h2>Log In</h2>
3132
const otp_txt = document.getElementById("otp_txt");
3233
const checkOtpBtn = document.getElementById("checkOtpBtn");
3334

34-
loginBtn.addEventListener('click', function() {
35+
loginBtn.addEventListener('click', function () {
3536
const data = {
3637
"username": username_txt.value,
3738
"password": password_txt.value
3839
};
39-
40+
4041
fetch("http://localhost:3000/api/login",
4142
{
4243
method: "POST",
@@ -46,33 +47,33 @@ <h2>Log In</h2>
4647
body: JSON.stringify(data)
4748
}
4849
)
49-
.then(response => response.json())
50-
.then(data => {
51-
if(data["STATUS_CODE"] == 202) {
52-
username_txt.style.display = "none";
53-
loginBtn.style.display = "none";
54-
password_txt.style.display = "none";
55-
56-
otp_txt.style.display = "block";
57-
checkOtpBtn.style.display = "block";
58-
59-
setCookie("pendingID", data["PENDING_ID"], 10);
60-
}
61-
62-
else {
63-
alert("An error occurred:\nSTATUS CODE: " + data["STATUS_CODE"] + "\n\n" + data["MESSAGE"]);
64-
}
65-
});
50+
.then(response => response.json())
51+
.then(data => {
52+
if (data["STATUS_CODE"] == 202) {
53+
username_txt.style.display = "none";
54+
loginBtn.style.display = "none";
55+
password_txt.style.display = "none";
56+
57+
otp_txt.style.display = "block";
58+
checkOtpBtn.style.display = "block";
59+
60+
setCookie("pendingID", data["PENDING_ID"], 10);
61+
}
62+
63+
else {
64+
alert("An error occurred:\nSTATUS CODE: " + data["STATUS_CODE"] + "\n\n" + data["MESSAGE"]);
65+
}
66+
});
6667
});
6768

68-
checkOtpBtn.addEventListener('click', function() {
69+
checkOtpBtn.addEventListener('click', function () {
6970
let pendingID = getCookie("pendingID");
7071

7172
const data = {
7273
"pendingID": pendingID,
7374
"otp": otp_txt.value
7475
};
75-
76+
7677
fetch("http://localhost:3000/api/otp_verification",
7778
{
7879
method: "POST",
@@ -82,16 +83,16 @@ <h2>Log In</h2>
8283
body: JSON.stringify(data)
8384
}
8485
)
85-
.then(response => response.json())
86-
.then(data => {
87-
if(data["STATUS_CODE"] == 200) {
88-
alert("Login successful:\nSTATUS CODE: " + data["STATUS_CODE"] + "\n\n" + data["MESSAGE"] + "\n\n\nI hope this repository has been helpful in understanding and learning how to manage a secure login!\n\nFeel free to experiment you can modify and improve my code, add extra checks, or implement new actions to execute after login.");
89-
}
90-
91-
else {
92-
alert("An error occurred:\nSTATUS CODE: " + data["STATUS_CODE"] + "\n\n" + data["MESSAGE"]);
93-
}
94-
});
86+
.then(response => response.json())
87+
.then(data => {
88+
if (data["STATUS_CODE"] == 200) {
89+
alert("Login successful:\nSTATUS CODE: " + data["STATUS_CODE"] + "\n\n" + data["MESSAGE"] + "\n\n\nI hope this repository has been helpful in understanding and learning how to manage a secure login!\n\nFeel free to experiment you can modify and improve my code, add extra checks, or implement new actions to execute after login.");
90+
}
91+
92+
else {
93+
alert("An error occurred:\nSTATUS CODE: " + data["STATUS_CODE"] + "\n\n" + data["MESSAGE"]);
94+
}
95+
});
9596
});
9697

9798
function setCookie(name, value, minutes) {
@@ -101,7 +102,7 @@ <h2>Log In</h2>
101102
date.setTime(date.getTime() + (minutes * 60 * 1000));
102103
expires = "; expires=" + date.toUTCString();
103104
}
104-
document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
105+
document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/; secure";
105106
}
106107

107108
function getCookie(name) {
@@ -118,4 +119,5 @@ <h2>Log In</h2>
118119

119120
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
120121
</body>
122+
121123
</html>

0 commit comments

Comments
 (0)