Beispiel #1
0
        // Response: Send, password required, password invalid
        public async Task <(Send, bool, bool)> AccessAsync(Guid sendId, string password)
        {
            var send = await _sendRepository.GetByIdAsync(sendId);

            var now = DateTime.UtcNow;

            if (send == null || send.MaxAccessCount.GetValueOrDefault(int.MaxValue) <= send.AccessCount ||
                send.ExpirationDate.GetValueOrDefault(DateTime.MaxValue) < now || send.Disabled ||
                send.DeletionDate < now)
            {
                return(null, false, false);
            }
            if (!string.IsNullOrWhiteSpace(send.Password))
            {
                if (string.IsNullOrWhiteSpace(password))
                {
                    return(null, true, false);
                }
                var passwordResult = _passwordHasher.VerifyHashedPassword(new User(), send.Password, password);
                if (passwordResult == PasswordVerificationResult.SuccessRehashNeeded)
                {
                    send.Password = HashPassword(password);
                }
                if (passwordResult == PasswordVerificationResult.Failed)
                {
                    return(null, false, true);
                }
            }
            // TODO: maybe move this to a simple ++ sproc?
            send.AccessCount++;
            await _sendRepository.ReplaceAsync(send);

            return(send, false, false);
        }
Beispiel #2
0
        // Response: Send, password required, password invalid
        public async Task <(string, bool, bool)> GetSendFileDownloadUrlAsync(Send send, string fileId, string password)
        {
            if (send.Type != SendType.File)
            {
                throw new BadRequestException("Can only get a download URL for a file type of Send");
            }

            var(grantAccess, passwordRequired, passwordInvalid) = SendCanBeAccessed(send, password);

            if (!grantAccess)
            {
                return(null, passwordRequired, passwordInvalid);
            }

            send.AccessCount++;
            await _sendRepository.ReplaceAsync(send);

            return(await _sendFileStorageService.GetSendFileDownloadUrlAsync(send, fileId), false, false);
        }