reworked password change
This commit is contained in:
parent
a1a7c5e4bb
commit
cdd705831b
@ -73,14 +73,15 @@ set.params = {
|
|||||||
permission: { type: 'string', optional: true }
|
permission: { type: 'string', optional: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function changePassword ({id, oldPassword, newPassword}) {
|
export async function changePassword ({oldPassword, newPassword}) {
|
||||||
await this.changePassword(id, oldPassword, newPassword)
|
await this.changePassword(oldPassword, newPassword)
|
||||||
}
|
}
|
||||||
|
|
||||||
changePassword.description = 'change password after checking old password (user function)'
|
changePassword.description = 'change password after checking old password (user function)'
|
||||||
|
|
||||||
|
changePassword.permission = ''
|
||||||
|
|
||||||
changePassword.params = {
|
changePassword.params = {
|
||||||
id: {type: 'string'},
|
|
||||||
oldPassword: {type: 'string'},
|
oldPassword: {type: 'string'},
|
||||||
newPassword: {type: 'string'}
|
newPassword: {type: 'string'}
|
||||||
}
|
}
|
||||||
|
@ -335,7 +335,7 @@ const apiHelpers = {
|
|||||||
// Handles both properties and wrapped models.
|
// Handles both properties and wrapped models.
|
||||||
const properties = user.properties || user
|
const properties = user.properties || user
|
||||||
|
|
||||||
return pick(properties, 'id', 'email', 'groups', 'permission')
|
return pick(properties, 'id', 'email', 'groups', 'permission', 'provider')
|
||||||
},
|
},
|
||||||
|
|
||||||
getServerPublicProperties (server) {
|
getServerPublicProperties (server) {
|
||||||
|
@ -334,15 +334,20 @@ export default class Xo extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async changePassword (id, oldPassword, newPassword) {
|
async changePassword (oldPassword, newPassword) {
|
||||||
|
const id = this.session.get('user_id')
|
||||||
const user = await this._getUser(id)
|
const user = await this._getUser(id)
|
||||||
|
|
||||||
|
if (user.provider) {
|
||||||
|
throw new Error('Password change is only for locally created users')
|
||||||
|
}
|
||||||
|
|
||||||
const auth = await user.checkPassword(oldPassword)
|
const auth = await user.checkPassword(oldPassword)
|
||||||
if (!auth) {
|
if (!auth) {
|
||||||
throw new InvalidCredential()
|
throw new InvalidCredential()
|
||||||
}
|
}
|
||||||
await user.setPassword(newPassword)
|
await user.setPassword(newPassword)
|
||||||
return await this._users.save(user.properties)
|
await this._users.save(user.properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------
|
// -----------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user