mirror of
https://github.com/bitwarden/server.git
synced 2024-12-28 17:57:37 +01:00
two factor emails
This commit is contained in:
parent
f4fa990cb1
commit
d57a68aae3
@ -14,6 +14,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="MailTemplates\TwoFactorEmail.cshtml" />
|
||||
<EmbeddedResource Include="MailTemplates\TwoFactorEmail.text.cshtml" />
|
||||
<EmbeddedResource Include="MailTemplates\ChangeEmailAlreadyExists.cshtml" />
|
||||
<EmbeddedResource Include="MailTemplates\ChangeEmailAlreadyExists.text.cshtml" />
|
||||
<EmbeddedResource Include="MailTemplates\OrganizationUserInvited.cshtml" />
|
||||
|
@ -1,4 +1,4 @@
|
||||
@model Bit.Core.Models.Mail.ChangeEmailViewModel
|
||||
@model Bit.Core.Models.Mail.EmailTokenViewModel
|
||||
@{
|
||||
Layout = "_BasicMailLayout";
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
@model Bit.Core.Models.Mail.ChangeEmailViewModel
|
||||
@model Bit.Core.Models.Mail.EmailTokenViewModel
|
||||
@{
|
||||
Layout = "_BasicMailLayout.text";
|
||||
}
|
||||
|
10
src/Core/MailTemplates/TwoFactorEmail.cshtml
Normal file
10
src/Core/MailTemplates/TwoFactorEmail.cshtml
Normal file
@ -0,0 +1,10 @@
|
||||
@model Bit.Core.Models.Mail.EmailTokenViewModel
|
||||
@{
|
||||
Layout = "_BasicMailLayout";
|
||||
}
|
||||
<p>
|
||||
Your two-step verification code is: @Model.Token
|
||||
</p>
|
||||
<p>
|
||||
Use this code to complete logging in with bitwarden.
|
||||
</p>
|
7
src/Core/MailTemplates/TwoFactorEmail.text.cshtml
Normal file
7
src/Core/MailTemplates/TwoFactorEmail.text.cshtml
Normal file
@ -0,0 +1,7 @@
|
||||
@model Bit.Core.Models.Mail.EmailTokenViewModel
|
||||
@{
|
||||
Layout = "_BasicMailLayout.text";
|
||||
}
|
||||
Your two-step verification code is: @Model.Token
|
||||
|
||||
Use this code to complete logging in with bitwarden.
|
@ -1,6 +1,6 @@
|
||||
namespace Bit.Core.Models.Mail
|
||||
{
|
||||
public class ChangeEmailViewModel : BaseMailModel
|
||||
public class EmailTokenViewModel : BaseMailModel
|
||||
{
|
||||
public string Token { get; set; }
|
||||
}
|
@ -9,6 +9,7 @@ namespace Bit.Core.Services
|
||||
Task SendWelcomeEmailAsync(User user);
|
||||
Task SendChangeEmailAlreadyExistsEmailAsync(string fromEmail, string toEmail);
|
||||
Task SendChangeEmailEmailAsync(string newEmailAddress, string token);
|
||||
Task SendTwoFactorEmailAsync(string email, string token);
|
||||
Task SendNoMasterPasswordHintEmailAsync(string email);
|
||||
Task SendMasterPasswordHintEmailAsync(string email, string hint);
|
||||
Task SendOrganizationInviteEmailAsync(string organizationName, OrganizationUser orgUser, string token);
|
||||
|
@ -48,7 +48,7 @@ namespace Bit.Core.Services
|
||||
public async Task SendChangeEmailEmailAsync(string newEmailAddress, string token)
|
||||
{
|
||||
var message = CreateDefaultMessage("Your Email Change", newEmailAddress);
|
||||
var model = new ChangeEmailViewModel
|
||||
var model = new EmailTokenViewModel
|
||||
{
|
||||
Token = token,
|
||||
WebVaultUrl = _globalSettings.BaseVaultUri,
|
||||
@ -61,6 +61,22 @@ namespace Bit.Core.Services
|
||||
await _mailDeliveryService.SendEmailAsync(message);
|
||||
}
|
||||
|
||||
public async Task SendTwoFactorEmailAsync(string email, string token)
|
||||
{
|
||||
var message = CreateDefaultMessage("Your Two-step Login Verification Code", email);
|
||||
var model = new EmailTokenViewModel
|
||||
{
|
||||
Token = token,
|
||||
WebVaultUrl = _globalSettings.BaseVaultUri,
|
||||
SiteName = _globalSettings.SiteName
|
||||
};
|
||||
message.HtmlContent = _engine.Parse("TwoFactorEmail", model);
|
||||
message.TextContent = _engine.Parse("TwoFactorEmail.text", model);
|
||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
||||
|
||||
await _mailDeliveryService.SendEmailAsync(message);
|
||||
}
|
||||
|
||||
public async Task SendMasterPasswordHintEmailAsync(string email, string hint)
|
||||
{
|
||||
var message = CreateDefaultMessage("Your Master Password Hint", email);
|
||||
|
@ -12,6 +12,7 @@ namespace Bit.Core.Services
|
||||
private const string WelcomeTemplateId = "045f8ad5-5547-4fa2-8d3d-6d46e401164d";
|
||||
private const string ChangeEmailAlreadyExistsTemplateId = "b69d2038-6ad9-4cf6-8f7f-7880921cba43";
|
||||
private const string ChangeEmailTemplateId = "ec2c1471-8292-4f17-b6b6-8223d514f86e";
|
||||
private const string TwoFactorEmailTemplateId = "264cfe69-5258-4c89-8d90-76b4659de589";
|
||||
private const string NoMasterPasswordHintTemplateId = "136eb299-e102-495a-88bd-f96736eea159";
|
||||
private const string MasterPasswordHintTemplateId = "be77cfde-95dd-4cb9-b5e0-8286b53885f1";
|
||||
private const string OrganizationInviteTemplateId = "1eff5512-e36c-49a8-b9e2-2b215d6bbced";
|
||||
@ -72,6 +73,20 @@ namespace Bit.Core.Services
|
||||
await _mailDeliveryService.SendEmailAsync(message);
|
||||
}
|
||||
|
||||
public async Task SendTwoFactorEmailAsync(string email, string token)
|
||||
{
|
||||
var message = CreateDefaultMessage(
|
||||
"Your Two-step Login Verification Code",
|
||||
email,
|
||||
TwoFactorEmailTemplateId);
|
||||
|
||||
AddSubstitution(message, "{{token}}", Uri.EscapeDataString(token));
|
||||
AddCategories(message, new List<string> { AdministrativeCategoryName, "Two Factor Email" });
|
||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
||||
|
||||
await _mailDeliveryService.SendEmailAsync(message);
|
||||
}
|
||||
|
||||
public async Task SendNoMasterPasswordHintEmailAsync(string email)
|
||||
{
|
||||
var message = CreateDefaultMessage(
|
||||
|
@ -201,7 +201,7 @@ namespace Bit.Core.Services
|
||||
|
||||
var token = await base.GenerateUserTokenAsync(user, TokenOptions.DefaultEmailProvider,
|
||||
"2faEmail:" + provider.MetaData["Email"]);
|
||||
await _mailService.SendChangeEmailEmailAsync((string)provider.MetaData["Email"], token);
|
||||
await _mailService.SendTwoFactorEmailAsync((string)provider.MetaData["Email"], token);
|
||||
}
|
||||
|
||||
public async Task<bool> VerifyTwoFactorEmailAsync(User user, string token)
|
||||
|
Loading…
Reference in New Issue
Block a user