public IActionResult Login(User user) { var repository = new JokesRepository(_conn); User u = repository.GetUserByEmail(user.Email); if (u == null) { return(Redirect("/account/login")); } else if (!repository.Match(user.Password, u.Password)) { return(Redirect("/account/login")); } var claims = new List <Claim> { new Claim("user", user.Email) }; HttpContext.SignInAsync(new ClaimsPrincipal( new ClaimsIdentity(claims, "Cookies", "user", "role"))).Wait(); return(Redirect("/home/index")); }
public IActionResult Index() { if (User.Identity.IsAuthenticated) { var repo = new JokesRepository(_conn); User user = repo.GetUserByEmail(User.Identity.Name); Joke joke = repo.GenerateRandomJoke(); var vm = new RandomJokeViewModel { Joke = joke, User = user, Liked = repo.DidUserLike(user.Id, joke.Id), Disliked = repo.DidUserDislike(user.Id, joke.Id) }; return(View(vm)); } else { return(Redirect("/account/login")); } }