From 45a4b58f265e0aa2bee0cd714084dc9ca5c04d0a Mon Sep 17 00:00:00 2001 From: "selina.mail" Date: Sun, 24 Mar 2024 21:02:56 +0100 Subject: [PATCH] implemented settings and user page (darkmode is still missing) --- backend/controller/users.js | 26 + backend/middleware/users.js | 5 +- backend/models/usersModel.js | 7 +- backend/routes/routes.js | 4 + components/LoginForm.vue | 250 +++-- components/server/Employee.vue | 476 ++++++++++ components/server/EmployeeGroups.vue | 485 ++++++++++ components/server/EmployeeTable.vue | 10 +- components/server/TemplateChecklistMVT.vue | 4 +- components/server/UserAccount.vue | 310 +++++- components/server/UserProfile.vue | 251 ++++- components/server/UserRightsList.vue | 4 +- documentation/.$Datenbankmodell.drawio.dtmp | 995 -------------------- documentation/Datenbankmodell.drawio | 2 +- layouts/Actionbar.vue | 23 +- layouts/PageHeader.vue | 101 +- layouts/empty.vue | 1 - nuxt.config.ts | 2 +- package-lock.json | 19 + package.json | 1 + pages/employees.vue | 6 +- pages/home.vue | 12 +- pages/login.vue | 5 +- pages/maintenanceVisits.vue | 13 +- pages/productionOrders.vue | 29 +- pages/settings.vue | 89 +- plugins/vuex.js | 131 ++- server/api/auth/login.ts | 16 +- server/api/auth/logout.ts | 3 + server/api/deleteEmployee/[id].ts | 23 + server/api/getEmployee/[id].ts | 23 + server/api/login.ts | 16 + server/api/updateEmployee.ts | 14 + server/api/updatePasswordEmployee.ts | 14 + server/middleware/employees.ts | 224 ++--- server/middleware/signUp.ts | 2 +- 36 files changed, 2283 insertions(+), 1313 deletions(-) create mode 100644 components/server/Employee.vue create mode 100644 components/server/EmployeeGroups.vue delete mode 100644 documentation/.$Datenbankmodell.drawio.dtmp create mode 100644 server/api/auth/logout.ts create mode 100644 server/api/deleteEmployee/[id].ts create mode 100644 server/api/getEmployee/[id].ts create mode 100644 server/api/login.ts create mode 100644 server/api/updateEmployee.ts create mode 100644 server/api/updatePasswordEmployee.ts diff --git a/backend/controller/users.js b/backend/controller/users.js index d903489..3614c65 100644 --- a/backend/controller/users.js +++ b/backend/controller/users.js @@ -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 = ?`; diff --git a/backend/middleware/users.js b/backend/middleware/users.js index 608006c..fe128c6 100644 --- a/backend/middleware/users.js +++ b/backend/middleware/users.js @@ -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', }); diff --git a/backend/models/usersModel.js b/backend/models/usersModel.js index 03f8bf5..41fd66b 100644 --- a/backend/models/usersModel.js +++ b/backend/models/usersModel.js @@ -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) { diff --git a/backend/routes/routes.js b/backend/routes/routes.js index 390f470..05fbf96 100644 --- a/backend/routes/routes.js +++ b/backend/routes/routes.js @@ -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); diff --git a/components/LoginForm.vue b/components/LoginForm.vue index a3c7fe2..f54858e 100644 --- a/components/LoginForm.vue +++ b/components/LoginForm.vue @@ -26,8 +26,11 @@
Password:
- - + + +
@@ -37,24 +40,42 @@
- - + +
- + + \ No newline at end of file diff --git a/components/server/Employee.vue b/components/server/Employee.vue new file mode 100644 index 0000000..7b38a4a --- /dev/null +++ b/components/server/Employee.vue @@ -0,0 +1,476 @@ + + + + + + + + diff --git a/components/server/EmployeeGroups.vue b/components/server/EmployeeGroups.vue new file mode 100644 index 0000000..6e59e50 --- /dev/null +++ b/components/server/EmployeeGroups.vue @@ -0,0 +1,485 @@ + + + + + + + + + \ No newline at end of file diff --git a/components/server/EmployeeTable.vue b/components/server/EmployeeTable.vue index dc96de2..16f5ce3 100644 --- a/components/server/EmployeeTable.vue +++ b/components/server/EmployeeTable.vue @@ -15,17 +15,17 @@ :class="['table-row', darkMode ? 'tr-darkmode' : 'tr-lightmode']"> - + @click="goToChosenEmployee(u.id)"> {{ u.fullName }} - + @click="goToChosenEmployee(u.id)"> {{ u.username }} @@ -45,7 +45,7 @@ import { computed } from 'vue'; // get accesss to the store const store = useStore() -const goToChosenAsset = (id) => { +const goToChosenEmployee = (id) => { store.commit('setChosenEmployee', id); store.commit('changeToEmployee'); }; diff --git a/components/server/TemplateChecklistMVT.vue b/components/server/TemplateChecklistMVT.vue index 69b2b33..51cce4b 100644 --- a/components/server/TemplateChecklistMVT.vue +++ b/components/server/TemplateChecklistMVT.vue @@ -45,7 +45,7 @@ {{ todo.commets }} @@ -149,6 +149,8 @@ import Axios from '../axios.config.js'; import clientsideConfig from '../../clientsideConfig.js'; import { useStore } from 'vuex'; import { computed } from 'vue'; +// import VueInputAutowidth from 'vue-input-autowidth'; +// Vue.use(VueInputAutowidth); const store = useStore(); const addBool = computed(() => store.state.new); diff --git a/components/server/UserAccount.vue b/components/server/UserAccount.vue index 05a4caf..37d1888 100644 --- a/components/server/UserAccount.vue +++ b/components/server/UserAccount.vue @@ -2,32 +2,243 @@

Account:

-
-
E-Mail:
-
...
+
+
+
Username:
+
{{ loggedInUserUsername }}
+ +
+
+
Email:
+
{{ loggedInUserEmail }}
+ +
+
-
-
Password:
-
*******
+
+
+
New Password:
+ +
+
+
Repeat:
+ +
+
- - + + - + - - + + + \ No newline at end of file diff --git a/components/server/UserProfile.vue b/components/server/UserProfile.vue index 00a031a..4ac9d6a 100644 --- a/components/server/UserProfile.vue +++ b/components/server/UserProfile.vue @@ -5,28 +5,221 @@
-
-
Username:
-
...
+
+
+
Full name:
+
{{ loggedInUserFullName }}
+ +
+
+
Registered:
+
 {{ loggedInUserRegistered }}
+
+
+
Last login:
+
 {{ loggedInUserLastLogin }}
+
+
+
+
+
+
City:
+
{{ loggedInUserCity }}
+ +
+
+
Phonenumber:
+
{{ loggedInUserPhonenumber }}
+ +
+
+
+
+
Postcode:
+
{{ loggedInUserPostcode }}
+ +
+
+
Address:
+
{{ loggedInUserAddress }}
+ +
+
- - + + - + - - + + + \ No newline at end of file + --> \ No newline at end of file diff --git a/documentation/.$Datenbankmodell.drawio.dtmp b/documentation/.$Datenbankmodell.drawio.dtmp deleted file mode 100644 index 78d9294..0000000 --- a/documentation/.$Datenbankmodell.drawio.dtmp +++ /dev/null @@ -1,995 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/documentation/Datenbankmodell.drawio b/documentation/Datenbankmodell.drawio index f60d6d9..4ecfed3 100644 --- a/documentation/Datenbankmodell.drawio +++ b/documentation/Datenbankmodell.drawio @@ -1,4 +1,4 @@ - + diff --git a/layouts/Actionbar.vue b/layouts/Actionbar.vue index 9258f6d..a6bb37c 100644 --- a/layouts/Actionbar.vue +++ b/layouts/Actionbar.vue @@ -91,9 +91,9 @@
Instance
- -