Reset password and users table on settings page

This commit is contained in:
Mark Cooper 2021-08-22 10:46:04 -05:00
parent 9331b5870f
commit f4cb5d101e
9 changed files with 221 additions and 58 deletions

View file

@ -28,7 +28,9 @@ class ApiController {
this.router.get('/metadata/:id/:trackIndex', this.getMetadata.bind(this))
this.router.patch('/match/:id', this.match.bind(this))
this.router.get('/users', this.getUsers.bind(this))
this.router.delete('/user/audiobook/:id', this.resetUserAudiobookProgress.bind(this))
this.router.patch('/user/password', this.userChangePassword.bind(this))
this.router.post('/authorize', this.authorize.bind(this))
@ -156,6 +158,11 @@ class ApiController {
res.sendStatus(200)
}
getUsers(req, res) {
if (req.user.type !== 'root') return res.sendStatus(403)
return res.json(this.db.users.map(u => u.toJSONForBrowser()))
}
async resetUserAudiobookProgress(req, res) {
req.user.resetAudiobookProgress(req.params.id)
await this.db.updateEntity('user', req.user)
@ -163,6 +170,10 @@ class ApiController {
res.sendStatus(200)
}
userChangePassword(req, res) {
this.auth.userChangePassword(req, res)
}
getGenres(req, res) {
res.json({
genres: this.db.getGenres()