mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 00:52:49 -05:00
premium signup with license file
This commit is contained in:
@ -9,14 +9,6 @@
|
||||
<DockerComposeProjectPath>..\..\docker\Docker.dcproj</DockerComposeProjectPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="licensing.cer" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="licensing.cer" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core\Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -12,6 +12,9 @@ using System.Linq;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Utilities;
|
||||
using Bit.Core;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using Bit.Core.Models.Business;
|
||||
|
||||
namespace Bit.Api.Controllers
|
||||
{
|
||||
@ -378,7 +381,7 @@ namespace Bit.Api.Controllers
|
||||
}
|
||||
|
||||
[HttpPost("premium")]
|
||||
public async Task<ProfileResponseModel> PostPremium([FromBody]PremiumRequestModel model)
|
||||
public async Task<ProfileResponseModel> PostPremium(PremiumRequestModel model)
|
||||
{
|
||||
var user = await _userService.GetUserByPrincipalAsync(User);
|
||||
if(user == null)
|
||||
@ -386,7 +389,32 @@ namespace Bit.Api.Controllers
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
await _userService.SignUpPremiumAsync(user, model.PaymentToken, model.AdditionalStorageGb.GetValueOrDefault(0));
|
||||
var valid = model.Validate(_globalSettings);
|
||||
UserLicense license = null;
|
||||
if(valid && model.License != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var stream = model.License.OpenReadStream())
|
||||
using(var reader = new StreamReader(stream))
|
||||
{
|
||||
var s = await reader.ReadToEndAsync();
|
||||
license = JsonConvert.DeserializeObject<UserLicense>(s);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(!valid)
|
||||
{
|
||||
throw new BadRequestException("Invalid license.");
|
||||
}
|
||||
|
||||
await _userService.SignUpPremiumAsync(user, model.PaymentToken,
|
||||
model.AdditionalStorageGb.GetValueOrDefault(0), license);
|
||||
return new ProfileResponseModel(user, null);
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Reference in New Issue
Block a user