mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 01:22:50 -05:00
Finish emails
This commit is contained in:
@ -205,15 +205,15 @@ namespace Bit.Core.Services
|
||||
await _mailDeliveryService.SendEmailAsync(message);
|
||||
}
|
||||
|
||||
public Task SendOrganizationInviteEmailAsync(string organizationName, OrganizationUser orgUser, ExpiringToken token) =>
|
||||
BulkSendOrganizationInviteEmailAsync(organizationName, new[] { (orgUser, token) });
|
||||
public Task SendOrganizationInviteEmailAsync(string organizationName, bool orgCanSponsor, OrganizationUser orgUser, ExpiringToken token) =>
|
||||
BulkSendOrganizationInviteEmailAsync(organizationName, orgCanSponsor, new[] { (orgUser, token) });
|
||||
|
||||
public async Task BulkSendOrganizationInviteEmailAsync(string organizationName, IEnumerable<(OrganizationUser orgUser, ExpiringToken token)> invites)
|
||||
public async Task BulkSendOrganizationInviteEmailAsync(string organizationName, bool orgCanSponsor, IEnumerable<(OrganizationUser orgUser, ExpiringToken token)> invites)
|
||||
{
|
||||
MailQueueMessage CreateMessage(string email, object model)
|
||||
{
|
||||
var message = CreateDefaultMessage($"Join {organizationName}", email);
|
||||
return new MailQueueMessage(message, "OrganizationUserInvited", model);
|
||||
return new MailQueueMessage(message, orgCanSponsor ? "OrganizationUserInvitedWithSponsorship" : "OrganizationUserInvited", model);
|
||||
}
|
||||
|
||||
var messageModels = invites.Select(invite => CreateMessage(invite.orgUser.Email,
|
||||
@ -761,18 +761,33 @@ namespace Bit.Core.Services
|
||||
{
|
||||
var message = CreateDefaultMessage("Finish Activation - Your Free Families Subscription", email);
|
||||
|
||||
var model = new FamiliesForEnterpriseOfferViewModel
|
||||
if (existingAccount)
|
||||
{
|
||||
SponsorEmail = sponsorEmail,
|
||||
WebVaultUrl = _globalSettings.BaseServiceUri.VaultWithHash,
|
||||
SiteName = _globalSettings.SiteName,
|
||||
SponsorshipToken = token,
|
||||
};
|
||||
var model = new FamiliesForEnterpriseOfferExistingAccountViewModel
|
||||
{
|
||||
SponsorEmail = sponsorEmail,
|
||||
SponsoredEmail = WebUtility.UrlEncode(email),
|
||||
WebVaultUrl = _globalSettings.BaseServiceUri.VaultWithHash,
|
||||
SiteName = _globalSettings.SiteName,
|
||||
SponsorshipToken = token,
|
||||
};
|
||||
|
||||
await AddMessageContentAsync(message, "FamiliesForEnterprise.FamiliesForEnterpriseOfferExistingAccount", model);
|
||||
}
|
||||
else
|
||||
{
|
||||
var model = new FamiliesForEnterpriseOfferNewAccountViewModel
|
||||
{
|
||||
SponsorEmail = sponsorEmail,
|
||||
SponsoredEmail = WebUtility.UrlEncode(email),
|
||||
WebVaultUrl = _globalSettings.BaseServiceUri.VaultWithHash,
|
||||
SiteName = _globalSettings.SiteName,
|
||||
SponsorshipToken = token,
|
||||
};
|
||||
|
||||
await AddMessageContentAsync(message, "FamiliesForEnterprise.FamiliesForEnterpriseOfferNewAccount", model);
|
||||
}
|
||||
|
||||
await AddMessageContentAsync(message, existingAccount
|
||||
? "FamiliesForEnterprise.FamiliesForEnterpriseOfferExistingAccount"
|
||||
: "FamiliesForEnterprise.FamiliesForEnterpriseOfferNewAccount", model);
|
||||
|
||||
message.Category = "FamiliesForEnterpriseOffer";
|
||||
await _mailDeliveryService.SendEmailAsync(message);
|
||||
}
|
||||
|
@ -1239,7 +1239,10 @@ namespace Bit.Core.Services
|
||||
{
|
||||
string MakeToken(OrganizationUser orgUser) =>
|
||||
_dataProtector.Protect($"OrganizationUserInvite {orgUser.Id} {orgUser.Email} {CoreHelpers.ToEpocMilliseconds(DateTime.UtcNow)}");
|
||||
await _mailService.BulkSendOrganizationInviteEmailAsync(organization.Name,
|
||||
|
||||
var orgCanSponsor = CheckOrgCanSponsor(organization);
|
||||
|
||||
await _mailService.BulkSendOrganizationInviteEmailAsync(organization.Name, orgCanSponsor,
|
||||
orgUsers.Select(o => (o, new ExpiringToken(MakeToken(o), DateTime.UtcNow.AddDays(5)))));
|
||||
}
|
||||
|
||||
@ -1249,7 +1252,19 @@ namespace Bit.Core.Services
|
||||
var nowMillis = CoreHelpers.ToEpocMilliseconds(now);
|
||||
var token = _dataProtector.Protect(
|
||||
$"OrganizationUserInvite {orgUser.Id} {orgUser.Email} {nowMillis}");
|
||||
await _mailService.SendOrganizationInviteEmailAsync(organization.Name, orgUser, new ExpiringToken(token, now.AddDays(5)));
|
||||
|
||||
// TODO: Refactor so that the below line can be used.
|
||||
// StaticStore.GetSponsoredPlan(PlanSponsorshipType.FamiliesForEnterprise).UsersCanSponsor(organization)
|
||||
var orgCanSponsor = CheckOrgCanSponsor(organization);
|
||||
|
||||
await _mailService.SendOrganizationInviteEmailAsync(organization.Name, orgCanSponsor, orgUser, new ExpiringToken(token, now.AddDays(5)));
|
||||
}
|
||||
|
||||
|
||||
private static bool CheckOrgCanSponsor(Organization organization)
|
||||
{
|
||||
return StaticStore.GetPlan(organization.PlanType).Product == ProductType.Enterprise
|
||||
&& !organization.SelfHost;
|
||||
}
|
||||
|
||||
public async Task<OrganizationUser> AcceptUserAsync(Guid organizationUserId, User user, string token,
|
||||
|
Reference in New Issue
Block a user