Merge pull request #6 from Flight-Simulator-EFB/features/route

Features/route
This commit is contained in:
Luke Else 2021-11-21 21:24:55 +00:00 committed by GitHub
commit 4d2c488ac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) //Using Session Extensions (Store the user session)
HttpContext.Session.SetObject("User", user); HttpContext.Session.SetObject("User", user);
return RedirectToAction("App", "Home"); return RedirectToAction("Index", "App");
}else{ }else{
TempData["Error"] = login.error_description; TempData["Error"] = login.error_description;
TempData["email"] = email; TempData["email"] = email;

46
Views/Route/Index.cshtml Normal file
View File

@ -0,0 +1,46 @@
@{
ViewData["Title"] = "Route Info";
}
<div class="row">
<div class="card-body col-md-6">
<div class="container jumbotron">
<h3>Route Info</h3>
<br />
<br />
<form asp-controller="Route" asp-action="New">
<div class="form-group">
<input type="text" class="form-control" placeholder="Departure" name="Departure" value="@TempData["Departure"]">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Arrival" name="Arrival" value="@TempData["Arrival"]">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Cruise" name="Cruise" value="@TempData["Cruise"]">
</div>
<button type="submit" class="btn btn-secondary">Get Route</button>
@{
if (TempData["Error"] != null)
{//If an error has been flagged, information will be displayed to the user
<br />
<br />
<div class="alert alert-danger">
<strong>Warning!</strong> @TempData["Error"] <button type='button' class='close' data-dismiss='alert' aria-hidden='true' />&times;
</div>
}
}
</form>
</div>
</div>
<div class="card-body mh-100 bg-warning col-md-6">
<img src="/images/RouteImage.png" width="100%" height="100%" style="object-fit: cover;">
</div>
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB