-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73f24da
commit 5f727fa
Showing
9 changed files
with
165 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// auth.js | ||
|
||
function registerUser() { | ||
const username = document.getElementById('newUsername').value; | ||
const password = document.getElementById('newPassword').value; | ||
|
||
// Store the new user in local storage | ||
localStorage.setItem('username', username); | ||
localStorage.setItem('password', password); | ||
|
||
alert('Registration successful! Please log in.'); | ||
window.location.href = '../scorm_package/login.html'; | ||
return false; | ||
} | ||
|
||
function loginUser() { | ||
const username = document.getElementById('username').value; | ||
const password = document.getElementById('password').value; | ||
const rememberMe = document.getElementById('rememberMe').checked; | ||
|
||
const storedUsername = localStorage.getItem('username'); | ||
const storedPassword = localStorage.getItem('password'); | ||
|
||
if (username === storedUsername && password === storedPassword) { | ||
if (rememberMe) { | ||
localStorage.setItem('loggedInUser', username); | ||
} | ||
sessionStorage.setItem('loggedInUser', username); | ||
alert('Login successful!'); | ||
window.location.href = '../scorm_package/chapter1.html'; // Redirect to the first chapter | ||
} else { | ||
alert('Invalid username or password!'); | ||
} | ||
return false; | ||
} | ||
|
||
function logoutUser() { | ||
sessionStorage.removeItem('loggedInUser'); | ||
alert('You have been logged out.'); | ||
window.location.href = '../scorm_package/login.html'; | ||
} | ||
|
||
function checkLogin() { | ||
const loggedInUser = sessionStorage.getItem('loggedInUser') || localStorage.getItem('loggedInUser'); | ||
|
||
if (!loggedInUser) { | ||
alert('You are not logged in. Please log in first.'); | ||
window.location.href = '../scorm_package/login.html'; | ||
} | ||
} | ||
|
||
window.onload = checkLogin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Login</title> | ||
<script src="../_static/auth.js"></script> | ||
</head> | ||
<body> | ||
<h1>Login</h1> | ||
<form onsubmit="return loginUser()"> | ||
<label for="username">Username:</label><br> | ||
<input type="text" id="username" name="username" required><br> | ||
<label for="password">Password:</label><br> | ||
<input type="password" id="password" name="password" required><br> | ||
<input type="checkbox" id="rememberMe" name="rememberMe"> Remember Me<br><br> | ||
<input type="submit" value="Login"> | ||
</form> | ||
<p>Don't have an account? <a href="signup.html">Sign Up</a></p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Sign Up</title> | ||
<script src="../_static/auth.js"></script> | ||
</head> | ||
<body> | ||
<h1>Sign Up</h1> | ||
<form onsubmit="return registerUser()"> | ||
<label for="newUsername">Username:</label><br> | ||
<input type="text" id="newUsername" name="newUsername" required><br> | ||
<label for="newPassword">Password:</label><br> | ||
<input type="password" id="newPassword" name="newPassword" required><br><br> | ||
<input type="submit" value="Sign Up"> | ||
</form> | ||
<p>Already have an account? <a href="login.html">Login</a></p> | ||
</body> | ||
</html> |