1
0
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:
Kyle Spearrin
2017-08-11 17:06:31 -04:00
parent 02bb037e38
commit 73029f76d2
15 changed files with 125 additions and 42 deletions

View File

@ -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>

View File

@ -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.