示例#1
0
        public IActionResult Get(string uuid)
        {
            var user = _authHandler.UserFromClaimsPrincipal(User);

            if (!SecureGuid.VerifyGuid(uuid, out var postGuid))
            {
                _logger.LogInformation("Post UUID is invalid.");
                _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                       $", IP: {HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP"}");
                _authHandler.TerminateSession(user);

                return(BadRequest());
            }


            var postInfo = _database.GetPostInfo(postGuid);

            if (postInfo == null)
            {
                _logger.LogInformation("Post does not exist.");
                _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                       $", IP: {HttpContext?.Connection.RemoteIpAddress.ToString() ?? "Unknown IP"}");
                _authHandler.TerminateSession(user);

                return(BadRequest());
            }

            var comments = _database.GetCommentsByPost(postGuid);

            postInfo.Comments = comments;

            return(Ok(postInfo));
        }
        public IActionResult NewComment([FromBody] Comment comment)
        {
            var user = _authHandler.UserFromClaimsPrincipal(User);

            if (string.IsNullOrWhiteSpace(comment.Content) || string.IsNullOrWhiteSpace(comment.Post) ||
                string.IsNullOrWhiteSpace(comment.Captcha))
            {
                _logger.LogInformation("Comment content, post or captcha is missing.");
                _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                       $", IP: {HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP"}");
                _authHandler.TerminateSession(user);

                return(BadRequest());
            }

            if (!_captcha.VerifyCaptcha(comment.Captcha, HttpContext.Connection.RemoteIpAddress, "newComment"))
            {
                _logger.LogInformation("Captcha failed verification.");
                _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                       $", IP: {HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP"}");
                _authHandler.TerminateSession(user);

                return(BadRequest());
            }


            if (comment.Content.Length > 128)
            {
                _logger.LogInformation("Comment content length exceeds the permitted limit.");
                _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                       $", IP: {HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP"}");
                _authHandler.TerminateSession(user);

                return(BadRequest());
            }

            if (!SecureGuid.VerifyGuid(comment.Post, out _))
            {
                _logger.LogInformation("Post UUID is invalid.");
                _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                       $", IP: {HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP"}");
                _authHandler.TerminateSession(user);

                return(BadRequest());
            }


            if (_database.CreateComment(comment, user))
            {
                _activityLogger.LogNewComment(Request.HttpContext.Connection.RemoteIpAddress, user, comment);
                return(Ok());
            }

            _logger.LogInformation("Database failed to create new comment.");
            _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                   $", IP: {HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP"}");
            _authHandler.TerminateSession(user);

            return(BadRequest());
        }
示例#3
0
        public IActionResult ChangePasswordCheck(User userInput)
        {
            var user = _authHandler.UserFromClaimsPrincipal(User);

            if (string.IsNullOrWhiteSpace(userInput.Password))
            {
                _logger.LogInformation("Password is null or empty");
                _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                       $", IP: {HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP"}");
                _authHandler.TerminateSession(user);
            }

            return(Ok(new { status = _authHandler.VerifyPassword(userInput.Password) }));
        }
示例#4
0
        public IActionResult Get(string uuid)
        {
            var user = _authHandler.UserFromClaimsPrincipal(User);

            if (!SecureGuid.VerifyGuid(uuid, out _))
            {
                _logger.LogInformation("Invalid Topic UUID");
                _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                       $", IP: {HttpContext?.Connection.RemoteIpAddress.ToString() ?? "Unknown IP"}");
                _authHandler.TerminateSession(user);

                return(BadRequest());
            }

            var topicInfo = _database.GetTopics(uuid);

            if (topicInfo.Count != 1)
            {
                _logger.LogInformation("Topic UUID does nto exist");
                _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                       $", IP: {HttpContext?.Connection.RemoteIpAddress.ToString() ?? "Unknown IP"}");
                _authHandler.TerminateSession(user);
            }

            var posts = _database.GetPostByTopic(new Guid(uuid));

            topicInfo[0].Posts = posts;
            return(Ok(topicInfo[0]));
        }
        public IActionResult Get(string search)
        {
            var user = _authHandler.UserFromClaimsPrincipal(User);

            if (Request.Headers.TryGetValue("Captcha", out var captchaValue))
            {
                if (!_captcha.VerifyCaptcha(captchaValue, HttpContext.Connection.RemoteIpAddress, "search"))
                {
                    _logger.LogInformation("Captcha verification failed.");
                    _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                           $", IP: {HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP"}");
                    _authHandler.TerminateSession(user);
                    return(BadRequest());
                }
            }
            else
            {
                _logger.LogInformation("Captcha header not provided.");
                _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                       $", IP: {HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP"}");
                _authHandler.TerminateSession(user);
                return(BadRequest());
            }

            if (string.IsNullOrWhiteSpace(search) || search.Length < 5)
            {
                _logger.LogInformation("Search input is empty or is less than 5 char.");
                _logger.LogInformation($"Terminating session. User: {user.Uuid}" +
                                       $", IP: {HttpContext?.Connection?.RemoteIpAddress?.ToString() ?? "Unknown IP"}");
                _authHandler.TerminateSession(user);
                return(BadRequest());
            }

            return(Ok(_database.SearchPost(search)));
        }