Send email notifications when 2FA state changes

This commit is contained in:
KernelDeimos
2024-05-06 21:13:00 -04:00
parent 0e16a3f3b4
commit d20249f29a
2 changed files with 35 additions and 0 deletions

View File

@@ -83,6 +83,12 @@ module.exports = eggspress('/auth/configure-2fa/:action', {
);
// update cached user
req.user.otp_enabled = 1;
const svc_email = req.services.get('email');
await svc_email.send_email({ email: user.email }, 'enabled_2fa', {
username: user.username,
});
return {};
};
@@ -93,6 +99,12 @@ module.exports = eggspress('/auth/configure-2fa/:action', {
);
// update cached user
req.user.otp_enabled = 0;
const svc_email = req.services.get('email');
await svc_email.send_email({ email: user.email }, 'disabled_2fa', {
username: user.username,
});
return { success: true };
};

View File

@@ -97,6 +97,29 @@ If this was not you, please contact support@puter.com immediately.
<p>Puter</p>
`,
},
'enabled_2fa': {
subject: '2FA Enabled on your Account',
html: `
<p>Hi there,</p>
<p>We're sending you this email to let you know 2FA was successfully enabled
on your account</p>
<p>If you did not perform this action please contact support@puter.com
immediately</p>
<p>Sincerely,</p>
<p>Puter</p>
`
},
'disabled_2fa': {
subject: '2FA Disabled on your Account',
html: `
<p>Hi there,</p>
<p>We hope you did this on purpose! 2FA Was disabled on your account.</p>
<p>If you did not perform this action please contact support@puter.com
immediately</p>
<p>Sincerely,</p>
<p>Puter</p>
`
}
}
class Emailservice extends BaseService {