public async Task <IActionResult> GetLatest(string cpf) { await Db.Connection.OpenAsync(); var query = new UserPostQuery(Db); var result = await query.LatestPostsAsync(cpf); return(new OkObjectResult(result)); }
public async Task <ActionResult <IEnumerable <TodoUser> > > GetTodoUsers() { await Db.Connection.OpenAsync(); var query = new UserPostQuery(Db); var result = await query.LatestPostsAsync(); JsonConvert.SerializeObject(result); return(new OkObjectResult(result)); }
protected override async Task <AuthenticateResult> HandleAuthenticateAsync() { if (!Request.Headers.ContainsKey("Authorization")) { return(AuthenticateResult.Fail("Authorization header was not found")); } try { var authenticationHeaderValue = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]); var bytes = Convert.FromBase64String(authenticationHeaderValue.Parameter); string[] credentials = Encoding.UTF8.GetString(bytes).Split(":"); string nick = credentials[0]; string password = credentials[1]; await Db.Connection.OpenAsync(); UserPostQuery query = new UserPostQuery(Db); List <TodoUser> users = await query.LatestPostsAsync(); TodoUser user = users.Where(user => user.Nick == nick && user.Password == password).FirstOrDefault(); //TodoUser user = _context.TodoUsers.Where(user => user.Nick == nick && user.Password == password).FirstOrDefault(); if (user == null) { AuthenticateResult.Fail("Invalid nick or password"); } else { var claims = new[] { new Claim(ClaimTypes.Name, user.Nick) }; var identity = new ClaimsIdentity(claims, Scheme.Name); var principal = new ClaimsPrincipal(identity); var ticket = new AuthenticationTicket(principal, Scheme.Name); return(AuthenticateResult.Success(ticket)); } } catch (Exception e) { e.Message.ToString(); return(AuthenticateResult.Fail("Error has occurred")); } return(AuthenticateResult.Fail("")); }
public async Task <ActionResult <TodoUser> > GetTodoUserAuth() { String nick = HttpContext.User.Identity.Name; await Db.Connection.OpenAsync(); var query = new UserPostQuery(Db); List <TodoUser> users = await query.LatestPostsAsync(); TodoUser user = users.Where(user => user.Nick == nick).FirstOrDefault(); if (user == null) { return(NotFound()); } return(new OkObjectResult(user)); }