diff --git a/server/routes/users.js b/server/routes/users.js
index 9efd0eb..78c5fbb 100644
--- a/server/routes/users.js
+++ b/server/routes/users.js
@@ -232,6 +232,33 @@ router.patch('/users/dark-mode', (req, res) => {
})
})
+router.patch('/users/password', (req, res) => {
+ if (!req.user) {
+ return res.sendStatus(401)
+ }
+
+ const salt = crypto.randomBytes(16)
+ crypto.pbkdf2(req.body.password, salt, 10000, 32, 'sha256', (err, hashedPassword) => {
+ if (err) {
+ logger.error(err)
+ return res.sendStatus(500)
+ }
+
+ db.run('UPDATE users SET hashed_password = ?, salt = ? WHERE id = ?', [
+ hashedPassword,
+ salt,
+ req.user.id
+ ], (err) => {
+ if (err) {
+ logger.error(err)
+ return res.sendStatus(500)
+ }
+
+ return res.sendStatus(200)
+ })
+ })
+})
+
router.delete('/users/:userId', (req, res) => {
if (!req.user) {
return res.sendStatus(401)
diff --git a/src/components/Account.vue b/src/components/Account.vue
new file mode 100644
index 0000000..25841d1
--- /dev/null
+++ b/src/components/Account.vue
@@ -0,0 +1,99 @@
+
+
+
+
+
+ Account
+
+
+
+
+
+
+ ID: {{ currentUser.id }}
+
+
+ Username: {{ currentUser.username }}
+
+
+ Name: {{ currentUser.name }}
+
+
+
+
+
+
+ Change Password
+
+
+
+
+
+ Change Password
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Close
+
+
+ Change Password
+
+
+
+
+
+
+
+ {{ snackbarText }}
+
+
+
+ Close
+
+
+
+
+
+
+
diff --git a/src/components/Admin.vue b/src/components/Admin.vue
index b87f8c1..8a01e1b 100644
--- a/src/components/Admin.vue
+++ b/src/components/Admin.vue
@@ -16,7 +16,7 @@
Register User
@@ -137,7 +137,7 @@
v-model="snackbar"
timeout="3000"
>
- {{ updateText }}
+ {{ snackbarText }}
+
+
+ mdi-account
+
+
+ Account
+
+
Save Profile As...
@@ -481,7 +481,7 @@
v-bind="attrs"
class="mx-3 my-3 mb-5"
v-on="on"
- @click="$refs.uploadSampleForm.reset()"
+ @click="resetUploadSampleForm"
>
Upload Sample
diff --git a/src/components/account.js b/src/components/account.js
new file mode 100644
index 0000000..dc76cb3
--- /dev/null
+++ b/src/components/account.js
@@ -0,0 +1,45 @@
+export default {
+ name: 'Admin',
+
+ data: () => ({
+ currentUser: {},
+ changePasswordDialog: false,
+ isPasswordValid: false,
+ password: '',
+ snackbar: false,
+ snackbarText: '',
+ rules: {
+ required: v => !!v || 'Required'
+ }
+ }),
+ created () {
+ this.getCurrentUser()
+ },
+ methods: {
+ getCurrentUser () {
+ this.$http.get('/users/current')
+ .then(response => {
+ if (response.status === 200) {
+ this.currentUser = response.data.user
+ }
+ })
+ },
+ updatePassword () {
+ this.$http.patch('/users/password', {
+ password: this.password
+ })
+ .then(response => {
+ if (response.status === 200) {
+ this.changePasswordDialog = false
+ this.snackbarText = 'Password Changed'
+ this.snackbar = true
+ }
+ })
+ },
+ resetChangePasswordForm () {
+ if (this.$refs.changePasswordForm) {
+ this.$refs.changePasswordForm.reset()
+ }
+ }
+ }
+}
diff --git a/src/components/admin.js b/src/components/admin.js
index 03b83fb..1d98fee 100644
--- a/src/components/admin.js
+++ b/src/components/admin.js
@@ -5,7 +5,7 @@ export default {
currentUser: {},
users: [],
snackbar: false,
- updateText: '',
+ snackbarText: '',
registerUserDialog: false,
isUserValid: false,
name: '',
@@ -44,11 +44,11 @@ export default {
})
.then(response => {
if (response.status === 200) {
- this.updateText = 'User updated'
+ this.snackbarText = 'User updated'
}
})
.catch(() => {
- this.updateText = 'Error updating user'
+ this.snackbarText = 'Error updating user'
})
},
updateUserUpload (id, canUpload) {
@@ -57,11 +57,11 @@ export default {
})
.then(response => {
if (response.status === 200) {
- this.updateText = 'User updated'
+ this.snackbarText = 'User updated'
}
})
.catch(() => {
- this.updateText = 'Error updating user'
+ this.snackbarText = 'Error updating user'
})
},
deleteUser (id) {
@@ -84,11 +84,16 @@ export default {
.then(response => {
if (response.status === 200) {
this.registerUserDialog = false
- this.updateText = 'User Registered'
+ this.snackbarText = 'User Registered'
this.snackbar = true
this.getUsers()
}
})
+ },
+ resetRegisterUserForm () {
+ if (this.$refs.registerUserForm) {
+ this.$refs.registerUserForm.reset()
+ }
}
}
}
diff --git a/src/components/appbar.js b/src/components/appbar.js
index b1cc659..24788a1 100644
--- a/src/components/appbar.js
+++ b/src/components/appbar.js
@@ -10,6 +10,9 @@ export default {
home () {
this.$router.push('/')
},
+ account () {
+ this.$router.push('/account')
+ },
admin () {
this.$router.push('/admin')
},
diff --git a/src/components/noise.js b/src/components/noise.js
index 9874e46..c872281 100644
--- a/src/components/noise.js
+++ b/src/components/noise.js
@@ -393,6 +393,16 @@ export default {
this.$vuetify.theme.dark = response.data.user.darkMode
}
})
+ },
+ resetProfileForm () {
+ if (this.$refs.profileForm) {
+ this.$refs.profileForm.reset()
+ }
+ },
+ resetUploadSampleForm () {
+ if (this.$refs.uploadSampleForm) {
+ this.$refs.uploadSampleForm.reset()
+ }
}
}
}
diff --git a/src/router/index.js b/src/router/index.js
index 6bc9df1..9a95935 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -14,23 +14,22 @@ const routes = [
{
path: '/login',
name: 'Login',
- // route level code-splitting
- // this generates a separate chunk (about.[hash].js) for this route
- // which is lazy-loaded when the route is visited.
- component: () => import(/* webpackChunkName: "about" */ '../views/LoginView.vue')
+ component: () => import('../views/LoginView.vue')
},
{
path: '/register',
name: 'Register',
- // route level code-splitting
- // this generates a separate chunk (about.[hash].js) for this route
- // which is lazy-loaded when the route is visited.
- component: () => import(/* webpackChunkName: "about" */ '../views/RegisterView.vue')
+ component: () => import('../views/RegisterView.vue')
},
{
path: '/admin',
name: 'Admin',
- component: () => import(/* webpackChunkName: "about" */ '../views/AdminView.vue')
+ component: () => import('../views/AdminView.vue')
+ },
+ {
+ path: '/account',
+ name: 'Account',
+ component: () => import('../views/AccountView.vue')
}
]
@@ -50,8 +49,7 @@ router.beforeEach((to, from, next) => {
next('/register')
}
})
- .catch((error) => {
- console.error(error.response)
+ .catch(() => {
next('/register')
})
} else if (to.name === 'Admin') {
@@ -63,8 +61,7 @@ router.beforeEach((to, from, next) => {
next('/')
}
})
- .catch((error) => {
- console.error(error.response)
+ .catch(() => {
next('/')
})
} else if (to.name === 'Register') {
@@ -76,10 +73,21 @@ router.beforeEach((to, from, next) => {
next()
}
})
- .catch((error) => {
- console.error(error.response)
+ .catch(() => {
next('/login')
})
+ } else if (to.name === 'Account') {
+ instance.get('/auth')
+ .then(response => {
+ if (response.status === 200) {
+ next()
+ } else {
+ next('/register')
+ }
+ })
+ .catch(() => {
+ next('/register')
+ })
} else {
next()
}
diff --git a/src/views/AccountView.vue b/src/views/AccountView.vue
new file mode 100644
index 0000000..ba2c495
--- /dev/null
+++ b/src/views/AccountView.vue
@@ -0,0 +1,15 @@
+
+
+
+
+