mirror of
https://github.com/bitwarden/server.git
synced 2024-12-11 15:17:44 +01:00
clean out deprecated services. update libs.
This commit is contained in:
parent
81d2e3e608
commit
434723e637
@ -9,17 +9,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="licensing.cer" />
|
<EmbeddedResource Include="licensing.cer" />
|
||||||
<EmbeddedResource Include="MailTemplates\Markdown\ChangeEmail.md" />
|
|
||||||
<EmbeddedResource Include="MailTemplates\Markdown\ChangeEmailAlreadyExists.md" />
|
|
||||||
<EmbeddedResource Include="MailTemplates\Markdown\MasterPasswordHint.md" />
|
|
||||||
<EmbeddedResource Include="MailTemplates\Markdown\NoMasterPasswordHint.md" />
|
|
||||||
<EmbeddedResource Include="MailTemplates\Markdown\OrganizationUserAccepted.md" />
|
|
||||||
<EmbeddedResource Include="MailTemplates\Markdown\OrganizationUserConfirmed.md" />
|
|
||||||
<EmbeddedResource Include="MailTemplates\Markdown\OrganizationUserInvited.md" />
|
|
||||||
<EmbeddedResource Include="MailTemplates\Markdown\TwoFactorEmail.md" />
|
|
||||||
<EmbeddedResource Include="MailTemplates\Markdown\VerifyDelete.md" />
|
|
||||||
<EmbeddedResource Include="MailTemplates\Markdown\VerifyEmail.md" />
|
|
||||||
<EmbeddedResource Include="MailTemplates\Markdown\Welcome.md" />
|
|
||||||
<EmbeddedResource Include="MailTemplates\Razor\VerifyDelete.cshtml" />
|
<EmbeddedResource Include="MailTemplates\Razor\VerifyDelete.cshtml" />
|
||||||
<EmbeddedResource Include="MailTemplates\Razor\VerifyDelete.text.cshtml" />
|
<EmbeddedResource Include="MailTemplates\Razor\VerifyDelete.text.cshtml" />
|
||||||
<EmbeddedResource Include="MailTemplates\Razor\VerifyEmail.cshtml" />
|
<EmbeddedResource Include="MailTemplates\Razor\VerifyEmail.cshtml" />
|
||||||
@ -60,7 +49,7 @@
|
|||||||
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />
|
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />
|
||||||
<PackageReference Include="Serilog.Extensions.Logging.File" Version="1.1.0" />
|
<PackageReference Include="Serilog.Extensions.Logging.File" Version="1.1.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.AzureDocumentDB" Version="3.7.0" />
|
<PackageReference Include="Serilog.Sinks.AzureDocumentDB" Version="3.7.0" />
|
||||||
<PackageReference Include="IdentityServer4" Version="2.0.1" />
|
<PackageReference Include="IdentityServer4" Version="2.0.2" />
|
||||||
<PackageReference Include="Dapper" Version="1.50.4-alpha1-00070" />
|
<PackageReference Include="Dapper" Version="1.50.4-alpha1-00070" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||||
<PackageReference Include="WindowsAzure.Storage" Version="8.5.0" />
|
<PackageReference Include="WindowsAzure.Storage" Version="8.5.0" />
|
||||||
@ -70,7 +59,7 @@
|
|||||||
<PackageReference Include="Portable.BouncyCastle" Version="1.8.1.3" />
|
<PackageReference Include="Portable.BouncyCastle" Version="1.8.1.3" />
|
||||||
<PackageReference Include="RazorLight" Version="2.0.0-alpha3" />
|
<PackageReference Include="RazorLight" Version="2.0.0-alpha3" />
|
||||||
<PackageReference Include="Sendgrid" Version="9.9.0" />
|
<PackageReference Include="Sendgrid" Version="9.9.0" />
|
||||||
<PackageReference Include="Stripe.net" Version="11.6.0" />
|
<PackageReference Include="Stripe.net" Version="11.6.1" />
|
||||||
<PackageReference Include="U2F.Core" Version="1.0.3" />
|
<PackageReference Include="U2F.Core" Version="1.0.3" />
|
||||||
<PackageReference Include="Otp.NET" Version="1.1.0" />
|
<PackageReference Include="Otp.NET" Version="1.1.0" />
|
||||||
<PackageReference Include="YubicoDotNetClient" Version="1.2.0" />
|
<PackageReference Include="YubicoDotNetClient" Version="1.2.0" />
|
||||||
|
@ -1 +0,0 @@
|
|||||||
To finalize changing your email address enter the following code in the pop-up window: {{token}}
|
|
@ -1,3 +0,0 @@
|
|||||||
A user ({{fromEmail}}) recently tried to change their account to use this email address ({{toEmail}}). An account already exists with this email ({{toEmail}}).
|
|
||||||
|
|
||||||
If you did not try to change an email address, you can safely ignore this email.
|
|
@ -1,7 +0,0 @@
|
|||||||
You (or someone) recently requested your master password hint.
|
|
||||||
|
|
||||||
Your hint is: "{{hint}}"
|
|
||||||
|
|
||||||
Login: <{{vaultUrl}}>
|
|
||||||
|
|
||||||
If you did not request your master password hint you can safely ignore this email.
|
|
@ -1,3 +0,0 @@
|
|||||||
You (or someone) recently requested your master password hint. Unfortunately, your account does not have a master password hint.
|
|
||||||
|
|
||||||
If you did not request your master password hint you can safely ignore this email.
|
|
@ -1,5 +0,0 @@
|
|||||||
This email is to notify you that {{userEmail}} has accepted your invitation to join {{organizationName}}.
|
|
||||||
|
|
||||||
To confirm this user, log into the bitwarden web vault, manage your organization "People" and confirm the user.
|
|
||||||
|
|
||||||
If you do not wish to confirm this user, you can also remove them from the organization on the same page.
|
|
@ -1,3 +0,0 @@
|
|||||||
This email is to notify you that you have been confirmed as a user of {{organizationName}}.
|
|
||||||
|
|
||||||
Any collections and logins being shared with you by this organization will now appear in your bitwarden vault.
|
|
@ -1,6 +0,0 @@
|
|||||||
You have been invited to join the {{organizationName}} organization. To accept this invite, click the
|
|
||||||
following link:
|
|
||||||
|
|
||||||
<{{url}}>
|
|
||||||
|
|
||||||
If you do not wish to join this organization, you can safely ignore this email.
|
|
@ -1,3 +0,0 @@
|
|||||||
Your two-step verification code is: {{token}}
|
|
||||||
|
|
||||||
Use this code to complete logging in with bitwarden.
|
|
@ -1,3 +0,0 @@
|
|||||||
Click the link below to delete your bitwarden account ({{email}}). If you did not request this email to delete your bitwarden account, you can safely ignore it.
|
|
||||||
|
|
||||||
<{{url}}>
|
|
@ -1,3 +0,0 @@
|
|||||||
Verify this email address for your bitwarden account by clicking the following link. If you did not request this email to verify a bitwarden account, you can safely ignore it.
|
|
||||||
|
|
||||||
<{{url}}>
|
|
@ -1,40 +0,0 @@
|
|||||||
Thank you for creating an account with bitwarden. You may now log in with your new account.
|
|
||||||
|
|
||||||
Did you know that bitwarden is free to sync with all of your devices? Download bitwarden today on:
|
|
||||||
|
|
||||||
Mobile
|
|
||||||
============
|
|
||||||
|
|
||||||
## iOS
|
|
||||||
<https://itunes.apple.com/us/app/bitwarden-free-password-manager/id1137397744?mt=8>
|
|
||||||
|
|
||||||
## Android
|
|
||||||
<https://play.google.com/store/apps/details?id=com.x8bit.bitwarden>
|
|
||||||
|
|
||||||
Desktop
|
|
||||||
============
|
|
||||||
|
|
||||||
## Chrome Extension
|
|
||||||
<https://chrome.google.com/webstore/detail/bitwarden-free-password-m/nngceckbapebfimnlniiiahkandclblb?utm_source=welcome_email&utm_medium=email>
|
|
||||||
|
|
||||||
## Firefox Extension
|
|
||||||
<https://addons.mozilla.org/firefox/addon/bitwarden-password-manager/>
|
|
||||||
|
|
||||||
## Opera Extension
|
|
||||||
<https://addons.opera.com/extensions/details/bitwarden-free-password-manager/?utm_source=welcome_email&utm_medium=email>
|
|
||||||
|
|
||||||
## Edge Extension
|
|
||||||
<https://www.microsoft.com/store/p/bitwarden-free-password-manager/9p6kxl0svnnl>
|
|
||||||
|
|
||||||
Web
|
|
||||||
============
|
|
||||||
|
|
||||||
You can also access your vault from any web-enabled device using our web vault at: <{{vaultUrl}}?utm_source=welcome_email&utm_medium=email>
|
|
||||||
|
|
||||||
------------
|
|
||||||
|
|
||||||
If you have any questions or problems you can email us from our website at:
|
|
||||||
<https://bitwarden.com/contact/?utm_source=welcome_email&utm_medium=email>
|
|
||||||
|
|
||||||
Thank you!
|
|
||||||
The bitwarden Team
|
|
@ -1,210 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Bit.Core.Models.Table;
|
|
||||||
using Bit.Core.Models.Mail;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace Bit.Core.Services
|
|
||||||
{
|
|
||||||
public class MarkdownMailService : IMailService
|
|
||||||
{
|
|
||||||
private const string Namespace = "Bit.Core.MailTemplates.Markdown";
|
|
||||||
|
|
||||||
private readonly GlobalSettings _globalSettings;
|
|
||||||
private readonly IMailDeliveryService _mailDeliveryService;
|
|
||||||
|
|
||||||
public MarkdownMailService(
|
|
||||||
GlobalSettings globalSettings,
|
|
||||||
IMailDeliveryService mailDeliveryService)
|
|
||||||
{
|
|
||||||
_globalSettings = globalSettings;
|
|
||||||
_mailDeliveryService = mailDeliveryService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendVerifyEmailEmailAsync(string email, Guid userId, string token)
|
|
||||||
{
|
|
||||||
var model = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
["url"] = string.Format("{0}/verify-email?userId={1}&token={2}",
|
|
||||||
_globalSettings.BaseServiceUri.VaultWithHash, userId, WebUtility.UrlEncode(token))
|
|
||||||
};
|
|
||||||
|
|
||||||
var message = await CreateMessageAsync("Verify Your Email", email, "VerifyEmail", model);
|
|
||||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendVerifyDeleteEmailAsync(string email, Guid userId, string token)
|
|
||||||
{
|
|
||||||
var model = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
["url"] = string.Format("{0}/verify-recover-delete?userId={1}&token={2}&email={3}",
|
|
||||||
_globalSettings.BaseServiceUri.VaultWithHash,
|
|
||||||
userId,
|
|
||||||
WebUtility.UrlEncode(token),
|
|
||||||
WebUtility.UrlEncode(email)),
|
|
||||||
["email"] = WebUtility.HtmlEncode(email)
|
|
||||||
};
|
|
||||||
|
|
||||||
var message = await CreateMessageAsync("Delete Your Account", email, "VerifyDelete", model);
|
|
||||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendChangeEmailAlreadyExistsEmailAsync(string fromEmail, string toEmail)
|
|
||||||
{
|
|
||||||
var model = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
["fromEmail"] = WebUtility.HtmlEncode(fromEmail),
|
|
||||||
["toEmail"] = WebUtility.HtmlEncode(toEmail),
|
|
||||||
};
|
|
||||||
|
|
||||||
var message = await CreateMessageAsync("Your Email Change", toEmail, "ChangeEmailAlreadyExists", model);
|
|
||||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendChangeEmailEmailAsync(string newEmailAddress, string token)
|
|
||||||
{
|
|
||||||
var model = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
["token"] = token
|
|
||||||
};
|
|
||||||
|
|
||||||
var message = await CreateMessageAsync("Your Email Change", newEmailAddress, "ChangeEmail", model);
|
|
||||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendTwoFactorEmailAsync(string email, string token)
|
|
||||||
{
|
|
||||||
var model = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
["token"] = token
|
|
||||||
};
|
|
||||||
|
|
||||||
var message = await CreateMessageAsync("Your Two-step Login Verification Code", email, "TwoFactorEmail", model);
|
|
||||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendMasterPasswordHintEmailAsync(string email, string hint)
|
|
||||||
{
|
|
||||||
var model = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
["hint"] = WebUtility.HtmlEncode(hint),
|
|
||||||
["vaultUrl"] = _globalSettings.BaseServiceUri.VaultWithHash
|
|
||||||
};
|
|
||||||
|
|
||||||
var message = await CreateMessageAsync("Your Master Password Hint", email, "MasterPasswordHint", model);
|
|
||||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendNoMasterPasswordHintEmailAsync(string email)
|
|
||||||
{
|
|
||||||
var message = await CreateMessageAsync("Your Master Password Hint", email, "NoMasterPasswordHint", null);
|
|
||||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendOrganizationAcceptedEmailAsync(string organizationName, string userEmail,
|
|
||||||
IEnumerable<string> adminEmails)
|
|
||||||
{
|
|
||||||
var model = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
["userEmail"] = WebUtility.HtmlEncode(userEmail),
|
|
||||||
["organizationName"] = WebUtility.HtmlEncode(organizationName)
|
|
||||||
};
|
|
||||||
|
|
||||||
var message = await CreateMessageAsync($"User {userEmail} Has Accepted Invite", adminEmails,
|
|
||||||
"OrganizationUserAccepted", model);
|
|
||||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendOrganizationConfirmedEmailAsync(string organizationName, string email)
|
|
||||||
{
|
|
||||||
var model = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
["organizationName"] = WebUtility.HtmlEncode(organizationName)
|
|
||||||
};
|
|
||||||
|
|
||||||
var message = await CreateMessageAsync($"You Have Been Confirmed To {organizationName}", email,
|
|
||||||
"OrganizationUserConfirmed", model);
|
|
||||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendOrganizationInviteEmailAsync(string organizationName, OrganizationUser orgUser, string token)
|
|
||||||
{
|
|
||||||
var model = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
["organizationName"] = WebUtility.HtmlEncode(organizationName),
|
|
||||||
["url"] = string.Format("{0}/accept-organization?organizationId={1}&organizationUserId={2}" +
|
|
||||||
"&email={3}&organizationName={4}&token={5}",
|
|
||||||
_globalSettings.BaseServiceUri.VaultWithHash,
|
|
||||||
orgUser.OrganizationId,
|
|
||||||
orgUser.Id,
|
|
||||||
WebUtility.UrlEncode(orgUser.Email),
|
|
||||||
WebUtility.UrlEncode(organizationName),
|
|
||||||
WebUtility.UrlEncode(token))
|
|
||||||
};
|
|
||||||
|
|
||||||
var message = await CreateMessageAsync($"Join {organizationName}", orgUser.Email, "OrganizationUserInvited", model);
|
|
||||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendWelcomeEmailAsync(User user)
|
|
||||||
{
|
|
||||||
var model = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
["vaultUrl"] = _globalSettings.BaseServiceUri.VaultWithHash
|
|
||||||
};
|
|
||||||
|
|
||||||
var message = await CreateMessageAsync("Welcome", user.Email, "Welcome", model);
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<MailMessage> CreateMessageAsync(string subject, string toEmail, string fileName,
|
|
||||||
Dictionary<string, string> model)
|
|
||||||
{
|
|
||||||
return await CreateMessageAsync(subject, new List<string> { toEmail }, fileName, model);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<MailMessage> CreateMessageAsync(string subject, IEnumerable<string> toEmails, string fileName,
|
|
||||||
Dictionary<string, string> model)
|
|
||||||
{
|
|
||||||
var message = new MailMessage
|
|
||||||
{
|
|
||||||
ToEmails = toEmails,
|
|
||||||
Subject = subject,
|
|
||||||
MetaData = new Dictionary<string, object>()
|
|
||||||
};
|
|
||||||
|
|
||||||
var assembly = typeof(MarkdownMailService).GetTypeInfo().Assembly;
|
|
||||||
using(var s = assembly.GetManifestResourceStream($"{Namespace}.{fileName}.md"))
|
|
||||||
using(var sr = new StreamReader(s))
|
|
||||||
{
|
|
||||||
var markdown = await sr.ReadToEndAsync();
|
|
||||||
|
|
||||||
if(model != null)
|
|
||||||
{
|
|
||||||
foreach(var prop in model)
|
|
||||||
{
|
|
||||||
markdown = markdown.Replace($"{{{{{prop.Key}}}}}", prop.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
message.HtmlContent = CommonMark.CommonMarkConverter.Convert(markdown);
|
|
||||||
message.TextContent = markdown;
|
|
||||||
}
|
|
||||||
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,254 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Bit.Core.Models.Table;
|
|
||||||
using System.Net;
|
|
||||||
using Bit.Core.Models.Mail;
|
|
||||||
|
|
||||||
namespace Bit.Core.Services
|
|
||||||
{
|
|
||||||
public class SendGridTemplateMailService : IMailService
|
|
||||||
{
|
|
||||||
private const string WelcomeTemplateId = "045f8ad5-5547-4fa2-8d3d-6d46e401164d";
|
|
||||||
private const string VerifyEmailTemplateId = "TODO";
|
|
||||||
private const string VerifyDeleteTemplateId = "TODO";
|
|
||||||
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";
|
|
||||||
private const string OrganizationAcceptedTemplateId = "28f7f741-598e-449c-85fe-601e1cc32ba3";
|
|
||||||
private const string OrganizationConfirmedTemplateId = "a8afe2a0-6161-4eb9-b40c-08a7f520ec50";
|
|
||||||
|
|
||||||
private const string AdministrativeCategoryName = "Administrative";
|
|
||||||
private const string MarketingCategoryName = "Marketing";
|
|
||||||
|
|
||||||
private readonly GlobalSettings _globalSettings;
|
|
||||||
private readonly IMailDeliveryService _mailDeliveryService;
|
|
||||||
|
|
||||||
public SendGridTemplateMailService(
|
|
||||||
GlobalSettings globalSettings,
|
|
||||||
IMailDeliveryService mailDeliveryService)
|
|
||||||
{
|
|
||||||
_globalSettings = globalSettings;
|
|
||||||
_mailDeliveryService = mailDeliveryService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendWelcomeEmailAsync(User user)
|
|
||||||
{
|
|
||||||
var message = CreateDefaultMessage(
|
|
||||||
"Welcome",
|
|
||||||
user.Email,
|
|
||||||
WelcomeTemplateId);
|
|
||||||
|
|
||||||
AddCategories(message, new List<string> { AdministrativeCategoryName, "Welcome" });
|
|
||||||
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendVerifyEmailEmailAsync(string email, Guid userId, string token)
|
|
||||||
{
|
|
||||||
var message = CreateDefaultMessage(
|
|
||||||
"Verify Your Email",
|
|
||||||
email,
|
|
||||||
VerifyEmailTemplateId);
|
|
||||||
|
|
||||||
AddSubstitution(message, "{{token}}", WebUtility.UrlEncode(token));
|
|
||||||
AddSubstitution(message, "{{userId}}", userId.ToString());
|
|
||||||
AddCategories(message, new List<string> { AdministrativeCategoryName, "Verify Email" });
|
|
||||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
|
||||||
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendVerifyDeleteEmailAsync(string email, Guid userId, string token)
|
|
||||||
{
|
|
||||||
var message = CreateDefaultMessage(
|
|
||||||
"Delete Your Account",
|
|
||||||
email,
|
|
||||||
VerifyDeleteTemplateId);
|
|
||||||
|
|
||||||
AddSubstitution(message, "{{token}}", WebUtility.UrlEncode(token));
|
|
||||||
AddSubstitution(message, "{{email}}", email);
|
|
||||||
AddSubstitution(message, "{{emailUrlEncoded}}", WebUtility.UrlEncode(email));
|
|
||||||
AddSubstitution(message, "{{userId}}", userId.ToString());
|
|
||||||
AddCategories(message, new List<string> { AdministrativeCategoryName, "Verify Delete" });
|
|
||||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
|
||||||
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendChangeEmailAlreadyExistsEmailAsync(string fromEmail, string toEmail)
|
|
||||||
{
|
|
||||||
var message = CreateDefaultMessage(
|
|
||||||
"Your Email Change",
|
|
||||||
toEmail,
|
|
||||||
ChangeEmailAlreadyExistsTemplateId);
|
|
||||||
|
|
||||||
AddSubstitution(message, "{{fromEmail}}", fromEmail);
|
|
||||||
AddSubstitution(message, "{{toEmail}}", toEmail);
|
|
||||||
AddCategories(message, new List<string> { AdministrativeCategoryName, "Change Email Already Exists" });
|
|
||||||
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendChangeEmailEmailAsync(string newEmailAddress, string token)
|
|
||||||
{
|
|
||||||
var message = CreateDefaultMessage(
|
|
||||||
"Your Email Change",
|
|
||||||
newEmailAddress,
|
|
||||||
ChangeEmailTemplateId);
|
|
||||||
|
|
||||||
AddSubstitution(message, "{{token}}", Uri.EscapeDataString(token));
|
|
||||||
AddCategories(message, new List<string> { AdministrativeCategoryName, "Change Email" });
|
|
||||||
message.MetaData.Add("SendGridBypassListManagement", true);
|
|
||||||
|
|
||||||
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(
|
|
||||||
"Your Master Password Hint",
|
|
||||||
email,
|
|
||||||
NoMasterPasswordHintTemplateId);
|
|
||||||
AddCategories(message, new List<string> { AdministrativeCategoryName, "No Master Password Hint" });
|
|
||||||
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendMasterPasswordHintEmailAsync(string email, string hint)
|
|
||||||
{
|
|
||||||
var message = CreateDefaultMessage(
|
|
||||||
"Your Master Password Hint",
|
|
||||||
email,
|
|
||||||
MasterPasswordHintTemplateId);
|
|
||||||
|
|
||||||
message.Subject = "Your Master Password Hint";
|
|
||||||
AddSubstitution(message, "{{hint}}", hint);
|
|
||||||
AddCategories(message, new List<string> { AdministrativeCategoryName, "Master Password Hint" });
|
|
||||||
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendOrganizationInviteEmailAsync(string organizationName, OrganizationUser orgUser, string token)
|
|
||||||
{
|
|
||||||
var message = CreateDefaultMessage(
|
|
||||||
$"Join {organizationName}",
|
|
||||||
orgUser.Email,
|
|
||||||
OrganizationInviteTemplateId);
|
|
||||||
|
|
||||||
AddSubstitution(message, "{{organizationName}}", organizationName);
|
|
||||||
AddSubstitution(message, "{{organizationId}}", orgUser.OrganizationId.ToString());
|
|
||||||
AddSubstitution(message, "{{organizationUserId}}", orgUser.Id.ToString());
|
|
||||||
AddSubstitution(message, "{{token}}", token);
|
|
||||||
AddSubstitution(message, "{{email}}", WebUtility.UrlEncode(orgUser.Email));
|
|
||||||
AddSubstitution(message, "{{organizationNameUrlEncoded}}", WebUtility.UrlEncode(organizationName));
|
|
||||||
AddCategories(message, new List<string> { AdministrativeCategoryName, "Organization User Invite" });
|
|
||||||
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendOrganizationAcceptedEmailAsync(string organizationName, string userEmail,
|
|
||||||
IEnumerable<string> adminEmails)
|
|
||||||
{
|
|
||||||
var message = CreateDefaultMessage(
|
|
||||||
$"User {userEmail} Has Accepted Invite",
|
|
||||||
adminEmails,
|
|
||||||
OrganizationAcceptedTemplateId);
|
|
||||||
|
|
||||||
AddSubstitution(message, "{{userEmail}}", userEmail);
|
|
||||||
AddSubstitution(message, "{{organizationName}}", organizationName);
|
|
||||||
AddCategories(message, new List<string> { AdministrativeCategoryName, "Organization User Accepted" });
|
|
||||||
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendOrganizationConfirmedEmailAsync(string organizationName, string email)
|
|
||||||
{
|
|
||||||
var message = CreateDefaultMessage(
|
|
||||||
$"You Have Been Confirmed To {organizationName}",
|
|
||||||
email,
|
|
||||||
OrganizationConfirmedTemplateId);
|
|
||||||
|
|
||||||
AddSubstitution(message, "{{organizationName}}", organizationName);
|
|
||||||
AddCategories(message, new List<string> { AdministrativeCategoryName, "Organization User Confirmed" });
|
|
||||||
|
|
||||||
await _mailDeliveryService.SendEmailAsync(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
private MailMessage CreateDefaultMessage(string subject, string toEmail, string templateId)
|
|
||||||
{
|
|
||||||
return CreateDefaultMessage(subject, new List<string> { toEmail }, templateId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private MailMessage CreateDefaultMessage(string subject, IEnumerable<string> toEmails, string templateId)
|
|
||||||
{
|
|
||||||
var message = new MailMessage
|
|
||||||
{
|
|
||||||
HtmlContent = " ",
|
|
||||||
TextContent = " ",
|
|
||||||
MetaData = new Dictionary<string, object>(),
|
|
||||||
ToEmails = toEmails,
|
|
||||||
Subject = subject
|
|
||||||
};
|
|
||||||
|
|
||||||
if(!string.IsNullOrWhiteSpace(templateId))
|
|
||||||
{
|
|
||||||
message.MetaData.Add("SendGridTemplateId", templateId);
|
|
||||||
}
|
|
||||||
|
|
||||||
AddSubstitution(message, "{{siteName}}", _globalSettings.SiteName);
|
|
||||||
AddSubstitution(message, "{{baseVaultUri}}", _globalSettings.BaseServiceUri.VaultWithHash);
|
|
||||||
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AddSubstitution(MailMessage message, string key, string value)
|
|
||||||
{
|
|
||||||
Dictionary<string, string> dict;
|
|
||||||
if(!message.MetaData.ContainsKey("SendGridSubstitutions"))
|
|
||||||
{
|
|
||||||
dict = new Dictionary<string, string>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dict = message.MetaData["SendGridSubstitutions"] as Dictionary<string, string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
dict.Add(key, value);
|
|
||||||
message.MetaData["SendGridSubstitutions"] = dict;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AddCategories(MailMessage message, List<string> categories)
|
|
||||||
{
|
|
||||||
List<string> cats;
|
|
||||||
if(!message.MetaData.ContainsKey("SendGridCategories"))
|
|
||||||
{
|
|
||||||
cats = categories;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cats = message.MetaData["SendGridCategories"] as List<string>;
|
|
||||||
cats.AddRange(categories);
|
|
||||||
}
|
|
||||||
|
|
||||||
message.MetaData["SendGridCategories"] = cats;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -56,15 +56,7 @@ namespace Bit.Core.Utilities
|
|||||||
|
|
||||||
public static void AddDefaultServices(this IServiceCollection services, GlobalSettings globalSettings)
|
public static void AddDefaultServices(this IServiceCollection services, GlobalSettings globalSettings)
|
||||||
{
|
{
|
||||||
if(globalSettings.SelfHosted)
|
services.AddSingleton<IMailService, RazorMailService>();
|
||||||
{
|
|
||||||
services.AddSingleton<IMailService, MarkdownMailService>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
services.AddSingleton<IMailService, RazorMailService>();
|
|
||||||
}
|
|
||||||
|
|
||||||
services.AddSingleton<ILicensingService, LicensingService>();
|
services.AddSingleton<ILicensingService, LicensingService>();
|
||||||
|
|
||||||
if(CoreHelpers.SettingHasValue(globalSettings.Mail.SendGridApiKey))
|
if(CoreHelpers.SettingHasValue(globalSettings.Mail.SendGridApiKey))
|
||||||
|
Loading…
Reference in New Issue
Block a user