コード例 #1
0
        public async Task <ApiKeyResponseModel> ApiKey(string id, [FromBody] ApiKeyRequestModel model)
        {
            var orgIdGuid = new Guid(id);

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

            var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);

            if (organization == null)
            {
                throw new NotFoundException();
            }

            var user = await _userService.GetUserByPrincipalAsync(User);

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

            if (!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
            {
                await Task.Delay(2000);

                throw new BadRequestException("MasterPasswordHash", "Invalid password.");
            }
            else
            {
                var response = new ApiKeyResponseModel(organization);
                return(response);
            }
        }
コード例 #2
0
        public async Task <ApiKeyResponseModel> ApiKey([FromBody] ApiKeyRequestModel model)
        {
            var user = await _userService.GetUserByPrincipalAsync(User);

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

            if (!await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
            {
                await Task.Delay(2000);

                throw new BadRequestException("MasterPasswordHash", "Invalid password.");
            }
            else
            {
                var response = new ApiKeyResponseModel(user);
                return(response);
            }
        }