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) {
|
||||
e.preventDefault();
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const loginForm = document.getElementById('loginForm');
|
||||
const loginContainer = document.getElementById('loginContainer');
|
||||
const appContainer = document.getElementById('appContainer');
|
||||
const loginMessage = document.getElementById('loginMessage');
|
||||
|
||||
// Get form values
|
||||
const subject = document.getElementById('subject').value;
|
||||
const description = document.getElementById('description').value;
|
||||
const scheduled = document.getElementById('scheduled').value;
|
||||
// Check if user is already logged in
|
||||
if (sessionStorage.getItem('loggedIn') === 'true') {
|
||||
loginContainer.style.display = 'none';
|
||||
appContainer.style.display = 'block';
|
||||
}
|
||||
|
||||
// Structure data for Org mode
|
||||
const taskData = {
|
||||
subject,
|
||||
description,
|
||||
scheduled
|
||||
};
|
||||
loginForm.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// 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!";
|
||||
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
|
||||
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>
|
||||
</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