1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05:00

update premium license and self host attr checks

This commit is contained in:
Kyle Spearrin
2017-08-14 12:08:57 -04:00
parent 9e566e90a9
commit 18cbc79dd2
6 changed files with 107 additions and 0 deletions

View File

@ -598,6 +598,30 @@ namespace Bit.Core.Services
}
}
public async Task UpdateLicenseAsync(User user, UserLicense license)
{
if(!_globalSettings.SelfHosted)
{
throw new InvalidOperationException("Licenses require self hosting.");
}
if(license == null || !_licenseService.VerifyLicense(license))
{
throw new BadRequestException("Invalid license.");
}
var dir = $"{_globalSettings.LicenseDirectory}/user";
Directory.CreateDirectory(dir);
File.WriteAllText($"{dir}/{user.Id}.json", JsonConvert.SerializeObject(license, Formatting.Indented));
user.Premium = true;
user.RevisionDate = DateTime.UtcNow;
user.MaxStorageGb = 10240; // 10 TB
user.LicenseKey = license.LicenseKey;
user.PremiumExpirationDate = license.Expires;
await SaveUserAsync(user);
}
public async Task AdjustStorageAsync(User user, short storageAdjustmentGb)
{
if(user == null)