GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fixes to database localstorage system · codingandcommunity/hackathon@8617883

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • social_media
    • createAccount.html
    • login.html
    • scripts.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎social_media/createAccount.html‎

Copy file name to clipboardExpand all lines: social_media/createAccount.html
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<body>
1111
<h1 id="logoText" onclick="window.location.href='index.html';">Title of Social Media Platform</h1> <!-- Clickable logo leads to index page -->
12-
<form id="login" name="login" action="#" method="post" onsubmit="return add(this);">
12+
<form id="login" name="login" action="#" method="post" onsubmit="return addUser(this);">
1313
<fieldset>
1414
<legend>Create Account</legend>
1515
<div class="formData">
Collapse file

‎social_media/login.html‎

Copy file name to clipboardExpand all lines: social_media/login.html
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
<title>Login</title>
55
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
66
<link rel="stylesheet" type="text/css" href="resources/styles.css"/>
7+
<script type="text/javascript" src="resources/jquery-3.3.1.min.js"/>
78
<script type="text/javascript" src="scripts.js"></script>
89
</head>
910

1011
<body>
1112
<h1 id="logoText" onclick="window.location.href='index.html';">Title of Social Media Platform</h1> <!-- Clickable logo leads to index page -->
12-
<form id="login" name="login" action="#" method="post" onsubmit="return validate(this);">
13+
<form id="login" name="login" action="#" method="post" onsubmit="return loginUser(this);">
1314
<fieldset>
1415
<legend>Login</legend>
1516
<div class="formData">
Collapse file

‎social_media/scripts.js‎

Copy file name to clipboardExpand all lines: social_media/scripts.js
+34-6Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
function getDatabase() {
2+
return JSON.parse(window.localStorage.getItem("database"));
3+
}
4+
5+
function saveDatabase(database) {
6+
window.localStorage.setItem("database", JSON.stringify(database));
7+
}
18

29
window.onload = function() {
10+
var database;
311
if (window.localStorage.length == 0) {
12+
413
//initialize database
514
database = {
615
"users": [
@@ -15,11 +24,18 @@ window.onload = function() {
1524
]
1625
//Can add more tables here ex: "posts": []
1726
}
18-
19-
window.localStorage.setItem("database", database);
27+
saveDatabase(database);
28+
} else {
29+
database = getDatabase();
2030
}
31+
console.log(database);
2132
};
2233

34+
function redirect(url) {
35+
console.log("Redirecting to " + url);
36+
window.location.href = url;
37+
}
38+
2339
function validate(formObj) {
2440
// validation code
2541
var alertString = "";
@@ -55,12 +71,24 @@ function validate(formObj) {
5571
}
5672

5773
//called in createAccount.html
58-
function add(formObj) {
74+
function addUser(formObj) {
5975
if (validate(formObj)) {
60-
database["users"].push({"username": formObj.usename.value, "password": formObj.password.value});
61-
window.localStorage.setItem("database", database);
76+
database = getDatabase();
77+
database.users.push({"username": formObj.username.value, "password": formObj.password.value});
78+
saveDatabase(database);
6279
return true;
6380
} else {
6481
return false;
6582
}
66-
}
83+
}
84+
85+
function loginUser(formObj) {
86+
// first check if the user exists in the database
87+
database = getDatabase();
88+
console.log(formObj.username.value);
89+
database.users.forEach(function(user) {
90+
if (user.username == formObj.username.value && user.password == formObj.password.value) {
91+
redirect('/index.html');
92+
}
93+
});
94+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.