HM-109. Добавлена ручка для смены пароля
This commit is contained in:
@ -198,7 +198,7 @@ export class UserService {
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const token = jwt.decode(access_token) as Token;
|
||||
const searchUser = await this.findUser(token.login);
|
||||
return searchUser && this.checkToken(token, agent);
|
||||
@ -216,4 +216,19 @@ export class UserService {
|
||||
login,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async changePassword(access_token: string, old_password: string, new_password: string): Promise<string> {
|
||||
const {login} = jwt.decode(access_token) as Token;
|
||||
const user = await this.userModel().findOne({login});
|
||||
if (user && await this.checkPassword(old_password, user.password)) {
|
||||
const salt = user.salt;
|
||||
const password = await bcrypt.hash(new_password, salt);
|
||||
await user.updateOne({
|
||||
password,
|
||||
});
|
||||
|
||||
return 'ok';
|
||||
}
|
||||
throw new BadRequestException('Unauthorized request');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user