public async Task <IActionResult> Access(string id, [FromBody] SendAccessRequestModel model)
        {
            var guid = new Guid(CoreHelpers.Base64UrlDecode(id));

            var(send, passwordRequired, passwordInvalid) =
                await _sendService.AccessAsync(guid, model.Password);

            if (passwordRequired)
            {
                return(new UnauthorizedResult());
            }
            if (passwordInvalid)
            {
                await Task.Delay(2000);

                throw new BadRequestException("Invalid password.");
            }
            if (send == null)
            {
                throw new NotFoundException();
            }

            var sendResponse = new SendAccessResponseModel(send, _globalSettings);

            if (send.UserId.HasValue)
            {
                var creator = await _userService.GetUserByIdAsync(send.UserId.Value);

                sendResponse.CreatorIdentifier = creator.Email;
            }
            return(new ObjectResult(sendResponse));
        }
        public async Task <IActionResult> GetSendFileDownloadData(string encodedSendId,
                                                                  string fileId, [FromBody] SendAccessRequestModel model)
        {
            var sendId = new Guid(CoreHelpers.Base64UrlDecode(encodedSendId));
            var send   = await _sendRepository.GetByIdAsync(sendId);

            if (send == null)
            {
                throw new BadRequestException("Could not locate send");
            }

            var(url, passwordRequired, passwordInvalid) = await _sendService.GetSendFileDownloadUrlAsync(send, fileId,
                                                                                                         model.Password);

            if (passwordRequired)
            {
                return(new UnauthorizedResult());
            }
            if (passwordInvalid)
            {
                await Task.Delay(2000);

                throw new BadRequestException("Invalid password.");
            }
            if (send == null)
            {
                throw new NotFoundException();
            }

            return(new ObjectResult(new SendFileDownloadDataResponseModel()
            {
                Id = fileId,
                Url = url,
            }));
        }
Exemple #3
0
        public async Task <IActionResult> GetSendFileDownloadData(string encodedSendId,
                                                                  string fileId, [FromBody] SendAccessRequestModel model)
        {
            // Uncomment whenever we want to require the `send-id` header
            //if (!_currentContext.HttpContext.Request.Headers.ContainsKey("Send-Id") ||
            //    _currentContext.HttpContext.Request.Headers["Send-Id"] != encodedSendId)
            //{
            //    throw new BadRequestException("Invalid Send-Id header.");
            //}

            var sendId = new Guid(CoreHelpers.Base64UrlDecode(encodedSendId));
            var send   = await _sendRepository.GetByIdAsync(sendId);

            if (send == null)
            {
                throw new BadRequestException("Could not locate send");
            }

            var(url, passwordRequired, passwordInvalid) = await _sendService.GetSendFileDownloadUrlAsync(send, fileId,
                                                                                                         model.Password);

            if (passwordRequired)
            {
                return(new UnauthorizedResult());
            }
            if (passwordInvalid)
            {
                await Task.Delay(2000);

                throw new BadRequestException("Invalid password.");
            }
            if (send == null)
            {
                throw new NotFoundException();
            }

            return(new ObjectResult(new SendFileDownloadDataResponseModel()
            {
                Id = fileId,
                Url = url,
            }));
        }
Exemple #4
0
        public async Task SendsController_WhenSendHidesEmail_CreatorIdentifierShouldBeNull(
            Guid id, Send send, User user)
        {
            var accessId = CoreHelpers.Base64UrlEncode(id.ToByteArray());

            send.Id        = default;
            send.Type      = SendType.Text;
            send.Data      = JsonConvert.SerializeObject(new Dictionary <string, string>());
            send.HideEmail = true;

            _sendService.AccessAsync(id, null).Returns((send, false, false));
            _userService.GetUserByIdAsync(Arg.Any <Guid>()).Returns(user);

            var request      = new SendAccessRequestModel();
            var actionResult = await _sut.Access(accessId, request);

            var response = (actionResult as ObjectResult)?.Value as SendAccessResponseModel;

            Assert.NotNull(response);
            Assert.Null(response.CreatorIdentifier);
        }
Exemple #5
0
        public async Task <IActionResult> Access(string id, [FromBody] SendAccessRequestModel model)
        {
            // Uncomment whenever we want to require the `send-id` header
            //if (!_currentContext.HttpContext.Request.Headers.ContainsKey("Send-Id") ||
            //    _currentContext.HttpContext.Request.Headers["Send-Id"] != id)
            //{
            //    throw new BadRequestException("Invalid Send-Id header.");
            //}

            var guid = new Guid(CoreHelpers.Base64UrlDecode(id));

            var(send, passwordRequired, passwordInvalid) =
                await _sendService.AccessAsync(guid, model.Password);

            if (passwordRequired)
            {
                return(new UnauthorizedResult());
            }
            if (passwordInvalid)
            {
                await Task.Delay(2000);

                throw new BadRequestException("Invalid password.");
            }
            if (send == null)
            {
                throw new NotFoundException();
            }

            var sendResponse = new SendAccessResponseModel(send, _globalSettings);

            if (send.UserId.HasValue && !send.HideEmail.GetValueOrDefault())
            {
                var creator = await _userService.GetUserByIdAsync(send.UserId.Value);

                sendResponse.CreatorIdentifier = creator.Email;
            }
            return(new ObjectResult(sendResponse));
        }
Exemple #6
0
        public async Task <IActionResult> Access(string id, [FromBody] SendAccessRequestModel model)
        {
            var guid = new Guid(CoreHelpers.Base64UrlDecode(id));

            var(send, passwordRequired, passwordInvalid) =
                await _sendService.AccessAsync(guid, model.Password);

            if (passwordRequired)
            {
                return(new UnauthorizedResult());
            }
            if (passwordInvalid)
            {
                await Task.Delay(2000);

                throw new BadRequestException("Invalid password.");
            }
            if (send == null)
            {
                throw new NotFoundException();
            }

            return(new ObjectResult(new SendAccessResponseModel(send, _globalSettings)));
        }