示例#1
0
        public async Task <PaymentResponseModel> PostPremium(PremiumRequestModel model)
        {
            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            var         valid   = model.Validate(_globalSettings);
            UserLicense license = null;

            if (valid && _globalSettings.SelfHosted)
            {
                license = await ApiHelpers.ReadJsonFileFromBody <UserLicense>(HttpContext, model.License);
            }

            if (!valid || (_globalSettings.SelfHosted && license == null))
            {
                throw new BadRequestException("Invalid license.");
            }

            var result = await _userService.SignUpPremiumAsync(user, model.PaymentToken,
                                                               model.PaymentMethodType.Value, model.AdditionalStorageGb.GetValueOrDefault(0), license);

            var profile = new ProfileResponseModel(user, null, await _userService.TwoFactorIsEnabledAsync(user));

            return(new PaymentResponseModel
            {
                UserProfile = profile,
                PaymentIntentClientSecret = result.Item2,
                Success = result.Item1
            });
        }
示例#2
0
        public async Task <ProfileResponseModel> PostPremium(PremiumRequestModel model)
        {
            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            var         valid   = model.Validate(_globalSettings);
            UserLicense license = null;

            if (valid && _globalSettings.SelfHosted)
            {
                license = await ApiHelpers.ReadJsonFileFromBody <UserLicense>(HttpContext, model.License);
            }

            if (!valid || (_globalSettings.SelfHosted && license == null))
            {
                throw new BadRequestException("Invalid license.");
            }

            await _userService.SignUpPremiumAsync(user, model.PaymentToken,
                                                  model.AdditionalStorageGb.GetValueOrDefault(0), license);

            return(new ProfileResponseModel(user, null));
        }
        public async Task <OrganizationResponseModel> PostLicense(OrganizationCreateLicenseRequestModel model)
        {
            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            var license = await ApiHelpers.ReadJsonFileFromBody <OrganizationLicense>(HttpContext, model.License);

            if (license == null)
            {
                throw new BadRequestException("Invalid license");
            }

            var policies = await _policyRepository.GetManyByUserIdAsync(user.Id);

            if (policies.Any(policy => policy.Type == PolicyType.SingleOrg))
            {
                throw new Exception("You may not create an organization. You belong to an organization " +
                                    "which has a policy that prohibits you from being a member of any other organization.");
            }

            var result = await _organizationService.SignUpAsync(license, user, model.Key, model.CollectionName);

            return(new OrganizationResponseModel(result.Item1));
        }
示例#4
0
        public async Task ReadJsonFileFromBody_Success()
        {
            var context = Substitute.For <HttpContext>();

            context.Request.ContentLength.Returns(200);
            var bytes    = Encoding.UTF8.GetBytes(testFile);
            var formFile = new FormFile(new MemoryStream(bytes), 0, bytes.Length, "bitwarden_organization_license", "bitwarden_organization_license.json");


            var license = await ApiHelpers.ReadJsonFileFromBody <OrganizationLicense>(context, formFile);

            Assert.Equal(8, license.Version);
        }
示例#5
0
        public async Task PostLicense(LicenseRequestModel model)
        {
            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            var license = await ApiHelpers.ReadJsonFileFromBody <UserLicense>(HttpContext, model.License);

            if (license == null)
            {
                throw new BadRequestException("Invalid license");
            }

            await _userService.UpdateLicenseAsync(user, license);
        }
示例#6
0
        public async Task PostLicense(string id, LicenseRequestModel model)
        {
            var orgIdGuid = new Guid(id);

            if (!_currentContext.OrganizationOwner(orgIdGuid))
            {
                throw new NotFoundException();
            }

            var license = await ApiHelpers.ReadJsonFileFromBody <OrganizationLicense>(HttpContext, model.License);

            if (license == null)
            {
                throw new BadRequestException("Invalid license");
            }

            await _organizationService.UpdateLicenseAsync(new Guid(id), license);
        }
示例#7
0
        public async Task <OrganizationResponseModel> PostLicense(OrganizationCreateLicenseRequestModel model)
        {
            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            var license = await ApiHelpers.ReadJsonFileFromBody <OrganizationLicense>(HttpContext, model.License);

            if (license == null)
            {
                throw new BadRequestException("Invalid license");
            }

            var result = await _organizationService.SignUpAsync(license, user, model.Key, model.CollectionName);

            return(new OrganizationResponseModel(result.Item1));
        }