@@ -29,17 +30,15 @@ const showPassword = ref(false);
+ :type="showPassword ? 'text' : 'password'"
+ autocomplete="current-password" required style="border-right:0;"/>
diff --git a/server/app.js b/server/app.js
index 5e8601d..726b8e8 100644
--- a/server/app.js
+++ b/server/app.js
@@ -1,32 +1,20 @@
// server/app.js
+console.log("Starting Server...");
import express from 'express';
import cors from 'cors';
// import multer from 'multer';
// import path from 'path';
import db from './models/db.js';
import dotenv from 'dotenv';
-import emailController from "./controllers/emailController.js";
dotenv.config();
-/**@typedef {import("../client/src/DBRecord.ts").DBRecord} DBRecord */
-
-console.log("Starting Server...");
// test db connection
try {
await db.query("SELECT 1")
console.log("DB connection successful")
await db.get('users', {id: 1});
console.log("Users table exists");
-
- await emailController.withTimeout(emailController.transporter.verify(), 15000)
- .then(() => {
- console.log("Transporter is ready to send emails");
- })
- .catch((error) => {
- console.error("Error verifying transporter:", error);
- process.exit(1);
- });
} catch (err) {
console.error(err);
process.exit(1);
@@ -52,11 +40,11 @@ const upload = multer({storage});*/
// user routes
import userRouter from './controllers/userController.js';
-
app.use('/api/users', userRouter);
// email routes
-app.use('/api/email', emailController.router);
+import emailRouter from "./controllers/emailController.js";
+app.use('/api/email', emailRouter);
// other routes
diff --git a/server/controllers/emailController.js b/server/controllers/emailController.js
index 8a07109..9fe10f7 100644
--- a/server/controllers/emailController.js
+++ b/server/controllers/emailController.js
@@ -144,9 +144,5 @@ async function withTimeout(promise, ms) {
}
-export default {
- withTimeout,
- transporter,
- router
-};
+export default router;
diff --git a/server/controllers/userController.js b/server/controllers/userController.js
index 27e9a55..f6a3e1f 100644
--- a/server/controllers/userController.js
+++ b/server/controllers/userController.js
@@ -41,12 +41,12 @@ router.get("/",
*/
async (req, res, next) => {
if (!req.body || !req.body.username || !req.body.password) {
- return res.status(400).json({data: null, error: 'Username and password are required'});
+ return res.status(400).json({data: null, message: 'Username and password are required'});
}
await users.addNewUser(req.body.username, req.body.password)
.then((user) => {
if (!user) {
- return res.status(500).json({data: null, error: 'User not found after insertion'});
+ return res.status(500).json({data: null, message: 'User not found after insertion'});
}
res.status(200).json({data: user, message: 'User added successfully'});
})
@@ -64,21 +64,21 @@ router.get("/:identifier",
*/
async (req, res, next) => {
const userIdentifier = req.params.identifier;
- if (!userIdentifier) return res.status(400).json({data: null, error: 'User identifier is required'});
+ if (!userIdentifier) return res.status(400).json({data: null, message: 'User identifier is required'});
await users.getUser(userIdentifier)
.then(user => {
- if (!user) return res.status(404).json({data: null, error: 'User not found'});
+ if (!user) return res.status(404).json({data: null, message: 'User not found'});
res.status(200).json({data: user});
})
.catch((err) => {
if (err instanceof Error) {
if (err.message === 'User not found') {
- return res.status(404).json({data: null, error: 'User not found'});
+ return res.status(404).json({data: null, error: err});
}
if (err.message === 'Multiple users found with the same identifier, something has gone wrong') {
res.status(500).json({
data: null,
- error: 'Multiple users found with the same identifier, something has gone wrong'
+ error: err
});
} else next(err);
} else {
@@ -100,16 +100,16 @@ router.post("/login",
const {username, password} = req.body;
if (!username || !password) return res.status(400).json({
data: null,
- error: 'Username and password are required'
+ message: 'Username and password are required'
});
await users.login(username, password).then(data => {
- if (!data) return res.status(401).json({data: null, error: 'Invalid username or password'});
+ if (!data) return res.status(401).json({data: null, message: 'Invalid username or password'});
res.status(200).json({data: data, message: 'Login successful'});
})
.catch((err) => {
if (err instanceof Error) {
if (err.message === 'Invalid username or password') {
- res.status(401).json({data: null, error: 'Invalid username or password'});
+ res.status(401).json({data: null, error: err});
} else next(err);
} else {
next(new Error('An unhandled error occurred while login'));
@@ -127,12 +127,10 @@ router.patch("/:identifier", authHandler.authenticateUser,
*/
async (req, res, next) => {
const userIdentifier = req.params.id;
- if (!userIdentifier) {
- return res.status(400).json({data: null, error: 'User Identifier is required'});
- }
+ if (!userIdentifier) return res.status(400).json({data: null, message: 'User Identifier is required'});
await users.updateUser(req.body)
.then(user => {
- if (!user) res.status(404).json({data: null, error: 'User not found'});
+ if (!user) res.status(404).json({data: null, message: 'User not found'});
else res.status(200).json({data: user, message: 'User updated successfully'});
})
.catch((err) => next(err))
@@ -150,10 +148,10 @@ router.delete("/:identifier", authHandler.authenticateUser,
*/
async (req, res, next) => {
const userIdentifier = req.params.identifier;
- if (!userIdentifier) return res.status(400).json({data: null, error: 'User identifier is required'});
+ if (!userIdentifier) return res.status(400).json({data: null, message: 'User identifier is required'});
await users.deleteUser(userIdentifier)
.then(user => {
- if (!user) return res.status(404).json({data: null, error: 'User not found'});
+ if (!user) return res.status(404).json({data: null, message: 'User not found'});
res.status(200).json({data: user, message: 'User deleted successfully'});
})
.catch((err) => next(err));