예제 #1
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();
            }

            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));
        }
예제 #2
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));
        }