Compare commits
1 Commits
1122de442b
...
reset
| Author | SHA1 | Date | |
|---|---|---|---|
| 90d7f2a5d2 |
9
.vscode/settings.json
vendored
9
.vscode/settings.json
vendored
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"files.exclude": {
|
|
||||||
"**/*.png": true,
|
|
||||||
"**/*.jpg": true,
|
|
||||||
"**/*.gif": true,
|
|
||||||
"**/*.svg": true,
|
|
||||||
"**/*.ico": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BIN
favicon.ico
Normal file
BIN
favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
@@ -1,10 +1,15 @@
|
|||||||
const basicAuth = require('basic-auth');
|
const basicAuth = require('basic-auth');
|
||||||
|
|
||||||
const auth = (req, res, next) => {
|
const auth = (req, res, next) => {
|
||||||
if (req.session && req.session.user) {
|
const user = basicAuth(req);
|
||||||
|
const username = process.env.AUTH_USERNAME; // Use environment variables
|
||||||
|
const password = process.env.AUTH_PASSWORD; // Use environment variables
|
||||||
|
|
||||||
|
if (user && user.name === username && user.pass === password) {
|
||||||
return next();
|
return next();
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send('Authentication required.');
|
res.set('WWW-Authenticate', 'Basic realm="401"');
|
||||||
|
return res.status(401).send('Authentication required.');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
93
package-lock.json
generated
93
package-lock.json
generated
@@ -11,11 +11,9 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"basic-auth": "^2.0.1",
|
"basic-auth": "^2.0.1",
|
||||||
"body-parser": "^1.20.3",
|
"body-parser": "^1.20.3",
|
||||||
"cookie-parser": "^1.4.7",
|
|
||||||
"debug": "^4.4.0",
|
"debug": "^4.4.0",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"express-session": "^1.18.1",
|
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
"winston": "^3.17.0"
|
"winston": "^3.17.0"
|
||||||
}
|
}
|
||||||
@@ -219,26 +217,6 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/cookie-parser": {
|
|
||||||
"version": "1.4.7",
|
|
||||||
"resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.7.tgz",
|
|
||||||
"integrity": "sha512-nGUvgXnotP3BsjiLX2ypbQnWoGUPIIfHQNZkkC668ntrzGWEZVW70HDEB1qnNGMicPje6EttlIgzo51YSwNQGw==",
|
|
||||||
"dependencies": {
|
|
||||||
"cookie": "0.7.2",
|
|
||||||
"cookie-signature": "1.0.6"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.8.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/cookie-parser/node_modules/cookie": {
|
|
||||||
"version": "0.7.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
|
|
||||||
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/cookie-signature": {
|
"node_modules/cookie-signature": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
|
||||||
@@ -404,50 +382,6 @@
|
|||||||
"url": "https://opencollective.com/express"
|
"url": "https://opencollective.com/express"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/express-session": {
|
|
||||||
"version": "1.18.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/express-session/-/express-session-1.18.1.tgz",
|
|
||||||
"integrity": "sha512-a5mtTqEaZvBCL9A9aqkrtfz+3SMDhOVUnjafjo+s7A9Txkq+SVX2DLvSp1Zrv4uCXa3lMSK3viWnh9Gg07PBUA==",
|
|
||||||
"dependencies": {
|
|
||||||
"cookie": "0.7.2",
|
|
||||||
"cookie-signature": "1.0.7",
|
|
||||||
"debug": "2.6.9",
|
|
||||||
"depd": "~2.0.0",
|
|
||||||
"on-headers": "~1.0.2",
|
|
||||||
"parseurl": "~1.3.3",
|
|
||||||
"safe-buffer": "5.2.1",
|
|
||||||
"uid-safe": "~2.1.5"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.8.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/express-session/node_modules/cookie": {
|
|
||||||
"version": "0.7.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
|
|
||||||
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/express-session/node_modules/cookie-signature": {
|
|
||||||
"version": "1.0.7",
|
|
||||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz",
|
|
||||||
"integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA=="
|
|
||||||
},
|
|
||||||
"node_modules/express-session/node_modules/debug": {
|
|
||||||
"version": "2.6.9",
|
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
|
||||||
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
|
|
||||||
"dependencies": {
|
|
||||||
"ms": "2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/express-session/node_modules/ms": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
|
||||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="
|
|
||||||
},
|
|
||||||
"node_modules/express/node_modules/debug": {
|
"node_modules/express/node_modules/debug": {
|
||||||
"version": "2.6.9",
|
"version": "2.6.9",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
|
||||||
@@ -771,14 +705,6 @@
|
|||||||
"node": ">= 0.8"
|
"node": ">= 0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/on-headers": {
|
|
||||||
"version": "1.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
|
|
||||||
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/one-time": {
|
"node_modules/one-time": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/one-time/-/one-time-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/one-time/-/one-time-1.0.0.tgz",
|
||||||
@@ -826,14 +752,6 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/random-bytes": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz",
|
|
||||||
"integrity": "sha512-iv7LhNVO047HzYR3InF6pUcUsPQiHTM1Qal51DcGSuZFBil1aBBWG5eHPNek7bvILMaYJ/8RU1e8w1AMdHmLQQ==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/range-parser": {
|
"node_modules/range-parser": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
|
||||||
@@ -1097,17 +1015,6 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/uid-safe": {
|
|
||||||
"version": "2.1.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz",
|
|
||||||
"integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==",
|
|
||||||
"dependencies": {
|
|
||||||
"random-bytes": "~1.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 0.8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/unpipe": {
|
"node_modules/unpipe": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||||
|
|||||||
@@ -12,11 +12,9 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"basic-auth": "^2.0.1",
|
"basic-auth": "^2.0.1",
|
||||||
"body-parser": "^1.20.3",
|
"body-parser": "^1.20.3",
|
||||||
"cookie-parser": "^1.4.7",
|
|
||||||
"debug": "^4.4.0",
|
"debug": "^4.4.0",
|
||||||
"dotenv": "^16.4.7",
|
"dotenv": "^16.4.7",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"express-session": "^1.18.1",
|
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
"winston": "^3.17.0"
|
"winston": "^3.17.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,34 +15,13 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
const loginContainer = document.getElementById('loginContainer');
|
const loginContainer = document.getElementById('loginContainer');
|
||||||
const appContainer = document.getElementById('appContainer');
|
const appContainer = document.getElementById('appContainer');
|
||||||
const loginMessage = document.getElementById('loginMessage');
|
const loginMessage = document.getElementById('loginMessage');
|
||||||
const logoutButton = document.getElementById('logoutButton');
|
|
||||||
const taskForm = document.getElementById('taskForm');
|
|
||||||
const sidenav = document.querySelector('.sidenav');
|
|
||||||
|
|
||||||
if (!loginForm || !loginContainer || !appContainer || !loginMessage || !logoutButton || !taskForm || !sidenav) {
|
|
||||||
console.error('One or more elements are missing in the DOM');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize Materialize components
|
|
||||||
M.Sidenav.init(sidenav);
|
|
||||||
M.Datepicker.init(document.querySelectorAll('.datepicker'), {
|
|
||||||
format: 'yyyy-mm-dd',
|
|
||||||
defaultDate: new Date(),
|
|
||||||
setDefaultDate: true,
|
|
||||||
firstDay: 1
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check if user is already logged in
|
// Check if user is already logged in
|
||||||
fetch('/check-session')
|
if (sessionStorage.getItem('loggedIn') === 'true') {
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
if (data.loggedIn) {
|
|
||||||
loginContainer.style.display = 'none';
|
loginContainer.style.display = 'none';
|
||||||
appContainer.style.display = 'block';
|
appContainer.style.display = 'block';
|
||||||
loadTags();
|
loadTags();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
loginForm.addEventListener('submit', function(e) {
|
loginForm.addEventListener('submit', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -73,23 +52,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
logoutButton.addEventListener('click', function() {
|
document.getElementById('taskForm').addEventListener('submit', function(e) {
|
||||||
fetch('/logout', {
|
|
||||||
method: 'POST'
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.ok) {
|
|
||||||
sessionStorage.removeItem('loggedIn');
|
|
||||||
loginContainer.style.display = 'block';
|
|
||||||
appContainer.style.display = 'none';
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error logging out:', error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
taskForm.addEventListener('submit', async function(e) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// Get form values
|
// Get form values
|
||||||
@@ -121,44 +84,34 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
loadTags(); // Force refresh tags after saving
|
loadTags(); // Force refresh tags after saving
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save task to server or IndexedDB if offline
|
// Send data to backend using fetch
|
||||||
if (navigator.onLine) {
|
fetch('/add-task', {
|
||||||
try {
|
|
||||||
const response = await fetch('/add-task', {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
body: JSON.stringify(taskData)
|
body: JSON.stringify(taskData)
|
||||||
});
|
})
|
||||||
const data = await response.json();
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
document.getElementById('responseMessage').textContent = data.message;
|
document.getElementById('responseMessage').textContent = data.message;
|
||||||
taskForm.reset(); // Reset the form after saving the task
|
})
|
||||||
} catch (error) {
|
.catch(error => {
|
||||||
if (error.status === 401) {
|
|
||||||
sessionStorage.removeItem('loggedIn');
|
|
||||||
loginContainer.style.display = 'block';
|
|
||||||
appContainer.style.display = 'none';
|
|
||||||
} else {
|
|
||||||
document.getElementById('responseMessage').textContent = "Error saving task!";
|
document.getElementById('responseMessage').textContent = "Error saving task!";
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
// Save task to IndexedDB
|
|
||||||
const db = await idb.openDB('org-todo-pwa', 1, {
|
|
||||||
upgrade(db) {
|
|
||||||
db.createObjectStore('tasks', { keyPath: 'id', autoIncrement: true });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
await db.add('tasks', taskData);
|
});
|
||||||
document.getElementById('responseMessage').textContent = "Task saved offline!";
|
|
||||||
taskForm.reset(); // Reset the form after saving the task
|
// Set tomorrow's date as the default for the date input
|
||||||
} catch (error) {
|
const today = new Date();
|
||||||
document.getElementById('responseMessage').textContent = "Error saving task offline!";
|
const tomorrow = new Date(today);
|
||||||
console.error('Error saving task offline:', error);
|
tomorrow.setDate(today.getDate() + 1);
|
||||||
}
|
const tomorrowString = tomorrow.toISOString().split('T')[0];
|
||||||
}
|
document.getElementById('scheduled').value = tomorrowString;
|
||||||
|
|
||||||
|
// Initialize flatpickr with Swedish locale and Monday as the first day of the week
|
||||||
|
flatpickr("#scheduled", {
|
||||||
|
weekNumbers: true, // Show week numbers
|
||||||
|
firstDayOfWeek: 1 // Start weeks on Monday
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load tags from server and initialize autocomplete
|
// Load tags from server and initialize autocomplete
|
||||||
|
|||||||
@@ -17,12 +17,12 @@
|
|||||||
<h1 class="center-align">Logga in</h1>
|
<h1 class="center-align">Logga in</h1>
|
||||||
<form id="loginForm">
|
<form id="loginForm">
|
||||||
<div class="input-field">
|
<div class="input-field">
|
||||||
<input type="text" id="username" placeholder="Användarnamn" required>
|
<label for="username">Användarnamn:</label>
|
||||||
<label for="username">Användarnamn</label>
|
<input type="text" id="username" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-field">
|
<div class="input-field">
|
||||||
<input type="password" id="password" placeholder="Lösenord" required>
|
<label for="password">Lösenord:</label>
|
||||||
<label for="password">Lösenord</label>
|
<input type="password" id="password" required>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn waves-effect waves-light" type="submit">Login</button>
|
<button class="btn waves-effect waves-light" type="submit">Login</button>
|
||||||
</form>
|
</form>
|
||||||
@@ -31,43 +31,43 @@
|
|||||||
|
|
||||||
<div id="appContainer" class="container" style="display:none;">
|
<div id="appContainer" class="container" style="display:none;">
|
||||||
<h1 class="center-align">TODO</h1>
|
<h1 class="center-align">TODO</h1>
|
||||||
<nav style="display:none;">
|
|
||||||
<div class="nav-wrapper">
|
|
||||||
<a href="#" class="brand-logo">Menu</a>
|
|
||||||
<a href="#" data-target="mobile-demo" class="sidenav-trigger"><i class="material-icons">menu</i></a>
|
|
||||||
<ul class="right hide-on-med-and-down">
|
|
||||||
<li><a id="logoutButton" class="hide-on-med-and-down">Logout</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<ul class="sidenav" id="mobile-demo">
|
|
||||||
<li><a id="logoutButton">Logout</a></li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<form id="taskForm">
|
<form id="taskForm">
|
||||||
<div class="input-field">
|
<div class="input-field">
|
||||||
<input type="text" id="subject" placeholder="Uppgift" required autocomplete="off">
|
<label for="subject">Uppgift:</label>
|
||||||
<label for="subject">Uppgift</label>
|
<input type="text" id="subject" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-field">
|
|
||||||
<textarea id="description" class="materialize-textarea" placeholder="Beskrivning"></textarea>
|
<div class="input-field">
|
||||||
<label for="description">Beskrivning</label>
|
<label for="description">Beskrivning:</label>
|
||||||
</div>
|
<textarea id="description" class="materialize-textarea"></textarea>
|
||||||
<div class="input-field">
|
</div>
|
||||||
<input type="text" id="scheduled" class="datepicker" required>
|
|
||||||
<label for="scheduled">Planerat datum</label>
|
<div class="input-field">
|
||||||
</div>
|
<label for="scheduled">Datum:</label>
|
||||||
<div class="input-field">
|
<input type="date" id="scheduled" lang="sv-SE" required>
|
||||||
<input type="text" id="tags" placeholder="Taggar">
|
</div>
|
||||||
<label for="tags">Taggar</label>
|
|
||||||
</div>
|
<div class="input-field">
|
||||||
<button class="btn waves-effect waves-light" type="submit">Save Task</button>
|
<label for="tags">Taggar (separera med komma):</label>
|
||||||
<p id="responseMessage"></p>
|
<input type="text" id="tags" class="autocomplete">
|
||||||
</form>
|
</div>
|
||||||
|
|
||||||
|
<button class="btn waves-effect waves-light" type="submit">Spara</button>
|
||||||
|
</form>
|
||||||
|
<p id="responseMessage" class="center-align"></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
|
|
||||||
<script src="app.js"></script>
|
<script src="app.js"></script>
|
||||||
|
<script>
|
||||||
|
// Set today's date as the default for the date input
|
||||||
|
const today = new Date().toISOString().split('T')[0];
|
||||||
|
document.getElementById('scheduled').value = today;
|
||||||
|
// Initialize flatpickr with Swedish locale and Monday as the first day of the week
|
||||||
|
flatpickr("#scheduled", {
|
||||||
|
weekNumbers: true, // Show week numbers
|
||||||
|
firstDayOfWeek: 1 // Start weeks on Monday
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
body {
|
body {
|
||||||
font-family: Arial, sans-serif;
|
font-family: Arial, sans-serif;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
margin: 0;
|
||||||
|
background-color: #f4f4f9;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
@@ -16,43 +22,5 @@ h1 {
|
|||||||
|
|
||||||
#responseMessage {
|
#responseMessage {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: green;}
|
color: green;
|
||||||
|
|
||||||
.menu {
|
|
||||||
position: relative;
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hamburger {
|
|
||||||
font-size: 24px;
|
|
||||||
cursor: pointer;
|
|
||||||
background: none;
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-content {
|
|
||||||
display: none;
|
|
||||||
position: absolute;
|
|
||||||
background-color: #f9f9f9;
|
|
||||||
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-content button {
|
|
||||||
color: black;
|
|
||||||
padding: 12px 16px;
|
|
||||||
text-decoration: none;
|
|
||||||
display: block;
|
|
||||||
background: none;
|
|
||||||
border: none;
|
|
||||||
width: 100%;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-content button:hover {
|
|
||||||
background-color: #f1f1f1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu.show .menu-content {
|
|
||||||
display: block;
|
|
||||||
}
|
}
|
||||||
@@ -8,29 +8,10 @@ router.post('/login', (req, res) => {
|
|||||||
const password = process.env.AUTH_PASSWORD;
|
const password = process.env.AUTH_PASSWORD;
|
||||||
|
|
||||||
if (user && user.name === username && user.pass === password) {
|
if (user && user.name === username && user.pass === password) {
|
||||||
req.session.user = user.name;
|
|
||||||
res.status(200).send('Login successful');
|
res.status(200).send('Login successful');
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send('Authentication required');
|
res.status(401).send('Authentication required');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
router.post('/logout', (req, res) => {
|
|
||||||
req.session.destroy((err) => {
|
|
||||||
if (err) {
|
|
||||||
return res.status(500).send('Error logging out');
|
|
||||||
}
|
|
||||||
res.clearCookie('connect.sid');
|
|
||||||
res.status(200).send('Logout successful');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
router.get('/check-session', (req, res) => {
|
|
||||||
if (req.session.user) {
|
|
||||||
res.json({ loggedIn: true });
|
|
||||||
} else {
|
|
||||||
res.json({ loggedIn: false });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
15
server.js
15
server.js
@@ -1,30 +1,17 @@
|
|||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
const session = require('express-session');
|
|
||||||
const cookieParser = require('cookie-parser');
|
|
||||||
const debug = require('debug')('app');
|
const debug = require('debug')('app');
|
||||||
const tasksRouter = require('./routes/tasks');
|
const tasksRouter = require('./routes/tasks');
|
||||||
const authRouter = require('./routes/auth');
|
const authRouter = require('./routes/auth');
|
||||||
const authMiddleware = require('./middleware/auth');
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = 3044;
|
const port = 3044;
|
||||||
|
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(cookieParser());
|
|
||||||
app.use(express.static('public'));
|
app.use(express.static('public'));
|
||||||
|
app.use('/', tasksRouter);
|
||||||
// Configure session middleware
|
|
||||||
app.use(session({
|
|
||||||
secret: process.env.SESSION_SECRET || 'default_secret', // Use a strong secret in production
|
|
||||||
resave: false,
|
|
||||||
saveUninitialized: false,
|
|
||||||
cookie: { secure: false, maxAge: 24 * 60 * 60 * 1000 } // 1 day
|
|
||||||
}));
|
|
||||||
|
|
||||||
app.use('/', authRouter);
|
app.use('/', authRouter);
|
||||||
app.use('/', authMiddleware, tasksRouter);
|
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
debug(`Server running at http://localhost:${port}`);
|
debug(`Server running at http://localhost:${port}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user