Force user to be logged in before accessing routes

This commit is contained in:
Luke Else 2022-02-11 20:14:57 +00:00
parent d8a40e64ef
commit a4e7a30a9f

View File

@ -24,6 +24,13 @@ namespace EFB.Controllers
public async Task<IActionResult> Index(string ICAO)
{
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
if (user == null)
{
TempData["Error"] = "Must be logged in to view charts";
return RedirectToAction("Index", "Home");
}
if(ICAO == null)
return View();
@ -34,7 +41,6 @@ namespace EFB.Controllers
{
ChartModel chartModel = new ChartModel(ICAO, charts);
//Save the current chart into user model for later access
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
user.CurrentCharts = chartModel;
HttpContext.Session.SetObject("User", user);
return RedirectToAction("ViewCharts");