mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-13 10:55:05 +02:00
Seperate out auth strategies, update change password to return error status codes
This commit is contained in:
parent
d9cfcc86e7
commit
9c8900560c
5 changed files with 729 additions and 523 deletions
|
@ -273,12 +273,24 @@ class MeController {
|
|||
* @param {RequestWithUser} req
|
||||
* @param {Response} res
|
||||
*/
|
||||
updatePassword(req, res) {
|
||||
async updatePassword(req, res) {
|
||||
if (req.user.isGuest) {
|
||||
Logger.error(`[MeController] Guest user "${req.user.username}" attempted to change password`)
|
||||
return res.sendStatus(500)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
this.auth.userChangePassword(req, res)
|
||||
|
||||
const { password, newPassword } = req.body
|
||||
if (!password || !newPassword || typeof password !== 'string' || typeof newPassword !== 'string') {
|
||||
return res.status(400).send('Missing or invalid password or new password')
|
||||
}
|
||||
|
||||
const result = await this.auth.localAuthStrategy.changePassword(req.user, password, newPassword)
|
||||
|
||||
if (result.error) {
|
||||
return res.status(400).send(result.error)
|
||||
}
|
||||
|
||||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue