|
@ -186,6 +186,13 @@ class UserService { |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
}, |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (userDefinition.password) { |
|
|
|
|
|
if (userDefinition.password !== userDefinition.passwordVerify) { |
|
|
|
|
|
throw new SiteError(400, 'The new password and password verification do not match.'); |
|
|
|
|
|
} |
|
|
|
|
|
await this.updatePassword(user, userDefinition.password); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async authenticate (account, options) { |
|
|
async authenticate (account, options) { |
|
@ -309,6 +316,15 @@ class UserService { |
|
|
return user; |
|
|
return user; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async getByUsername (username) { |
|
|
|
|
|
const user = await User |
|
|
|
|
|
.findOne({ username_lc: username.trim().toLowerCase() }) |
|
|
|
|
|
.select('+email +flags +permissions') |
|
|
|
|
|
.populate(this.populateUser) |
|
|
|
|
|
.lean(); |
|
|
|
|
|
return user; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
async getUserAccounts (pagination, username) { |
|
|
async getUserAccounts (pagination, username) { |
|
|
let search = { }; |
|
|
let search = { }; |
|
|
if (username) { |
|
|
if (username) { |
|
@ -562,6 +578,25 @@ class UserService { |
|
|
await User.updateOne({ _id: user._id }, { $unset: { 'header': '' } }); |
|
|
await User.updateOne({ _id: user._id }, { $unset: { 'header': '' } }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async updatePassword (user, password) { |
|
|
|
|
|
const { crypto: cryptoService } = this.dtp.services; |
|
|
|
|
|
|
|
|
|
|
|
const passwordSalt = uuidv4(); |
|
|
|
|
|
const passwordHash = cryptoService.maskPassword(passwordSalt, password); |
|
|
|
|
|
|
|
|
|
|
|
this.log.info('updating user password', { userId: user._id }); |
|
|
|
|
|
|
|
|
|
|
|
await User.updateOne( |
|
|
|
|
|
{ _id: user._id }, |
|
|
|
|
|
{ |
|
|
|
|
|
$set: { |
|
|
|
|
|
passwordSalt: passwordSalt, |
|
|
|
|
|
password: passwordHash, |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
async remove (user) { |
|
|
async remove (user) { |
|
|
const { |
|
|
const { |
|
|
link: linkService, |
|
|
link: linkService, |
|
|