public async Task <IActionResult> fllws([FromBody] followModel follow, string username)
        {
            //TODO maybe auth
            //If user not logged in
            if (!CookieHandler.LoggedIn(Request) &&
                !(Request.Headers.TryGetValue("Authorization", out var header) && header.Equals(AuthorizationConstants.terribleHackAuth)))
            {
                return(Unauthorized());
            }

            // TODO: Figure out this mess :)
            if (string.IsNullOrEmpty(follow.follow))
            {
                _logger.LogInformation($"User {username} Unfollow user {follow.unfollow}");
                if (!_userRepository.UnfollowUser(username, follow.unfollow))
                {
                    return(NoContent());
                }
            }
            else if (string.IsNullOrEmpty(follow.unfollow))
            {
                _logger.LogInformation($"User {username} follow user {follow.follow}");
                if (!_userRepository.FollowUser(username, follow.follow))
                {
                    return(NotFound());
                }
            }
            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> fllws([FromBody] followModel follow, string username)
        {
            //TODO maybe auth
            //If user not logged in
            //if (!CookieHandler.LoggedIn(Request) || !Guid.TryParse(Request.Cookies["userId"].ToString(), out var UserId))
            //    return Unauthorized();

            if (string.IsNullOrEmpty(follow.follow))
            {
                if (!_userRepository.UnfollowUser(username, follow.unfollow))
                {
                    return(NoContent());
                }
            }
            else if (string.IsNullOrEmpty(follow.unfollow))
            {
                if (!_userRepository.FollowUser(username, follow.follow))
                {
                    return(NotFound());
                }
            }
            return(NoContent());
        }