Added double negation to clean code
This commit is contained in:
parent
eff67b7697
commit
ec5ca51602
@ -26,10 +26,16 @@ namespace EFB.Controllers
|
||||
{
|
||||
//Retrieve and Check current user status
|
||||
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
||||
if(user == null) return RedirectToAction("Index", "Home");
|
||||
if(user == null){
|
||||
TempData["Error"] = "You must be logged in before you are able to view the FlightSim Page";
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
//Retrieve the user's latest sim position and construct it into FlightsimModel
|
||||
if (user.Route == null) return RedirectToAction("Index", "Route");
|
||||
if (user.Route == null){
|
||||
TempData["Error"] = "You must have a route planned before you are able to view the Flightsim page";
|
||||
return RedirectToAction("Index", "Route");
|
||||
}
|
||||
|
||||
SimPositionModel latestPositionModel = await Mongo.GetLatestData(user.EMail);
|
||||
|
||||
|
@ -46,10 +46,16 @@ namespace EFB.Controllers
|
||||
public async Task<IActionResult> New(string departure, string arrival, string cruise)
|
||||
{
|
||||
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
||||
if (!(user == null || user.UserToken.IsExpired()))
|
||||
if (user == null || user.UserToken.IsExpired())
|
||||
{//If the user is still authenticated
|
||||
if (FormAuthenticator.ValidateICAOCode(departure) && FormAuthenticator.ValidateICAOCode(arrival))
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
if (!FormAuthenticator.ValidateICAOCode(departure) || !FormAuthenticator.ValidateICAOCode(arrival))
|
||||
{//If the user has entered valid ICAOs
|
||||
TempData["Error"] = "Invalid Departure or Arrival ICAO";
|
||||
return RedirectToAction("Index", "Route");
|
||||
}
|
||||
|
||||
uint cruiseAlt;
|
||||
|
||||
@ -99,24 +105,23 @@ namespace EFB.Controllers
|
||||
TempData["Departure"] = departure;
|
||||
TempData["Arrival"] = arrival;
|
||||
return RedirectToAction("Index", "Route");
|
||||
|
||||
}
|
||||
TempData["Error"] = "Invalid Departure or Arrival ICAO";
|
||||
return RedirectToAction("Index", "Route");
|
||||
}
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
|
||||
public async Task<IActionResult> Poll(string departure, string arrival, uint cruise)
|
||||
{
|
||||
if (HttpContext.Session.GetString("User") != null)
|
||||
{//If the user is currently logged in
|
||||
if (HttpContext.Session.GetString("User") == null)
|
||||
{//If the user is not currently logged in
|
||||
TempData["Error"] = "Please login before trying to plan a route";
|
||||
return RedirectToAction("Index", "Route");
|
||||
}
|
||||
|
||||
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
||||
|
||||
if (user.RouteToken != null)
|
||||
if (user.RouteToken == null)
|
||||
{//If the user has a route object (e.g, they have been to the route page)
|
||||
|
||||
return RedirectToAction("Index", "Route");
|
||||
}
|
||||
//Make calls to the server to fetch route
|
||||
bool collected = false;
|
||||
int pollCount = 0;
|
||||
@ -185,18 +190,6 @@ namespace EFB.Controllers
|
||||
|
||||
TempData["Error"] = $"Unable to get route after {pollCount} Attempts!";
|
||||
return RedirectToAction("Index", "Route");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return RedirectToAction("Index", "Route");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return RedirectToAction("Index", "Route");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,8 +31,12 @@ namespace EFB.Controllers
|
||||
|
||||
public async Task<IActionResult> Login(string email, string password){
|
||||
|
||||
if (Form.FormAuthenticator.ValidateEMail(email))
|
||||
if (!Form.FormAuthenticator.ValidateEMail(email))
|
||||
{
|
||||
TempData["Error"] = "Please enter a valid E-Mail";
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
//API Helper
|
||||
APIInterface API = new APIInterface();
|
||||
|
||||
@ -55,14 +59,18 @@ namespace EFB.Controllers
|
||||
TempData["Error"] = response.Error;
|
||||
TempData["email"] = email;
|
||||
return RedirectToAction("Index", "Home");
|
||||
}else{
|
||||
|
||||
}
|
||||
//Type cast required but we know response will be of known type
|
||||
LoginResponse login = response.Result;
|
||||
|
||||
//Generate User Session
|
||||
if (login.error == null)
|
||||
if (login.error != null)
|
||||
{
|
||||
TempData["Error"] = login.error_description;
|
||||
TempData["email"] = email;
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
UserModel user = new UserModel{
|
||||
EMail = email,
|
||||
UserToken = new TokenModel{
|
||||
@ -74,19 +82,6 @@ namespace EFB.Controllers
|
||||
//Using Session Extensions (Store the user session)
|
||||
HttpContext.Session.SetObject("User", user);
|
||||
return RedirectToAction("Index", "App");
|
||||
}else{
|
||||
TempData["Error"] = login.error_description;
|
||||
TempData["email"] = email;
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
TempData["Error"] = "Please enter a valid E-Mail";
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user