1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 09:32:48 -05:00

License expiration email for self-hosted org/premium accounts

This commit is contained in:
Matt Portune
2020-05-18 16:06:34 -04:00
parent e71617886a
commit 2cf7f18858
8 changed files with 62 additions and 0 deletions

View File

@ -278,6 +278,18 @@ namespace Bit.Core.Services
message.Category = "AddedCredit";
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendLicenseExpiredAsync(IEnumerable<string> emails, bool isOrganization)
{
var message = CreateDefaultMessage("License Expired", emails);
var model = new LicenseExpiredViewModel
{
IsOrganization = isOrganization
};
await AddMessageContentAsync(message, "LicenseExpired", model);
message.Category = "LicenseExpired";
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendNewDeviceLoggedInEmail(string email, string deviceType, DateTime timestamp, string ip)
{

View File

@ -24,6 +24,7 @@ namespace Bit.Core.Services
private readonly IUserRepository _userRepository;
private readonly IOrganizationRepository _organizationRepository;
private readonly IOrganizationUserRepository _organizationUserRepository;
private readonly IMailService _mailService;
private readonly ILogger<LicensingService> _logger;
private IDictionary<Guid, DateTime> _userCheckCache = new Dictionary<Guid, DateTime>();
@ -32,6 +33,7 @@ namespace Bit.Core.Services
IUserRepository userRepository,
IOrganizationRepository organizationRepository,
IOrganizationUserRepository organizationUserRepository,
IMailService mailService,
IWebHostEnvironment environment,
ILogger<LicensingService> logger,
GlobalSettings globalSettings)
@ -39,6 +41,7 @@ namespace Bit.Core.Services
_userRepository = userRepository;
_organizationRepository = organizationRepository;
_organizationUserRepository = organizationUserRepository;
_mailService = mailService;
_logger = logger;
_globalSettings = globalSettings;
@ -124,6 +127,8 @@ namespace Bit.Core.Services
org.ExpirationDate = license?.Expires ?? DateTime.UtcNow;
org.RevisionDate = DateTime.UtcNow;
await _organizationRepository.ReplaceAsync(org);
await _mailService.SendLicenseExpiredAsync(new List<string> {org.BillingEmail}, true);
}
public async Task ValidateUsersAsync()
@ -213,6 +218,8 @@ namespace Bit.Core.Services
user.PremiumExpirationDate = license?.Expires ?? DateTime.UtcNow;
user.RevisionDate = DateTime.UtcNow;
await _userRepository.ReplaceAsync(user);
await _mailService.SendLicenseExpiredAsync(new List<string> {user.Email}, false);
}
public bool VerifyLicense(ILicense license)