Skip to content

Commit

Permalink
send email on password change
Browse files Browse the repository at this point in the history
  • Loading branch information
giall committed Jan 11, 2020
1 parent 54ed451 commit f3bf578
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/services/mail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ export class MailService {
});
}

async passwordChange(user: User): Promise<void> {
const subject = 'Password change';
const text = `Hi ${user.username},\n\nYour password has been changed successfully.\n\n
If this wasn't you, please reset your password or contact support at ${properties.app.email}.\n\nThank you,\nThe ${this.app} Team`;
const html = `Hi ${user.username},<br/><br/>
Your password has been changed successfully.<br/><br/>
If this wasn't you, please reset your password or <a href="mailto:${properties.app.email}">contact support</a>.<br/><br/>
Thank you,<br/>The ${this.app} Team`;
return this.transporter.send({
from: this.from, to: to(user), subject, text, html
});
}

async magicLogin(user: User): Promise<void> {
const token = magicLogin(user);
const magicLoginUrl = `${properties.web.host}/${properties.web.endpoints.magicLogin}?token=${token}`;
Expand Down
1 change: 1 addition & 0 deletions src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class UserService {
const user = await this.userRepository.findById(userId);
this.verifyPassword(user, oldPassword);
await this.userRepository.update(userId, {hash: hashPassword(newPassword)});
await this.mailService.passwordChange(user);
this.log.info(`Changed password for userId=${userId}`);
}

Expand Down

0 comments on commit f3bf578

Please sign in to comment.