Updates to App and route Controller
This commit is contained in:
46
Controllers/AppController.cs
Normal file
46
Controllers/AppController.cs
Normal 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!");
|
||||
}
|
||||
}
|
||||
}
|
41
Controllers/RouteController.cs
Normal file
41
Controllers/RouteController.cs
Normal 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!");
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
Reference in New Issue
Block a user