Updates to App and route Controller

This commit is contained in:
luke-else
2021-11-15 07:44:18 +00:00
parent 5845229628
commit 08c2e9c07b
5 changed files with 134 additions and 1 deletions

View File

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using EFB.Models;
using Microsoft.AspNetCore.Http;
using EFB.Sessions;
namespace EFB.Controllers
{
public class AppController : Controller
{
private readonly ILogger<AppController> _logger;
public AppController(ILogger<AppController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
//Check to see what point on the application the user is at and where they should be sent
UserModel User = HttpContext.Session.GetObject<UserModel>("User");
if (User != null)
{
if (User.Route == null)
{
return RedirectToAction("Index", "Route");
}else{
return RedirectToAction("Index", "App");
}
}else{
return RedirectToAction("Index", "Home");
}
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View("Error!");
}
}
}

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Http;
using EFB.Models;
using EFB.Sessions;
namespace EFB.Controllers
{
public class RouteController : Controller
{
private readonly ILogger<RouteController> _logger;
public RouteController(ILogger<RouteController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
//Check the user has a valid login
UserModel User = HttpContext.Session.GetObject<UserModel>("User");
if (User == null || User.Route != null || User.Token.IsExpired())
{
return RedirectToAction("Index", "Home");
}
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View("Error!");
}
}
}

View File

@ -72,7 +72,7 @@ namespace EFB.Controllers
//Using Session Extensions (Store the user session)
HttpContext.Session.SetObject("User", user);
return RedirectToAction("App", "Home");
return RedirectToAction("Index", "App");
}else{
TempData["Error"] = login.error_description;
TempData["email"] = email;