void IBannedImageLogger.Log(ModelStateEntry modelStateEntry, IPAddress ip, IIpHash ipHash) { if (modelStateEntry != null) { var hasBannedImage = modelStateEntry.Errors.Select(a => a.ErrorMessage).Contains(ValidateImage.BannedImageString); if (hasBannedImage) { this.logger.LogInformation($"User ip:{ip.ToString()} hash:{ipHash.Val} attempted to upload banned image."); } } }
async Task <OneOf <Success, Banned> > IPostService.AddThread(Guid postId, Guid threadId, Guid boardId, string subject, TripCodedName name, string comment, bool isSage, IIpHash ipAddress, Option <File> file, CancellationToken cancellationToken) { if (await this.bannedIpRepository.IsBanned(ipAddress, cancellationToken)) { return(new Banned()); } var thread = new Thread(threadId, boardId, subject); await threadRepository.Add(thread).ConfigureAwait(false); var post = new Domain.Post(postId, threadId, DateTime.UtcNow, name.Val, comment, isSage, ipAddress.Val); await this.postRepository.Add(post).ConfigureAwait(false); await file.MapToTask(some => this.fileRepository.Add(some)); return(new Success()); }
async Task <OneOf <Success, Banned, ImageCountExceeded, PostCountExceeded> > IPostService.Add(Guid postId, Guid threadId, TripCodedName name, string comment, bool isSage, IIpHash ipAddress, Option <File> file, CancellationToken cancellationToken) { if (await this.bannedIpRepository.IsBanned(ipAddress, cancellationToken)) { return(new Banned()); } if (ImageLimit <= await this.fileRepository.GetImageCount(threadId, cancellationToken)) { return(new ImageCountExceeded()); } if (PostLimit <= await this.postRepository.GetThreadPostCount(threadId, cancellationToken)) { return(new PostCountExceeded()); } var post = new Domain.Post(postId, threadId, DateTime.UtcNow, name.Val, comment, isSage, ipAddress.Val); await this.postRepository.Add(post).ConfigureAwait(false); await file.MapToTask(some => this.fileRepository.Add(some)); return(new Success()); }
Task <bool> IBannedIpRepository.IsBanned(IIpHash hash, CancellationToken cancellationToken) { return(this.client.BannedIps.AnyAsync(a => a.IpHash == hash.Val, cancellationToken)); }
async Task <Option <DateTime> > IBannedIpRepository.GetByHash(IIpHash hash, CancellationToken cancellationToken) { var ban = await this.client.BannedIps.SingleOrNone(a => a.IpHash == hash.Val, cancellationToken); return(ban.Map(b => b.Expiry)); }
Task IBannedIpRepository.Ban(IIpHash hash, string reason, DateTime expiry) { this.client.BannedIps.Add(new BannedIp(Guid.NewGuid(), hash.Val, reason, expiry)); return(this.client.SaveChangesAsync()); }
Task <Option <DateTime> > IUserService.GetExpiry(IIpHash hash, CancellationToken cancellationToken) { return(this.bannedIpRepository.GetByHash(hash, cancellationToken)); }
Task IUserService.BanUser(IIpHash hash, string reason, DateTime expiry) { return(this.bannedIpRepository.Ban(hash, reason, expiry)); }