Ny inloggning, formulär innnan. Fixes #7
This commit is contained in:
@@ -10,7 +10,35 @@ if ('serviceWorker' in navigator) {
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('taskForm').addEventListener('submit', function(e) {
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const loginForm = document.getElementById('loginForm');
|
||||
const loginContainer = document.getElementById('loginContainer');
|
||||
const appContainer = document.getElementById('appContainer');
|
||||
const loginMessage = document.getElementById('loginMessage');
|
||||
|
||||
// Check if user is already logged in
|
||||
if (sessionStorage.getItem('loggedIn') === 'true') {
|
||||
loginContainer.style.display = 'none';
|
||||
appContainer.style.display = 'block';
|
||||
}
|
||||
|
||||
loginForm.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const username = document.getElementById('username').value;
|
||||
const password = document.getElementById('password').value;
|
||||
|
||||
// Simple authentication check (replace with your own logic)
|
||||
if (username === 'admin' && password === 'password') {
|
||||
sessionStorage.setItem('loggedIn', 'true');
|
||||
loginContainer.style.display = 'none';
|
||||
appContainer.style.display = 'block';
|
||||
} else {
|
||||
loginMessage.textContent = 'Invalid username or password';
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('taskForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Get form values
|
||||
@@ -40,4 +68,5 @@ document.getElementById('taskForm').addEventListener('submit', function(e) {
|
||||
.catch(error => {
|
||||
document.getElementById('responseMessage').textContent = "Error saving task!";
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,7 +13,23 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div id="loginContainer" class="container">
|
||||
<h1 class="center-align">Login</h1>
|
||||
<form id="loginForm">
|
||||
<div class="input-field">
|
||||
<label for="username">Username:</label>
|
||||
<input type="text" id="username" required>
|
||||
</div>
|
||||
<div class="input-field">
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" required>
|
||||
</div>
|
||||
<button class="btn waves-effect waves-light" type="submit">Login</button>
|
||||
</form>
|
||||
<p id="loginMessage" class="center-align"></p>
|
||||
</div>
|
||||
|
||||
<div id="appContainer" class="container" style="display:none;">
|
||||
<h1 class="center-align">TODO</h1>
|
||||
<form id="taskForm">
|
||||
<div class="input-field">
|
||||
|
||||
Reference in New Issue
Block a user