public async Task <IActionResult> Register([FromBody] RegisterModel model) { if (!ModelState.IsValid) { return(Unauthorized()); } if (CookieHandler.LoggedIn(Request) && Guid.TryParse(Request.Cookies["userId"].ToString(), out var UserId)) { return(RedirectToAction("Root", "Timeline")); } try { var res = _userRepository.RegisterUser(model); var options = new CookieOptions(); options.Expires = DateTime.UtcNow.AddSeconds(60); HttpContext.Response.Cookies.Append("user", model.username, options); HttpContext.Response.Cookies.Append("userId", res.ToString(), options); //return RedirectToAction("Root", "Timeline"); } catch (Exception e) { } return(NoContent()); }
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()); }
public async Task <IActionResult> AddMessage([FromBody] MessageCreate msg, string username) { //Create a new message from logged in user //TODO if user not logged in if (!CookieHandler.LoggedIn(Request) && !(Request.Headers.TryGetValue("Authorization", out var header) && header.Equals(AuthorizationConstants.terribleHackAuth))) { return(Unauthorized()); } switch (Request.Method) { case "POST": _logger.LogInformation($"User: {username} posted msg: {msg.content}"); _timelineRepository.PostMessage(username, msg.content); return(NoContent()); case "GET": _logger.LogInformation($"GET request to msgs/{username} - This end point should not be called... Typically?"); _timelineRepository.GetUserTimeline(username); return(NoContent()); } return(NoContent()); }
public async Task <IActionResult> Login(LoginModel model) { if (CookieHandler.LoggedIn(Request) && Guid.TryParse(Request.Cookies["userId"].ToString(), out var UserId)) { return(RedirectToAction("Root", "Timeline")); } if (!ModelState.IsValid) { return(Unauthorized()); } var res = _userRepository.Login(model); if (!res.Equals(Guid.Empty)) { var options = new CookieOptions(); options.Expires = DateTime.UtcNow.AddSeconds(60); HttpContext.Response.Cookies.Append("user", model.Username, options); HttpContext.Response.Cookies.Append("userId", res.ToString(), options); return(RedirectToAction("Root", "Timeline")); } return(NoContent()); }