implemented settings and user page (darkmode is still missing)

This commit is contained in:
2024-03-24 21:02:56 +01:00
parent acb7bb7cb6
commit 45a4b58f26
36 changed files with 2283 additions and 1313 deletions

View File

@ -71,6 +71,32 @@ export const signUp = async (req, res, next) => {
}
};
// Update user password to Database
export const updatePasswordById = async (req, res, next) => {
try {
const id = req.body.id;
let sql = `UPDATE users SET password = ? WHERE id = ?`;
bcrypt.hash(req.body.password, 10, async (err, hash) => {
if (err) {
throw err;
return res.status(500).send({
message: err,
});
} else {
const results = await ownConn.query(sql, [hash, id]);
return res.status(200).send({
message: 'Password changed!',
});
}
});
}
catch (err) {
// Manage Errors
console.log("SQL error : ", err);
result(err, null);
}
};
export const login = async (req, res, next) => {
try {
let sql = `SELECT * FROM users WHERE username = ?`;

View File

@ -38,10 +38,7 @@ export const validateRegister = (req, res, next) => {
});
}
// password (repeat) must match
if (
!req.body.password_repeat ||
req.body.password != req.body.password_repeat
) {
if (req.body.password != req.body.password_repeat) {
return res.status(400).send({
message: 'Both passwords must match',
});

View File

@ -46,8 +46,9 @@ export const getSelectedUsersByUser = async (selected, result) => {
export const updateUserById = async (data, result) => {
try {
const id = data.id;
let sql = `UPDATE users SET username = ?, password = ?, fullName = ?, email = ?, phonenumber = ?, address = ?, city = ?, postcode = ?, adminBool = ?, technicianBool = ?, readerBool = ? WHERE id = ?`;
const results = await ownConn.query(sql, [data.username, data.password, data.fullName, data.email, data.phonenumber, data.address, data.city, data.postcode, data.adminBool, data.technicianBool,, data.readerBool, id]);
let sql = `UPDATE users SET username = ?, fullName = ?, email = ?, phonenumber = ?, address = ?, city = ?, postcode = ?, adminBool = ?, technicianBool = ?, readerBool = ? WHERE id = ?`;
const results = await ownConn.query(sql, [data.username, data.fullName, data.email, data.phonenumber, data.address, data.city, data.postcode, data.adminBool, data.technicianBool, data.readerBool, id]);
results.insertId = results.insertId.toString();
result(null, results);
}
catch (err) {
@ -57,12 +58,12 @@ export const updateUserById = async (data, result) => {
}
};
// Delete user to Database
export const deleteUserById = async (id, result) => {
try {
let sql = `DELETE FROM users WHERE id = ?`;
const results = await ownConn.query(sql, [id])
results.insertId = results.insertId.toString();
result(null, results);
}
catch (err) {

View File

@ -108,6 +108,7 @@ import {
import {
signUp,
updatePasswordById,
login,
showUsers,
showUserById,
@ -603,6 +604,9 @@ router.delete("/issueVariantsByIssueSlipId/:id", deleteIssueVariantByIssueSlipId
// sign-up process
router.post('/signUp', userMiddleware.validateRegister, signUp);
// update password process
router.put('/updatePassword', updatePasswordById);
// login process
router.post('/login', login);