Compare commits
4 Commits
main
...
developmen
Author | SHA1 | Date | |
---|---|---|---|
ed6e80fab3 | |||
27bf158a7a | |||
72124e7f15 | |||
b1e8bfe8d0 |
@ -1,10 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Net.Http;
|
|
||||||
using EFB.Models;
|
using EFB.Models;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace EFB.Controllers.API
|
namespace EFB.Controllers.API
|
||||||
{
|
{
|
||||||
@ -12,10 +10,10 @@ namespace EFB.Controllers.API
|
|||||||
{
|
{
|
||||||
private HttpClient HttpClient { get; set; }
|
private HttpClient HttpClient { get; set; }
|
||||||
|
|
||||||
public async Task<ResponseModel<T>> Get<T>(string Endpoint, Dictionary<string, string> Headers){
|
public async Task<ResponseModel<T>> Get<T>(string Endpoint, Dictionary<string, string> Headers)
|
||||||
|
{
|
||||||
|
//Create the HTTP client used for the GetRequest.
|
||||||
this.HttpClient = new HttpClient();
|
this.HttpClient = new HttpClient();
|
||||||
|
|
||||||
this.HttpClient.DefaultRequestHeaders.Clear();
|
this.HttpClient.DefaultRequestHeaders.Clear();
|
||||||
|
|
||||||
if (Headers != null)
|
if (Headers != null)
|
||||||
@ -30,10 +28,9 @@ namespace EFB.Controllers.API
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
//Get the response from the server
|
||||||
var pendingResult = this.HttpClient.GetAsync(Endpoint);
|
var pendingResult = this.HttpClient.GetAsync(Endpoint);
|
||||||
|
|
||||||
var result = await pendingResult;
|
var result = await pendingResult;
|
||||||
|
|
||||||
string resultString = result.Content.ReadAsStringAsync().Result;
|
string resultString = result.Content.ReadAsStringAsync().Result;
|
||||||
|
|
||||||
//Assess return value (object or raw string)
|
//Assess return value (object or raw string)
|
||||||
@ -43,8 +40,8 @@ namespace EFB.Controllers.API
|
|||||||
{//If the user requests string for return type
|
{//If the user requests string for return type
|
||||||
response = JsonConvert.DeserializeObject<T>(resultString);
|
response = JsonConvert.DeserializeObject<T>(resultString);
|
||||||
}
|
}
|
||||||
|
return new ResponseModel<T>()
|
||||||
return new ResponseModel<T>(){
|
{
|
||||||
//Sender should be aware of type T becuase of Generic type
|
//Sender should be aware of type T becuase of Generic type
|
||||||
Result = (T)response
|
Result = (T)response
|
||||||
};
|
};
|
||||||
@ -53,20 +50,19 @@ namespace EFB.Controllers.API
|
|||||||
{
|
{
|
||||||
return new ResponseModel<T> { Error = e.Message };
|
return new ResponseModel<T> { Error = e.Message };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//Returned in the event No other response has been returned
|
//Returned in the event No other response has been returned
|
||||||
return new ResponseModel<T> { Error = "Invalid Endpoint - Please try again later" };
|
return new ResponseModel<T> { Error = "Invalid Endpoint - Please try again later" };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ResponseModel<T>> Post<T>(string Endpoint, Dictionary<string, string> Headers, HttpContent Body){
|
public async Task<ResponseModel<T>> Post<T>(string Endpoint, Dictionary<string, string> Headers, HttpContent Body)
|
||||||
|
{
|
||||||
|
//Create a HTTP client to allow for making Post requests
|
||||||
this.HttpClient = new HttpClient();
|
this.HttpClient = new HttpClient();
|
||||||
this.HttpClient.DefaultRequestHeaders.Clear();
|
this.HttpClient.DefaultRequestHeaders.Clear();
|
||||||
|
|
||||||
if (Headers != null)
|
if (Headers != null)
|
||||||
{
|
{//Go through and add each header to the HTTP Client
|
||||||
foreach (var Header in Headers)
|
foreach (var Header in Headers)
|
||||||
{
|
{
|
||||||
this.HttpClient.DefaultRequestHeaders.Add(Header.Key, Header.Value);
|
this.HttpClient.DefaultRequestHeaders.Add(Header.Key, Header.Value);
|
||||||
@ -75,11 +71,11 @@ namespace EFB.Controllers.API
|
|||||||
|
|
||||||
if (Form.FormAuthenticator.ValidateEndpoint(Endpoint))
|
if (Form.FormAuthenticator.ValidateEndpoint(Endpoint))
|
||||||
{
|
{
|
||||||
try{//Try statement to catch errors in the process of making the request
|
try
|
||||||
|
{//Try statement to catch errors in the process of making the request
|
||||||
var pendingResult = this.HttpClient.PostAsync(Endpoint, Body);
|
var pendingResult = this.HttpClient.PostAsync(Endpoint, Body);
|
||||||
var result = await pendingResult;
|
var result = await pendingResult;
|
||||||
string resultString = result.Content.ReadAsStringAsync().Result;
|
string resultString = result.Content.ReadAsStringAsync().Result;
|
||||||
|
|
||||||
object response = resultString;
|
object response = resultString;
|
||||||
|
|
||||||
if (typeof(T) != typeof(string))
|
if (typeof(T) != typeof(string))
|
||||||
@ -87,28 +83,28 @@ namespace EFB.Controllers.API
|
|||||||
response = JsonConvert.DeserializeObject<T>(resultString);
|
response = JsonConvert.DeserializeObject<T>(resultString);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResponseModel<T>(){
|
return new ResponseModel<T>()
|
||||||
|
{
|
||||||
//Sender should be aware of type T becuase of Generic type
|
//Sender should be aware of type T becuase of Generic type
|
||||||
Result = (T)response
|
Result = (T)response
|
||||||
};
|
};
|
||||||
}catch(System.Exception e){
|
}
|
||||||
|
catch (System.Exception e)
|
||||||
|
{
|
||||||
return new ResponseModel<T> { Error = e.Message };
|
return new ResponseModel<T> { Error = e.Message };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Returned in the event No other response has been returned
|
//Returned in the event No other response has been returned
|
||||||
return new ResponseModel<T> { Error = "Invalid Endpoint - Please try again later" };
|
return new ResponseModel<T> { Error = "Invalid Endpoint - Please try again later" };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public async Task<ResponseModel<T>> Put<T>(string Endpoint, Dictionary<string, string> Headers, HttpContent Body)
|
||||||
|
{
|
||||||
|
//Create HTTP client to allow for HttpRequests
|
||||||
public async Task<ResponseModel<T>> Put<T>(string Endpoint, Dictionary<string, string> Headers, HttpContent Body){
|
|
||||||
|
|
||||||
this.HttpClient = new HttpClient();
|
this.HttpClient = new HttpClient();
|
||||||
this.HttpClient.DefaultRequestHeaders.Clear();
|
this.HttpClient.DefaultRequestHeaders.Clear();
|
||||||
|
|
||||||
if (Headers != null)
|
if (Headers != null)
|
||||||
{
|
{//Loop through and add each heder to the HTTP client
|
||||||
foreach (var Header in Headers)
|
foreach (var Header in Headers)
|
||||||
{
|
{
|
||||||
this.HttpClient.DefaultRequestHeaders.Add(Header.Key, Header.Value);
|
this.HttpClient.DefaultRequestHeaders.Add(Header.Key, Header.Value);
|
||||||
@ -117,11 +113,13 @@ namespace EFB.Controllers.API
|
|||||||
|
|
||||||
if (Form.FormAuthenticator.ValidateEndpoint(Endpoint))
|
if (Form.FormAuthenticator.ValidateEndpoint(Endpoint))
|
||||||
{
|
{
|
||||||
try{//Try statement to catch errors in the process of making the request
|
try
|
||||||
|
{//Try statement to catch errors in the process of making the request
|
||||||
var pendingResult = this.HttpClient.PutAsync(Endpoint, Body);
|
var pendingResult = this.HttpClient.PutAsync(Endpoint, Body);
|
||||||
var result = await pendingResult;
|
var result = await pendingResult;
|
||||||
string resultString = result.Content.ReadAsStringAsync().Result;
|
string resultString = result.Content.ReadAsStringAsync().Result;
|
||||||
|
|
||||||
|
//Recieve the response as a string which will be morphed in other types
|
||||||
object response = resultString;
|
object response = resultString;
|
||||||
|
|
||||||
if (typeof(T) != typeof(string))
|
if (typeof(T) != typeof(string))
|
||||||
@ -129,20 +127,21 @@ namespace EFB.Controllers.API
|
|||||||
response = JsonConvert.DeserializeObject<T>(resultString);
|
response = JsonConvert.DeserializeObject<T>(resultString);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResponseModel<T>(){
|
return new ResponseModel<T>()
|
||||||
|
{
|
||||||
//Sender should be aware of type T becuase of Generic type
|
//Sender should be aware of type T becuase of Generic type
|
||||||
Result = (T)response
|
Result = (T)response
|
||||||
};
|
};
|
||||||
}catch(System.Exception e){
|
}
|
||||||
|
catch (System.Exception e)
|
||||||
|
{
|
||||||
return new ResponseModel<T> { Error = e.Message };
|
return new ResponseModel<T> { Error = e.Message };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Returned in the event No other response has been returned
|
//Returned in the event No other response has been returned
|
||||||
return new ResponseModel<T> { Error = "Invalid Endpoint - Please try again later" };
|
return new ResponseModel<T> { Error = "Invalid Endpoint - Please try again later" };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,13 +1,8 @@
|
|||||||
using System;
|
using EFB.Models;
|
||||||
using System.Collections.Generic;
|
using EFB.Sessions;
|
||||||
using System.Diagnostics;
|
using Microsoft.AspNetCore.Http;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using EFB.Models;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using EFB.Sessions;
|
|
||||||
|
|
||||||
namespace EFB.Controllers
|
namespace EFB.Controllers
|
||||||
{
|
{
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
using System;
|
using EFB.Controllers.Form;
|
||||||
using System.Collections.Generic;
|
using EFB.Models;
|
||||||
using System.Diagnostics;
|
using EFB.Sessions;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using EFB.Models;
|
using System.Threading.Tasks;
|
||||||
using EFB.Models.JSON;
|
|
||||||
using EFB.Controllers.Form;
|
|
||||||
using EFB.Sessions;
|
|
||||||
|
|
||||||
namespace EFB.Controllers
|
namespace EFB.Controllers
|
||||||
{
|
{
|
||||||
@ -45,14 +40,16 @@ namespace EFB.Controllers
|
|||||||
HttpContext.Session.SetObject("User", user);
|
HttpContext.Session.SetObject("User", user);
|
||||||
return RedirectToAction("ViewCharts");
|
return RedirectToAction("ViewCharts");
|
||||||
}
|
}
|
||||||
}else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
TempData["Error"] = "Invalid ICAO";
|
TempData["Error"] = "Invalid ICAO";
|
||||||
}
|
}
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult ViewCharts(string chart){
|
public IActionResult ViewCharts(string chart)
|
||||||
|
{
|
||||||
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
||||||
if (user != null)
|
if (user != null)
|
||||||
{
|
{
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using EFB.Sessions;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using EFB.Models;
|
using EFB.Models;
|
||||||
using EFB.MongoData;
|
|
||||||
using EFB.Models.Route;
|
using EFB.Models.Route;
|
||||||
|
using EFB.MongoData;
|
||||||
|
using EFB.Sessions;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace EFB.Controllers
|
namespace EFB.Controllers
|
||||||
{
|
{
|
||||||
@ -26,13 +23,15 @@ namespace EFB.Controllers
|
|||||||
{
|
{
|
||||||
//Retrieve and Check current user status
|
//Retrieve and Check current user status
|
||||||
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
||||||
if(user == null){
|
if (user == null)
|
||||||
|
{
|
||||||
TempData["Error"] = "You must be logged in before you are able to view the FlightSim Page";
|
TempData["Error"] = "You must be logged in before you are able to view the FlightSim Page";
|
||||||
return RedirectToAction("Index", "Home");
|
return RedirectToAction("Index", "Home");
|
||||||
}
|
}
|
||||||
|
|
||||||
//Retrieve the user's latest sim position and construct it into FlightsimModel
|
//Retrieve the user's latest sim position and construct it into FlightsimModel
|
||||||
if (user.Route == null){
|
if (user.Route == null)
|
||||||
|
{
|
||||||
TempData["Error"] = "You must have a route planned before you are able to view the Flightsim page";
|
TempData["Error"] = "You must have a route planned before you are able to view the Flightsim page";
|
||||||
return RedirectToAction("Index", "Route");
|
return RedirectToAction("Index", "Route");
|
||||||
}
|
}
|
||||||
@ -46,7 +45,8 @@ namespace EFB.Controllers
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private IWaypoint DetermineClosest(RouteModel route, SimPosition currentPosition){
|
private IWaypoint DetermineClosest(RouteModel route, SimPosition currentPosition)
|
||||||
|
{
|
||||||
IWaypoint closest = null;
|
IWaypoint closest = null;
|
||||||
float closestDistance = float.MaxValue;
|
float closestDistance = float.MaxValue;
|
||||||
//Assuming that we are on the earth for simplicity
|
//Assuming that we are on the earth for simplicity
|
||||||
@ -74,7 +74,8 @@ namespace EFB.Controllers
|
|||||||
}
|
}
|
||||||
return closest;
|
return closest;
|
||||||
}
|
}
|
||||||
private float DegreesToRadians(float degrees){
|
private float DegreesToRadians(float degrees)
|
||||||
|
{
|
||||||
return (float)(degrees * Math.PI / 180);
|
return (float)(degrees * Math.PI / 180);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace EFB.Controllers.Form
|
namespace EFB.Controllers.Form
|
||||||
{
|
{
|
||||||
public static class FormAuthenticator
|
public static class FormAuthenticator
|
||||||
{
|
{
|
||||||
|
|
||||||
public static bool ValidateEMail(string EMail){
|
public static bool ValidateEMail(string EMail)
|
||||||
|
{
|
||||||
if (EMail != null && EMail.Contains("@") && EMail.Contains(".") && !EMail.Contains(" "))
|
if (EMail != null && EMail.Contains("@") && EMail.Contains(".") && !EMail.Contains(" "))
|
||||||
{
|
{
|
||||||
if (EMail.Count(x => x == '@') == 1)
|
if (EMail.Count(x => x == '@') == 1)
|
||||||
@ -19,7 +17,8 @@ namespace EFB.Controllers.Form
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ValidateEndpoint(string Endpoint){
|
public static bool ValidateEndpoint(string Endpoint)
|
||||||
|
{
|
||||||
//If it contains http & :// it can be either https or http
|
//If it contains http & :// it can be either https or http
|
||||||
if (Endpoint.Contains("http") && Endpoint.Contains("://") && Endpoint.Length > 7)
|
if (Endpoint.Contains("http") && Endpoint.Contains("://") && Endpoint.Length > 7)
|
||||||
{
|
{
|
||||||
@ -28,7 +27,8 @@ namespace EFB.Controllers.Form
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ValidateICAOCode(string ICAO){
|
public static bool ValidateICAOCode(string ICAO)
|
||||||
|
{
|
||||||
if (ICAO.Length == 4)
|
if (ICAO.Length == 4)
|
||||||
{
|
{
|
||||||
//If the value contains a Number, then the value will return false
|
//If the value contains a Number, then the value will return false
|
||||||
@ -37,7 +37,8 @@ namespace EFB.Controllers.Form
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ValidateCruiseAlt(uint CruiseAlt){
|
public static bool ValidateCruiseAlt(uint CruiseAlt)
|
||||||
|
{
|
||||||
if (CruiseAlt > 0 && CruiseAlt < 50000)
|
if (CruiseAlt > 0 && CruiseAlt < 50000)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
using EFB.Models;
|
using EFB.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using Microsoft.AspNetCore.Http;
|
||||||
using System.Threading.Tasks;
|
using EFB.Sessions;
|
||||||
|
|
||||||
namespace EFB.Controllers
|
namespace EFB.Controllers
|
||||||
{
|
{
|
||||||
@ -20,6 +18,10 @@ namespace EFB.Controllers
|
|||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
|
//Ensure that the user is not already logged in
|
||||||
|
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
||||||
|
if (user != null) return RedirectToAction("Index", "App");
|
||||||
|
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
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 EFB.Models;
|
||||||
using EFB.Sessions;
|
using EFB.Sessions;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace EFB.Controllers
|
namespace EFB.Controllers
|
||||||
{
|
{
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
using System;
|
using EFB.Controllers.API;
|
||||||
using System.Threading.Tasks;
|
using EFB.Controllers.Form;
|
||||||
using System.Threading;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Net.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using EFB.Models;
|
using EFB.Models;
|
||||||
using EFB.Models.JSON;
|
using EFB.Models.JSON;
|
||||||
using EFB.Sessions;
|
using EFB.Sessions;
|
||||||
using EFB.Controllers.Form;
|
using Microsoft.AspNetCore.Http;
|
||||||
using EFB.Controllers.API;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace EFB.Controllers
|
namespace EFB.Controllers
|
||||||
{
|
{
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
|
using EFB.Controllers.API;
|
||||||
|
using EFB.Models;
|
||||||
|
using EFB.Models.JSON;
|
||||||
|
using EFB.Sessions;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using EFB.Models.JSON;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using EFB.Models;
|
|
||||||
using EFB.Sessions;
|
|
||||||
using EFB.Controllers.API;
|
|
||||||
|
|
||||||
namespace EFB.Controllers
|
namespace EFB.Controllers
|
||||||
{
|
{
|
||||||
@ -28,8 +26,11 @@ namespace EFB.Controllers
|
|||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> Login(string email, string password)
|
||||||
public async Task<IActionResult> Login(string email, string password){
|
{
|
||||||
|
//Ensure that the user is not already logged in
|
||||||
|
UserModel user = HttpContext.Session.GetObject<UserModel>("User");
|
||||||
|
if (user != null) return RedirectToAction("Index", "App");
|
||||||
|
|
||||||
if (!Form.FormAuthenticator.ValidateEMail(email))
|
if (!Form.FormAuthenticator.ValidateEMail(email))
|
||||||
{
|
{
|
||||||
@ -71,9 +72,11 @@ namespace EFB.Controllers
|
|||||||
return RedirectToAction("Index", "Home");
|
return RedirectToAction("Index", "Home");
|
||||||
}
|
}
|
||||||
|
|
||||||
UserModel user = new UserModel{
|
user = new UserModel
|
||||||
|
{
|
||||||
EMail = email,
|
EMail = email,
|
||||||
UserToken = new TokenModel{
|
UserToken = new TokenModel
|
||||||
|
{
|
||||||
TokenValue = login.access_token,
|
TokenValue = login.access_token,
|
||||||
Expiration = DateTime.UtcNow.AddSeconds(login.expires_in)
|
Expiration = DateTime.UtcNow.AddSeconds(login.expires_in)
|
||||||
}
|
}
|
||||||
@ -82,10 +85,10 @@ 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("Index", "App");
|
return RedirectToAction("Index", "App");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Logout(){
|
public IActionResult Logout()
|
||||||
|
{
|
||||||
HttpContext.Session.SetObject("User", null);
|
HttpContext.Session.SetObject("User", null);
|
||||||
return RedirectToAction("Index", "Home");
|
return RedirectToAction("Index", "Home");
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using libmetar.Services;
|
using libmetar.Services;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace EFB.Metar
|
namespace EFB.Metar
|
||||||
{
|
{
|
||||||
@ -12,11 +10,13 @@ namespace EFB.Metar
|
|||||||
private static TafService tafService { get; set; } = new TafService();
|
private static TafService tafService { get; set; } = new TafService();
|
||||||
|
|
||||||
|
|
||||||
public static async Task<string> GetMETAR(string ICAO){
|
public static async Task<string> GetMETAR(string ICAO)
|
||||||
|
{
|
||||||
return (await metarService.GetRawAsync(ICAO)).Raw;
|
return (await metarService.GetRawAsync(ICAO)).Raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<List<string>> GetTAF(string ICAO){
|
public static async Task<List<string>> GetTAF(string ICAO)
|
||||||
|
{
|
||||||
var downloadedTAF = (await tafService.GetRawAsync(ICAO)).RawSplit;
|
var downloadedTAF = (await tafService.GetRawAsync(ICAO)).RawSplit;
|
||||||
List<string> TAF = new List<string>();
|
List<string> TAF = new List<string>();
|
||||||
|
|
||||||
|
@ -1,18 +1,11 @@
|
|||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
using System.Net.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using EFB.Models;
|
|
||||||
using EFB.Models.JSON;
|
|
||||||
using EFB.Sessions;
|
|
||||||
using EFB.Controllers.Form;
|
|
||||||
using EFB.Controllers.API;
|
using EFB.Controllers.API;
|
||||||
|
using EFB.Controllers.Form;
|
||||||
|
using EFB.Models.JSON;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace EFB.Models
|
namespace EFB.Models
|
||||||
{
|
{
|
||||||
@ -29,7 +22,8 @@ namespace EFB.Models
|
|||||||
public Chart[] PilotBriefing { get; set; }
|
public Chart[] PilotBriefing { get; set; }
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public ChartModel(){
|
public ChartModel()
|
||||||
|
{
|
||||||
//Empty constructor for JSON Serialisation Purposes
|
//Empty constructor for JSON Serialisation Purposes
|
||||||
}
|
}
|
||||||
public ChartModel(string ICAO, ChartList response)
|
public ChartModel(string ICAO, ChartList response)
|
||||||
@ -45,7 +39,8 @@ namespace EFB.Models
|
|||||||
PilotBriefing = FillChart(response.PilotBriefing);
|
PilotBriefing = FillChart(response.PilotBriefing);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Chart[] FillChart(ChartsCollection collection){
|
private Chart[] FillChart(ChartsCollection collection)
|
||||||
|
{
|
||||||
if (collection != null)
|
if (collection != null)
|
||||||
{
|
{
|
||||||
return collection.Charts;
|
return collection.Charts;
|
||||||
@ -53,7 +48,8 @@ namespace EFB.Models
|
|||||||
return new Chart[] { };
|
return new Chart[] { };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<ChartList> FetchAsync(string ICAO){
|
public static async Task<ChartList> FetchAsync(string ICAO)
|
||||||
|
{
|
||||||
Console.WriteLine("Start");
|
Console.WriteLine("Start");
|
||||||
if (FormAuthenticator.ValidateICAOCode(ICAO))
|
if (FormAuthenticator.ValidateICAOCode(ICAO))
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace EFB.Models
|
namespace EFB.Models
|
||||||
{
|
{
|
||||||
public class ErrorViewModel
|
public class ErrorViewModel
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using EFB.Models.Route;
|
using EFB.Models.Route;
|
||||||
|
|
||||||
namespace EFB.Models
|
namespace EFB.Models
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace EFB.Models.JSON
|
namespace EFB.Models.JSON
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace EFB.Models.JSON
|
namespace EFB.Models.JSON
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace EFB.Models.JSON
|
namespace EFB.Models.JSON
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace EFB.Models.JSON
|
namespace EFB.Models.JSON
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
|
using MySql.Data.MySqlClient;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MySql.Data.MySqlClient;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using EFB.Sessions;
|
|
||||||
|
|
||||||
namespace EFB.Models
|
namespace EFB.Models
|
||||||
{
|
{
|
||||||
@ -19,7 +17,8 @@ namespace EFB.Models
|
|||||||
public string Longitude { get; set; }
|
public string Longitude { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public NavdataModel(int id, string name, string type, string latitude, string longitude){
|
public NavdataModel(int id, string name, string type, string latitude, string longitude)
|
||||||
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
Name = name;
|
Name = name;
|
||||||
Type = type;
|
Type = type;
|
||||||
@ -29,7 +28,8 @@ namespace EFB.Models
|
|||||||
}
|
}
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public NavdataModel(int id, string name, string type, int? frequency, string latitude, string longitude){
|
public NavdataModel(int id, string name, string type, int? frequency, string latitude, string longitude)
|
||||||
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
Name = name;
|
Name = name;
|
||||||
Type = type;
|
Type = type;
|
||||||
@ -38,7 +38,8 @@ namespace EFB.Models
|
|||||||
Longitude = longitude;
|
Longitude = longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<NavdataModel[]> Populate(){
|
public static async Task<NavdataModel[]> Populate()
|
||||||
|
{
|
||||||
string password = Environment.GetEnvironmentVariable("MySQLPassword", EnvironmentVariableTarget.User);
|
string password = Environment.GetEnvironmentVariable("MySQLPassword", EnvironmentVariableTarget.User);
|
||||||
MySqlConnection con = new MySqlConnection($"server=server.luke-else.co.uk;userid=root;password={password};database=EFB");
|
MySqlConnection con = new MySqlConnection($"server=server.luke-else.co.uk;userid=root;password={password};database=EFB");
|
||||||
con.Open();
|
con.Open();
|
||||||
@ -67,7 +68,9 @@ namespace EFB.Models
|
|||||||
navdata.Add(
|
navdata.Add(
|
||||||
new NavdataModel(id, name, type, frequency, latitude, longitude)
|
new NavdataModel(id, name, type, frequency, latitude, longitude)
|
||||||
);
|
);
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
navdata.Add(
|
navdata.Add(
|
||||||
new NavdataModel(id, name, type, latitude, longitude)
|
new NavdataModel(id, name, type, latitude, longitude)
|
||||||
);
|
);
|
||||||
@ -77,7 +80,8 @@ namespace EFB.Models
|
|||||||
return navdata.ToArray<NavdataModel>();
|
return navdata.ToArray<NavdataModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NavdataModel BinarySearch(ref NavdataModel[] data, int start, int end, string target){
|
public static NavdataModel BinarySearch(ref NavdataModel[] data, int start, int end, string target)
|
||||||
|
{
|
||||||
int midpoint = start + ((end - start) / 2);
|
int midpoint = start + ((end - start) / 2);
|
||||||
target = target.ToUpper().Trim();
|
target = target.ToUpper().Trim();
|
||||||
|
|
||||||
@ -122,14 +126,19 @@ namespace EFB.Models
|
|||||||
if (leftPointer == left.Length)
|
if (leftPointer == left.Length)
|
||||||
{//Take a value only from the right (left pointer had reached the end)
|
{//Take a value only from the right (left pointer had reached the end)
|
||||||
AddValue(ref combined, right[rightPointer], ref rightPointer);
|
AddValue(ref combined, right[rightPointer], ref rightPointer);
|
||||||
}else if (rightPointer == right.Length)
|
}
|
||||||
|
else if (rightPointer == right.Length)
|
||||||
{//Take a value only from the left (right pointer has reached the end)
|
{//Take a value only from the left (right pointer has reached the end)
|
||||||
AddValue(ref combined, left[leftPointer], ref leftPointer);
|
AddValue(ref combined, left[leftPointer], ref leftPointer);
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (String.Compare(left[leftPointer].Name, right[rightPointer].Name) <= 0)
|
if (String.Compare(left[leftPointer].Name, right[rightPointer].Name) <= 0)
|
||||||
{//Take a value from the left hand side of the list. (Left value is considered 'smaller')
|
{//Take a value from the left hand side of the list. (Left value is considered 'smaller')
|
||||||
AddValue(ref combined, left[leftPointer], ref leftPointer);
|
AddValue(ref combined, left[leftPointer], ref leftPointer);
|
||||||
}else{//Take a value from the right (right value is considered smaller)
|
}
|
||||||
|
else
|
||||||
|
{//Take a value from the right (right value is considered smaller)
|
||||||
AddValue(ref combined, right[rightPointer], ref rightPointer);
|
AddValue(ref combined, right[rightPointer], ref rightPointer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,7 +148,8 @@ namespace EFB.Models
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddValue(ref List<NavdataModel> data, NavdataModel value, ref int pointer){
|
private static void AddValue(ref List<NavdataModel> data, NavdataModel value, ref int pointer)
|
||||||
|
{
|
||||||
pointer++;
|
pointer++;
|
||||||
data.Add(value);
|
data.Add(value);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace EFB.Models
|
namespace EFB.Models
|
||||||
{
|
{
|
||||||
public class ResponseModel<T>
|
public class ResponseModel<T>
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace EFB.Models.Route
|
namespace EFB.Models.Route
|
||||||
{
|
{
|
||||||
public interface IWaypoint
|
public interface IWaypoint
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace EFB.Models.Route
|
namespace EFB.Models.Route
|
||||||
{
|
{
|
||||||
public class NavaidModel : IWaypoint
|
public class NavaidModel : IWaypoint
|
||||||
@ -17,7 +12,8 @@ namespace EFB.Models.Route
|
|||||||
public IWaypoint Previous { get; set; } = null;
|
public IWaypoint Previous { get; set; } = null;
|
||||||
public bool Visited { get; set; } = false;
|
public bool Visited { get; set; } = false;
|
||||||
|
|
||||||
public NavaidModel(string name, string airway, float longitude, float latitude){
|
public NavaidModel(string name, string airway, float longitude, float latitude)
|
||||||
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Airway = airway;
|
Airway = airway;
|
||||||
Longitude = longitude;
|
Longitude = longitude;
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace EFB.Models.Route
|
namespace EFB.Models.Route
|
||||||
{
|
{
|
||||||
public class WaypointModel : IWaypoint
|
public class WaypointModel : IWaypoint
|
||||||
@ -16,7 +11,8 @@ namespace EFB.Models.Route
|
|||||||
public IWaypoint Previous { get; set; } = null;
|
public IWaypoint Previous { get; set; } = null;
|
||||||
public bool Visited { get; set; }
|
public bool Visited { get; set; }
|
||||||
|
|
||||||
public WaypointModel(string name, string airway, float longitude, float latitude){
|
public WaypointModel(string name, string airway, float longitude, float latitude)
|
||||||
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Airway = airway;
|
Airway = airway;
|
||||||
Longitude = longitude;
|
Longitude = longitude;
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using EFB.Models.Route;
|
|
||||||
using EFB.Controllers.Form;
|
using EFB.Controllers.Form;
|
||||||
using System.Net.Http;
|
using EFB.Models.Route;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace EFB.Models
|
namespace EFB.Models
|
||||||
{
|
{
|
||||||
@ -19,7 +15,8 @@ namespace EFB.Models
|
|||||||
public WaypointModel Arrival { get; set; } = null;
|
public WaypointModel Arrival { get; set; } = null;
|
||||||
public IWaypoint Current { get; set; } = null;
|
public IWaypoint Current { get; set; } = null;
|
||||||
public uint Cruise { get; set; } = 0;
|
public uint Cruise { get; set; } = 0;
|
||||||
public RouteModel(string departure, string departureRoute, string arrival, string arrivalRoute, uint cruise){
|
public RouteModel(string departure, string departureRoute, string arrival, string arrivalRoute, uint cruise)
|
||||||
|
{
|
||||||
if (FormAuthenticator.ValidateICAOCode(departure))
|
if (FormAuthenticator.ValidateICAOCode(departure))
|
||||||
{
|
{
|
||||||
Departure = new WaypointModel(departure, departureRoute, 0, 0);
|
Departure = new WaypointModel(departure, departureRoute, 0, 0);
|
||||||
@ -36,16 +33,20 @@ namespace EFB.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IWaypoint Next(){
|
public IWaypoint Next()
|
||||||
if(Current.Next != null){
|
{
|
||||||
|
if (Current.Next != null)
|
||||||
|
{
|
||||||
Current = Current.Next;
|
Current = Current.Next;
|
||||||
return Current;
|
return Current;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IWaypoint Previous(){
|
public IWaypoint Previous()
|
||||||
if(Current.Previous != null){
|
{
|
||||||
|
if (Current.Previous != null)
|
||||||
|
{
|
||||||
Current = Current.Previous;
|
Current = Current.Previous;
|
||||||
return Current;
|
return Current;
|
||||||
}
|
}
|
||||||
@ -53,7 +54,8 @@ namespace EFB.Models
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Generate a route Object
|
//Generate a route Object
|
||||||
public static async Task<RouteModel> StringToRoute(string departure, string arrival, uint cruise, string routeString){
|
public static async Task<RouteModel> StringToRoute(string departure, string arrival, uint cruise, string routeString)
|
||||||
|
{
|
||||||
var navdataFetch = NavdataModel.Populate();
|
var navdataFetch = NavdataModel.Populate();
|
||||||
string[] routeTemp = routeString.Split(" ");
|
string[] routeTemp = routeString.Split(" ");
|
||||||
|
|
||||||
@ -86,7 +88,8 @@ namespace EFB.Models
|
|||||||
float.Parse(currentWaypoint.Longitude),
|
float.Parse(currentWaypoint.Longitude),
|
||||||
float.Parse(currentWaypoint.Latitude)
|
float.Parse(currentWaypoint.Latitude)
|
||||||
);
|
);
|
||||||
}else
|
}
|
||||||
|
else
|
||||||
{//Navaid Type
|
{//Navaid Type
|
||||||
next = new NavaidModel(
|
next = new NavaidModel(
|
||||||
routeTemp[i],
|
routeTemp[i],
|
||||||
@ -123,7 +126,8 @@ namespace EFB.Models
|
|||||||
|
|
||||||
|
|
||||||
//Generate a route String
|
//Generate a route String
|
||||||
public static string ParseRoute(string route){
|
public static string ParseRoute(string route)
|
||||||
|
{
|
||||||
route.Replace('/', ' ');
|
route.Replace('/', ' ');
|
||||||
var routeArr = route.Split(' ');
|
var routeArr = route.Split(' ');
|
||||||
|
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MongoDB.Bson.Serialization.Attributes;
|
|
||||||
using MongoDB.Bson;
|
using MongoDB.Bson;
|
||||||
using MongoDB.Driver;
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace EFB.Models
|
namespace EFB.Models
|
||||||
{
|
{
|
||||||
@ -16,7 +12,8 @@ namespace EFB.Models
|
|||||||
public DateTime LatestPacketUpdate { get; set; }
|
public DateTime LatestPacketUpdate { get; set; }
|
||||||
public SimPosition LatestPosition { get; set; } = null;
|
public SimPosition LatestPosition { get; set; } = null;
|
||||||
|
|
||||||
public SimPositionModel(string email, SimPosition position){
|
public SimPositionModel(string email, SimPosition position)
|
||||||
|
{
|
||||||
EMail = email;
|
EMail = email;
|
||||||
LatestPacketUpdate = DateTime.Now;
|
LatestPacketUpdate = DateTime.Now;
|
||||||
LatestPosition = position;
|
LatestPosition = position;
|
||||||
@ -31,7 +28,8 @@ namespace EFB.Models
|
|||||||
public float Longitude { get; set; }
|
public float Longitude { get; set; }
|
||||||
public int Altitude { get; set; }
|
public int Altitude { get; set; }
|
||||||
|
|
||||||
public SimPosition(float latitude, float longitude, int altitude){
|
public SimPosition(float latitude, float longitude, int altitude)
|
||||||
|
{
|
||||||
Latitude = latitude;
|
Latitude = latitude;
|
||||||
Longitude = longitude;
|
Longitude = longitude;
|
||||||
Altitude = altitude;
|
Altitude = altitude;
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace EFB.Models
|
namespace EFB.Models
|
||||||
{
|
{
|
||||||
@ -13,7 +10,8 @@ namespace EFB.Models
|
|||||||
public string TokenValue { get; init; }
|
public string TokenValue { get; init; }
|
||||||
public DateTime Expiration { get; init; }
|
public DateTime Expiration { get; init; }
|
||||||
|
|
||||||
public bool IsExpired(){
|
public bool IsExpired()
|
||||||
|
{
|
||||||
//Check if the current time is beyond expiration
|
//Check if the current time is beyond expiration
|
||||||
if (DateTime.UtcNow > Expiration)
|
if (DateTime.UtcNow > Expiration)
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace EFB.Models
|
namespace EFB.Models
|
||||||
{
|
{
|
||||||
public class UserModel
|
public class UserModel
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Html;
|
|
||||||
using Microsoft.AspNetCore.Razor;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using EFB.Models.JSON;
|
using EFB.Models.JSON;
|
||||||
using Microsoft.AspNetCore;
|
using Newtonsoft.Json;
|
||||||
using EFB.Sessions;
|
|
||||||
|
|
||||||
namespace EFB.Models
|
namespace EFB.Models
|
||||||
{
|
{
|
||||||
@ -17,7 +8,8 @@ namespace EFB.Models
|
|||||||
public ChartModel Charts { get; set; }
|
public ChartModel Charts { get; set; }
|
||||||
public Chart Selected { get; set; }
|
public Chart Selected { get; set; }
|
||||||
|
|
||||||
public ViewChartModel(ChartModel current, string selected){
|
public ViewChartModel(ChartModel current, string selected)
|
||||||
|
{
|
||||||
Charts = current;
|
Charts = current;
|
||||||
if (selected != null)
|
if (selected != null)
|
||||||
{
|
{
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MongoDB.Driver;
|
|
||||||
using MongoDB.Bson;
|
|
||||||
using EFB.Models;
|
using EFB.Models;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace EFB.MongoData
|
namespace EFB.MongoData
|
||||||
{
|
{
|
||||||
public class Mongo
|
public class Mongo
|
||||||
{
|
{
|
||||||
//function that is responsible to getting the user's latest sim position from the MongoDB
|
//function that is responsible to getting the user's latest sim position from the MongoDB
|
||||||
public static async Task<SimPositionModel> GetLatestData(string email){
|
public static async Task<SimPositionModel> GetLatestData(string email)
|
||||||
|
{
|
||||||
|
//Create mongo client to allow connection to the database
|
||||||
MongoClient client = new MongoClient(
|
MongoClient client = new MongoClient(
|
||||||
Environment.GetEnvironmentVariable("MongoDBConnectionString", EnvironmentVariableTarget.User)
|
Environment.GetEnvironmentVariable("MongoDBConnectionString", EnvironmentVariableTarget.User)
|
||||||
);
|
);
|
||||||
MongoDatabaseBase database = (MongoDatabaseBase)client.GetDatabase("EFB");
|
MongoDatabaseBase database = (MongoDatabaseBase)client.GetDatabase("EFB");
|
||||||
MongoCollectionBase<SimPositionModel> collection = (MongoCollectionBase<SimPositionModel>)database.GetCollection<SimPositionModel>("Simdata");
|
MongoCollectionBase<SimPositionModel> collection = (MongoCollectionBase<SimPositionModel>)database.GetCollection<SimPositionModel>("Simdata");
|
||||||
|
|
||||||
|
//Create filter to select specifically the records where the Email is the same as what we specified
|
||||||
FilterDefinition<SimPositionModel> filter = Builders<SimPositionModel>.Filter.Eq(x => x.EMail, email);
|
FilterDefinition<SimPositionModel> filter = Builders<SimPositionModel>.Filter.Eq(x => x.EMail, email);
|
||||||
var data = await collection.FindAsync<SimPositionModel>(filter).Result.ToListAsync();
|
var data = await collection.FindAsync<SimPositionModel>(filter).Result.ToListAsync();
|
||||||
if (data.Count > 0)
|
if (data.Count > 0)
|
||||||
{
|
{//Return the first item in the list (Should only be 1)
|
||||||
return data[0];
|
return data[0];
|
||||||
}
|
}//Or return null if not present
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace EFB
|
namespace EFB
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,8 @@ namespace EFB.Sessions
|
|||||||
public static void SetObject(this ISession session, string key, object value)
|
public static void SetObject(this ISession session, string key, object value)
|
||||||
{//Sets the object of a session to Object
|
{//Sets the object of a session to Object
|
||||||
session.SetString(key, JsonConvert.SerializeObject(value, Formatting.None,
|
session.SetString(key, JsonConvert.SerializeObject(value, Formatting.None,
|
||||||
new JsonSerializerSettings(){
|
new JsonSerializerSettings()
|
||||||
|
{
|
||||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.HttpsPolicy;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace EFB
|
namespace EFB
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user