Ny inloggning, formulär innnan. Fixes #7
This commit is contained in:
@@ -10,34 +10,63 @@ if ('serviceWorker' in navigator) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('taskForm').addEventListener('submit', function(e) {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
e.preventDefault();
|
const loginForm = document.getElementById('loginForm');
|
||||||
|
const loginContainer = document.getElementById('loginContainer');
|
||||||
|
const appContainer = document.getElementById('appContainer');
|
||||||
|
const loginMessage = document.getElementById('loginMessage');
|
||||||
|
|
||||||
// Get form values
|
// Check if user is already logged in
|
||||||
const subject = document.getElementById('subject').value;
|
if (sessionStorage.getItem('loggedIn') === 'true') {
|
||||||
const description = document.getElementById('description').value;
|
loginContainer.style.display = 'none';
|
||||||
const scheduled = document.getElementById('scheduled').value;
|
appContainer.style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
// Structure data for Org mode
|
loginForm.addEventListener('submit', function(e) {
|
||||||
const taskData = {
|
e.preventDefault();
|
||||||
subject,
|
|
||||||
description,
|
|
||||||
scheduled
|
|
||||||
};
|
|
||||||
|
|
||||||
// Send data to backend using fetch
|
const username = document.getElementById('username').value;
|
||||||
fetch('/add-task', {
|
const password = document.getElementById('password').value;
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
// Simple authentication check (replace with your own logic)
|
||||||
'Content-Type': 'application/json',
|
if (username === 'admin' && password === 'password') {
|
||||||
},
|
sessionStorage.setItem('loggedIn', 'true');
|
||||||
body: JSON.stringify(taskData)
|
loginContainer.style.display = 'none';
|
||||||
})
|
appContainer.style.display = 'block';
|
||||||
.then(response => response.json())
|
} else {
|
||||||
.then(data => {
|
loginMessage.textContent = 'Invalid username or password';
|
||||||
document.getElementById('responseMessage').textContent = data.message;
|
}
|
||||||
})
|
});
|
||||||
.catch(error => {
|
|
||||||
document.getElementById('responseMessage').textContent = "Error saving task!";
|
document.getElementById('taskForm').addEventListener('submit', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// Get form values
|
||||||
|
const subject = document.getElementById('subject').value;
|
||||||
|
const description = document.getElementById('description').value;
|
||||||
|
const scheduled = document.getElementById('scheduled').value;
|
||||||
|
|
||||||
|
// Structure data for Org mode
|
||||||
|
const taskData = {
|
||||||
|
subject,
|
||||||
|
description,
|
||||||
|
scheduled
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send data to backend using fetch
|
||||||
|
fetch('/add-task', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(taskData)
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
document.getElementById('responseMessage').textContent = data.message;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
document.getElementById('responseMessage').textContent = "Error saving task!";
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,23 @@
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
|
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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>
|
<h1 class="center-align">TODO</h1>
|
||||||
<form id="taskForm">
|
<form id="taskForm">
|
||||||
<div class="input-field">
|
<div class="input-field">
|
||||||
|
|||||||
Reference in New Issue
Block a user