Exemplo n.º 1
0
 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.");
         }
     }
 }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
 Task <bool> IBannedIpRepository.IsBanned(IIpHash hash, CancellationToken cancellationToken)
 {
     return(this.client.BannedIps.AnyAsync(a => a.IpHash == hash.Val, cancellationToken));
 }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
 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());
 }
Exemplo n.º 7
0
 Task <Option <DateTime> > IUserService.GetExpiry(IIpHash hash, CancellationToken cancellationToken)
 {
     return(this.bannedIpRepository.GetByHash(hash, cancellationToken));
 }
Exemplo n.º 8
0
 Task IUserService.BanUser(IIpHash hash, string reason, DateTime expiry)
 {
     return(this.bannedIpRepository.Ban(hash, reason, expiry));
 }