From c8f95c7e18671e5df158ab45638ba7373e907505 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Tue, 3 May 2022 00:59:32 +0200 Subject: [PATCH] Use SSO auth, remove legacy deutschebahn endpoints --- trainav.web/JSON/CardResponse/CardResponse.cs | 214 --------- .../ListOrdersResponse/ListOrdersResponse.cs | 75 --- trainav.web/JSON/OEAPIResponse.cs | 28 +- trainav.web/JSON/TicketResponse.cs | 434 ------------------ trainav.web/Migrations.cs | 30 +- trainav.web/Pages/Card.cshtml | 16 - trainav.web/Pages/Card.cshtml.cs | 65 --- trainav.web/Pages/Cards.cshtml | 169 ------- trainav.web/Pages/Cards.cshtml.cs | 54 --- trainav.web/Pages/Delete.cshtml | 98 ++-- trainav.web/Pages/Delete.cshtml.cs | 29 +- trainav.web/Pages/Index.cshtml | 174 ++++--- trainav.web/Pages/Index.cshtml.cs | 9 +- trainav.web/Pages/Inspection.cshtml | 151 ------ trainav.web/Pages/Inspection.cshtml.cs | 29 -- trainav.web/Pages/Login.cshtml | 30 -- trainav.web/Pages/Logout.cshtml | 7 - trainav.web/Pages/Logout.cshtml.cs | 9 - trainav.web/Pages/OEAPI.cshtml | 12 +- trainav.web/Pages/OEAPI.cshtml.cs | 14 +- trainav.web/Pages/Plain.cshtml | 44 -- trainav.web/Pages/Plain.cshtml.cs | 20 - trainav.web/Pages/Register.cshtml | 29 -- trainav.web/Pages/Register.cshtml.cs | 31 -- trainav.web/Pages/Shared/_Layout.cshtml | 84 ++-- trainav.web/Pages/Ticket.cshtml | 16 - trainav.web/Pages/Ticket.cshtml.cs | 255 ---------- trainav.web/Pages/Trip.cshtml | 309 ++++++------- trainav.web/Pages/Trip.cshtml.cs | 18 +- trainav.web/Utils/AuthUtil.cs | 17 + .../StringExtensions.cs} | 27 +- trainav.web/database/Database.cs | 5 +- trainav.web/database/Tables/Card.cs | 36 -- trainav.web/database/Tables/Leg.cs | 4 +- trainav.web/database/Tables/Ticket.cs | 22 - trainav.web/database/Tables/TicketLeg.cs | 27 -- trainav.web/database/Tables/User.cs | 4 +- trainav.web/trainav.web.csproj | 39 -- trainav.web/wwwroot/css/site.css | 86 ++-- 39 files changed, 439 insertions(+), 2281 deletions(-) delete mode 100644 trainav.web/JSON/CardResponse/CardResponse.cs delete mode 100644 trainav.web/JSON/ListOrdersResponse/ListOrdersResponse.cs delete mode 100644 trainav.web/JSON/TicketResponse.cs delete mode 100644 trainav.web/Pages/Card.cshtml delete mode 100644 trainav.web/Pages/Card.cshtml.cs delete mode 100644 trainav.web/Pages/Cards.cshtml delete mode 100644 trainav.web/Pages/Cards.cshtml.cs delete mode 100644 trainav.web/Pages/Inspection.cshtml delete mode 100644 trainav.web/Pages/Inspection.cshtml.cs delete mode 100644 trainav.web/Pages/Login.cshtml delete mode 100644 trainav.web/Pages/Logout.cshtml delete mode 100644 trainav.web/Pages/Logout.cshtml.cs delete mode 100644 trainav.web/Pages/Plain.cshtml delete mode 100644 trainav.web/Pages/Plain.cshtml.cs delete mode 100644 trainav.web/Pages/Register.cshtml delete mode 100644 trainav.web/Pages/Register.cshtml.cs delete mode 100644 trainav.web/Pages/Ticket.cshtml delete mode 100644 trainav.web/Pages/Ticket.cshtml.cs create mode 100644 trainav.web/Utils/AuthUtil.cs rename trainav.web/{Pages/Login.cshtml.cs => Utils/StringExtensions.cs} (55%) delete mode 100644 trainav.web/database/Tables/Card.cs delete mode 100644 trainav.web/database/Tables/Ticket.cs delete mode 100644 trainav.web/database/Tables/TicketLeg.cs diff --git a/trainav.web/JSON/CardResponse/CardResponse.cs b/trainav.web/JSON/CardResponse/CardResponse.cs deleted file mode 100644 index 7447e49..0000000 --- a/trainav.web/JSON/CardResponse/CardResponse.cs +++ /dev/null @@ -1,214 +0,0 @@ -// -// -// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do: -// -// using trainav.web.JSON.CardResponse; -// -// var cardResponse = CardResponse.FromJson(jsonString); - -using System.Collections.Generic; -using System.Globalization; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; - -namespace trainav.web.JSON.CardResponse { - public partial class CardResponse { - [JsonProperty("?xml", NullValueHandling = NullValueHandling.Ignore)] - public Xml Xml { get; set; } - - [JsonProperty("rporderdetails", NullValueHandling = NullValueHandling.Ignore)] - public Rporderdetails Rporderdetails { get; set; } - } - - public class Rporderdetails { - [JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)] - public string Version { get; set; } - - [JsonProperty("rpheader", NullValueHandling = NullValueHandling.Ignore)] - public Rpheader Rpheader { get; set; } - - [JsonProperty("order", NullValueHandling = NullValueHandling.Ignore)] - public Order Order { get; set; } - } - - public class Order { - [JsonProperty("@cdt", NullValueHandling = NullValueHandling.Ignore)] - public string Cdt { get; set; } - - [JsonProperty("@cid", NullValueHandling = NullValueHandling.Ignore)] - public string Cid { get; set; } - - [JsonProperty("@ddt", NullValueHandling = NullValueHandling.Ignore)] - public string Ddt { get; set; } - - [JsonProperty("@fkat", NullValueHandling = NullValueHandling.Ignore)] - public string Fkat { get; set; } - - [JsonProperty("@ldt", NullValueHandling = NullValueHandling.Ignore)] - public string Ldt { get; set; } - - [JsonProperty("@on", NullValueHandling = NullValueHandling.Ignore)] - public string On { get; set; } - - [JsonProperty("@pg", NullValueHandling = NullValueHandling.Ignore)] - public string Pg { get; set; } - - [JsonProperty("@sdt", NullValueHandling = NullValueHandling.Ignore)] - public string Sdt { get; set; } - - [JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)] - public string Version { get; set; } - - [JsonProperty("@vfrom", NullValueHandling = NullValueHandling.Ignore)] - public string Vfrom { get; set; } - - [JsonProperty("@vto", NullValueHandling = NullValueHandling.Ignore)] - public string Vto { get; set; } - - [JsonProperty("@zweg", NullValueHandling = NullValueHandling.Ignore)] - public string Zweg { get; set; } - - [JsonProperty("tcklist", NullValueHandling = NullValueHandling.Ignore)] - public Tcklist Tcklist { get; set; } - - [JsonProperty("posinfolist", NullValueHandling = NullValueHandling.Ignore)] - public Posinfolist Posinfolist { get; set; } - } - - public class Posinfolist { - [JsonProperty("posinfo", NullValueHandling = NullValueHandling.Ignore)] - public Posinfo Posinfo { get; set; } - } - - public class Posinfo { - [JsonProperty("@dir", NullValueHandling = NullValueHandling.Ignore)] - public string Dir { get; set; } - - [JsonProperty("@dirlabel", NullValueHandling = NullValueHandling.Ignore)] - public string Dirlabel { get; set; } - - [JsonProperty("@posnr", NullValueHandling = NullValueHandling.Ignore)] - public string Posnr { get; set; } - - [JsonProperty("@shownr", NullValueHandling = NullValueHandling.Ignore)] - public string Shownr { get; set; } - - [JsonProperty("@state", NullValueHandling = NullValueHandling.Ignore)] - public string State { get; set; } - - [JsonProperty("@type", NullValueHandling = NullValueHandling.Ignore)] - public string Type { get; set; } - - [JsonProperty("@typeinfo", NullValueHandling = NullValueHandling.Ignore)] - public string Typeinfo { get; set; } - - [JsonProperty("@vfo", NullValueHandling = NullValueHandling.Ignore)] - public string Vfo { get; set; } - - [JsonProperty("@vto", NullValueHandling = NullValueHandling.Ignore)] - public string Vto { get; set; } - - [JsonProperty("childlist")] public object Childlist { get; set; } - } - - public class Tcklist { - [JsonProperty("tck", NullValueHandling = NullValueHandling.Ignore)] - public Tck Tck { get; set; } - } - - public class Tck { - [JsonProperty("@posnr", NullValueHandling = NullValueHandling.Ignore)] - public string Posnr { get; set; } - - [JsonProperty("htdata", NullValueHandling = NullValueHandling.Ignore)] - public Htdata Htdata { get; set; } - - [JsonProperty("mtk", NullValueHandling = NullValueHandling.Ignore)] - public Mtk Mtk { get; set; } - - [JsonProperty("bahncardimage", NullValueHandling = NullValueHandling.Ignore)] - public Bahncardimage Bahncardimage { get; set; } - } - - public class Bahncardimage { - [JsonProperty("#cdata-section", NullValueHandling = NullValueHandling.Ignore)] - public string CdataSection { get; set; } - } - - public class Htdata { - [JsonProperty("ht", NullValueHandling = NullValueHandling.Ignore)] - public List Ht { get; set; } - } - - public class Ht { - [JsonProperty("@name", NullValueHandling = NullValueHandling.Ignore)] - public string Name { get; set; } - - [JsonProperty("@pos", NullValueHandling = NullValueHandling.Ignore)] - public string Pos { get; set; } - - [JsonProperty("@type", NullValueHandling = NullValueHandling.Ignore)] - public string Type { get; set; } - - [JsonProperty("#text", NullValueHandling = NullValueHandling.Ignore)] - public string Text { get; set; } - } - - public class Mtk { - [JsonProperty("@dir", NullValueHandling = NullValueHandling.Ignore)] - public string Dir { get; set; } - - [JsonProperty("@status", NullValueHandling = NullValueHandling.Ignore)] - public string Status { get; set; } - - [JsonProperty("txt", NullValueHandling = NullValueHandling.Ignore)] - public string Txt { get; set; } - - [JsonProperty("zb", NullValueHandling = NullValueHandling.Ignore)] - public string Zb { get; set; } - - [JsonProperty("nvplist", NullValueHandling = NullValueHandling.Ignore)] - public Nvplist Nvplist { get; set; } - } - - public class Nvplist { - [JsonProperty("nvp", NullValueHandling = NullValueHandling.Ignore)] - public List Nvp { get; set; } - } - - public class Nvp { - [JsonProperty("@name", NullValueHandling = NullValueHandling.Ignore)] - public string Name { get; set; } - - [JsonProperty("#text", NullValueHandling = NullValueHandling.Ignore)] - public string Text { get; set; } - } - - public class Rpheader { - [JsonProperty("@tnr", NullValueHandling = NullValueHandling.Ignore)] - public string Tnr { get; set; } - - [JsonProperty("@ts", NullValueHandling = NullValueHandling.Ignore)] - public string Ts { get; set; } - } - - public class Xml { - [JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)] - public string Version { get; set; } - - [JsonProperty("@encoding", NullValueHandling = NullValueHandling.Ignore)] - public string Encoding { get; set; } - } - - public partial class CardResponse { - public static CardResponse FromJson(string json) => JsonConvert.DeserializeObject(json, Converter.Settings); - } - - internal static class Converter { - public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings { - MetadataPropertyHandling = MetadataPropertyHandling.Ignore, - DateParseHandling = DateParseHandling.None, - Converters = {new IsoDateTimeConverter {DateTimeStyles = DateTimeStyles.AssumeUniversal}} - }; - } -} diff --git a/trainav.web/JSON/ListOrdersResponse/ListOrdersResponse.cs b/trainav.web/JSON/ListOrdersResponse/ListOrdersResponse.cs deleted file mode 100644 index eea184b..0000000 --- a/trainav.web/JSON/ListOrdersResponse/ListOrdersResponse.cs +++ /dev/null @@ -1,75 +0,0 @@ -// -// -// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do: -// -// using trainav.web.JSON; -// -// var listOrdersResponse = ListOrdersResponse.FromJson(jsonString); - -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace trainav.web.JSON.ListOrdersResponse { - public partial class ListOrdersResponse { - [JsonProperty("?xml", NullValueHandling = NullValueHandling.Ignore)] - public Xml Xml { get; set; } - - [JsonProperty("rporderheadlist", NullValueHandling = NullValueHandling.Ignore)] - public Rporderheadlist Rporderheadlist { get; set; } - } - - public class Rporderheadlist { - [JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)] - public string Version { get; set; } - - [JsonProperty("rpheader", NullValueHandling = NullValueHandling.Ignore)] - public Rpheader Rpheader { get; set; } - - [JsonProperty("orderheadlist", NullValueHandling = NullValueHandling.Ignore)] - public Orderheadlist Orderheadlist { get; set; } - } - - public class Orderheadlist { - [JsonProperty("orderhead", NullValueHandling = NullValueHandling.Ignore)] - public List Orderhead { get; set; } - } - - public class Orderhead { - [JsonProperty("@ldt", NullValueHandling = NullValueHandling.Ignore)] - public string Ldt { get; set; } - - [JsonProperty("@on", NullValueHandling = NullValueHandling.Ignore)] - public string On { get; set; } - - [JsonProperty("authtmp", NullValueHandling = NullValueHandling.Ignore)] - public Authtmp Authtmp { get; set; } - } - - public class Authtmp { - [JsonProperty("@htmp", NullValueHandling = NullValueHandling.Ignore)] - public string Htmp { get; set; } - - [JsonProperty("@ts", NullValueHandling = NullValueHandling.Ignore)] - public string Ts { get; set; } - } - - public class Rpheader { - [JsonProperty("@tnr", NullValueHandling = NullValueHandling.Ignore)] - public string Tnr { get; set; } - - [JsonProperty("@ts", NullValueHandling = NullValueHandling.Ignore)] - public string Ts { get; set; } - } - - public class Xml { - [JsonProperty("@version", NullValueHandling = NullValueHandling.Ignore)] - public string Version { get; set; } - - [JsonProperty("@encoding", NullValueHandling = NullValueHandling.Ignore)] - public string Encoding { get; set; } - } - - public partial class ListOrdersResponse { - public static ListOrdersResponse FromJson(string json) => JsonConvert.DeserializeObject(json, Converter.Settings); - } -} \ No newline at end of file diff --git a/trainav.web/JSON/OEAPIResponse.cs b/trainav.web/JSON/OEAPIResponse.cs index 4392194..c223edc 100644 --- a/trainav.web/JSON/OEAPIResponse.cs +++ b/trainav.web/JSON/OEAPIResponse.cs @@ -13,6 +13,12 @@ namespace trainav.web.JSON { using J = JsonPropertyAttribute; using R = Required; using N = NullValueHandling; + using System; + using System.Collections.Generic; + using System.Globalization; + using Newtonsoft.Json; + using Newtonsoft.Json.Converters; + using Newtonsoft.Json.Linq; public partial class OeapiResponse { [J("status", NullValueHandling = N.Ignore)] @@ -259,4 +265,24 @@ namespace trainav.web.JSON { public partial class OeapiResponse { public static OeapiResponse FromJson(string json) => JsonConvert.DeserializeObject(json, Converter.Settings); } -} \ No newline at end of file + + internal static class Converter { + public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings { + MetadataPropertyHandling = MetadataPropertyHandling.Ignore, + DateParseHandling = DateParseHandling.None, + Converters = {new IsoDateTimeConverter {DateTimeStyles = DateTimeStyles.AssumeUniversal}} + }; + } + internal class SingleOrArrayConverter : JsonConverter { + public override bool CanWrite => false; + public override bool CanConvert(Type objectType) => objectType == typeof(List); + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { + var token = JToken.Load(reader); + return token.Type == JTokenType.Array ? token.ToObject>() : new List {token.ToObject()}; + } + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { + throw new NotImplementedException(); + } + } + +} diff --git a/trainav.web/JSON/TicketResponse.cs b/trainav.web/JSON/TicketResponse.cs deleted file mode 100644 index dc0ea42..0000000 --- a/trainav.web/JSON/TicketResponse.cs +++ /dev/null @@ -1,434 +0,0 @@ -// -// -// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do: -// -// using trainav.web.JSON; -// -// var ticketResponse = TicketResponse.FromJson(jsonString); - -using System; -using System.Collections.Generic; -using System.Globalization; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Linq; - -namespace trainav.web.JSON { - using J = JsonPropertyAttribute; - using R = Required; - using NV = NullValueHandling; - - public partial class TicketResponse { - [J("?xml", NullValueHandling = NV.Ignore)] - public Xml Xml { get; set; } - - [J("rporderdetails", NullValueHandling = NV.Ignore)] - public Rporderdetails Rporderdetails { get; set; } - } - - public class Rporderdetails { - [J("rpheader", NullValueHandling = NV.Ignore)] - public Rpheader Rpheader { get; set; } - - [J("@version", NullValueHandling = NV.Ignore)] - public string Version { get; set; } - - [J("order", NullValueHandling = NV.Ignore)] - public Order Order { get; set; } - } - - public class Order { - [J("@cid", NullValueHandling = NV.Ignore)] - public string Cid { get; set; } - - [J("@cdt", NullValueHandling = NV.Ignore)] - public string Cdt { get; set; } - - [J("schedulelist", NullValueHandling = NV.Ignore)] - public Schedulelist Schedulelist { get; set; } - - [J("tcklist", NullValueHandling = NV.Ignore)] - public Tcklist Tcklist { get; set; } - - [J("@sdt", NullValueHandling = NV.Ignore)] - public string Sdt { get; set; } - - [J("@zweg", NullValueHandling = NV.Ignore)] - public string Zweg { get; set; } - - [J("@vto", NullValueHandling = NV.Ignore)] - public string Vto { get; set; } - - [J("@vfrom", NullValueHandling = NV.Ignore)] - public string Vfrom { get; set; } - - [J("@ldt", NullValueHandling = NV.Ignore)] - public string Ldt { get; set; } - - [J("@pg", NullValueHandling = NV.Ignore)] - public string Pg { get; set; } - - [J("posinfolist", NullValueHandling = NV.Ignore)] - public Posinfolist Posinfolist { get; set; } - - [J("@on", NullValueHandling = NV.Ignore)] - public string On { get; set; } - - [J("txt", NullValueHandling = NV.Ignore)] - public string Txt { get; set; } - - [J("@hkey", NullValueHandling = NV.Ignore)] - public string Hkey { get; set; } - - [J("reslist", NullValueHandling = NV.Ignore)] - public Reslist Reslist { get; set; } - - [J("@ddt", NullValueHandling = NV.Ignore)] - public string Ddt { get; set; } - - [J("@version", NullValueHandling = NV.Ignore)] - public string Version { get; set; } - - [J("@fkat", NullValueHandling = NV.Ignore)] - public string Fkat { get; set; } - } - - public class Posinfolist { - [J("posinfo", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter))] - public List Posinfo { get; set; } - } - - public class FluffyChildlist { - [J("posinfo", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter))] - public List Posinfo { get; set; } - } - - public class PurplePosinfo { - [J("@state", NullValueHandling = NV.Ignore)] - public string State { get; set; } - - [J("@dir", NullValueHandling = NV.Ignore)] - public string Dir { get; set; } - - [J("@posnr", NullValueHandling = NV.Ignore)] - public string Posnr { get; set; } - - [J("@type", NullValueHandling = NV.Ignore)] - public string Type { get; set; } - - [J("@shownr", NullValueHandling = NV.Ignore)] - public string Shownr { get; set; } - - [J("@dirlabel", NullValueHandling = NV.Ignore)] - public string Dirlabel { get; set; } - - [J("@vfo", NullValueHandling = NV.Ignore)] - public string Vfo { get; set; } - - [J("@typeinfo", NullValueHandling = NV.Ignore)] - public string Typeinfo { get; set; } - - [J("@vto", NullValueHandling = NV.Ignore)] - public string Vto { get; set; } - - [J("childlist", NullValueHandling = NV.Ignore)] - public FluffyChildlist Childlist { get; set; } - } - - public class PurpleChildlist { - [J("posinfo", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter))] - public List Posinfo { get; set; } - } - - public class PosinfoElement { - [J("@state", NullValueHandling = NV.Ignore)] - public string State { get; set; } - - [J("@dir", NullValueHandling = NV.Ignore)] - public string Dir { get; set; } - - [J("@posnr", NullValueHandling = NV.Ignore)] - public string Posnr { get; set; } - - [J("@type", NullValueHandling = NV.Ignore)] - public string Type { get; set; } - - [J("@shownr", NullValueHandling = NV.Ignore)] - public string Shownr { get; set; } - - [J("@dirlabel", NullValueHandling = NV.Ignore)] - public string Dirlabel { get; set; } - - [J("@vfo", NullValueHandling = NV.Ignore)] - public string Vfo { get; set; } - - [J("@typeinfo", NullValueHandling = NV.Ignore)] - public string Typeinfo { get; set; } - - [J("@vto", NullValueHandling = NV.Ignore)] - public string Vto { get; set; } - - [J("childlist", NullValueHandling = NV.Ignore)] - public PurpleChildlist Childlist { get; set; } - } - - public class Reslist { - [J("res", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter))] - public List Res { get; set; } - } - - public class Re { - [J("@tid", NullValueHandling = NV.Ignore)] - public string Tid { get; set; } - - [J("@posnr", NullValueHandling = NV.Ignore)] - public string Posnr { get; set; } - - [J("@dt", NullValueHandling = NV.Ignore)] - public string Dt { get; set; } - - [J("nvplist", NullValueHandling = NV.Ignore)] - public Nvplist Nvplist { get; set; } - - [J("@cdt", NullValueHandling = NV.Ignore)] - public string Cdt { get; set; } - - [J("plaetze", NullValueHandling = NV.Ignore)] - public Plaetze Plaetze { get; set; } - - [J("txt", NullValueHandling = NV.Ignore)] - public string Txt { get; set; } - - [J("@tn", NullValueHandling = NV.Ignore)] - public string Tn { get; set; } - } - - public class Nvplist { - [J("nvp", NullValueHandling = NV.Ignore)] - public List Nvp { get; set; } - } - - public class Nvp { - [J("@name", NullValueHandling = NV.Ignore)] - public string Name { get; set; } - - [J("#text", NullValueHandling = NV.Ignore)] - public string Text { get; set; } - } - - public class Plaetze { - [J("platz", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter))] - public List Platz { get; set; } - } - - public class Platz { - [J("platznr", NullValueHandling = NV.Ignore)] - public string Platznr { get; set; } - - [J("wagennr", NullValueHandling = NV.Ignore)] - public string Wagennr { get; set; } - } - - public class Schedulelist { - [J("out", NullValueHandling = NV.Ignore)] - public Journey Out { get; set; } - - [J("ret", NullValueHandling = NV.Ignore)] - public Journey Ret { get; set; } - } - - public class Journey { - [J("txt", NullValueHandling = NV.Ignore)] - public string Txt { get; set; } - - [J("@posnr", NullValueHandling = NV.Ignore)] - public string Posnr { get; set; } - - [J("trainlist", NullValueHandling = NV.Ignore)] - public Trainlist Trainlist { get; set; } - } - - public class Trainlist { - [J("train", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter))] - public List Train { get; set; } - } - - public class Train { - [J("@tid", NullValueHandling = NV.Ignore)] - public string Tid { get; set; } - - [J("@type", NullValueHandling = NV.Ignore)] - public string Type { get; set; } - - [J("zugnr", NullValueHandling = NV.Ignore)] - public string Zugnummer { get; set; } - - [J("arr", NullValueHandling = NV.Ignore)] - public Station Arr { get; set; } - - [J("gat", NullValueHandling = NV.Ignore)] - public string Gattung { get; set; } - - [J("sci", NullValueHandling = NV.Ignore)] - public string Zugklasse { get; set; } - - [J("dep", NullValueHandling = NV.Ignore)] - public Station Dep { get; set; } - - [J("@tn", NullValueHandling = NV.Ignore)] - public string Line { get; set; } - } - - public class Station { - [J("x", NullValueHandling = NV.Ignore)] - public string X { get; set; } - - [J("y", NullValueHandling = NV.Ignore)] - public string Y { get; set; } - - [J("@dt", NullValueHandling = NV.Ignore)] - public string Date { get; set; } - - [J("ebhf_name", NullValueHandling = NV.Ignore)] - public string EbhfName { get; set; } - - [J("ebhf_nr", NullValueHandling = NV.Ignore)] - public string EbhfNr { get; set; } - - [J("@t", NullValueHandling = NV.Ignore)] - public string Time { get; set; } - - [J("n", NullValueHandling = NV.Ignore)] - public string Name { get; set; } - - [J("nr", NullValueHandling = NV.Ignore)] - public string BhfNr { get; set; } - - [J("plz", NullValueHandling = NV.Ignore)] - public string Plz { get; set; } - - [J("ptf", NullValueHandling = NV.Ignore)] - public string Ptf { get; set; } - } - - public class Tcklist { - [J("tck", NullValueHandling = NV.Ignore), JsonConverter(typeof(SingleOrArrayConverter))] - public List Tck { get; set; } - } - - public class Tck { - [J("mtk", NullValueHandling = NV.Ignore)] - public Mtk Mtk { get; set; } - - [J("@posnr", NullValueHandling = NV.Ignore)] - public string Posnr { get; set; } - - [J("htdata", NullValueHandling = NV.Ignore)] - public Htdata Htdata { get; set; } - } - - public class Htdata { - [J("ht", NullValueHandling = NV.Ignore)] - public List Ht { get; set; } - } - - public class Ht { - [J("@pos", NullValueHandling = NV.Ignore)] - public string Pos { get; set; } - - [J("#text", NullValueHandling = NV.Ignore)] - public string Text { get; set; } - - [J("@name", NullValueHandling = NV.Ignore)] - public string Name { get; set; } - - [J("@type", NullValueHandling = NV.Ignore)] - public string Type { get; set; } - } - - public class Mtk { - [J("@status", NullValueHandling = NV.Ignore)] - public string Status { get; set; } - - [J("@dir", NullValueHandling = NV.Ignore)] - public string Dir { get; set; } - - [J("iss", NullValueHandling = NV.Ignore)] - public string Iss { get; set; } - - [J("tkey", NullValueHandling = NV.Ignore)] - public string Tkey { get; set; } - - [J("bc", NullValueHandling = NV.Ignore)] - public Bc Bc { get; set; } - - [J("nvplist", NullValueHandling = NV.Ignore)] - public Nvplist Nvplist { get; set; } - - [J("reisender_vorname", NullValueHandling = NV.Ignore)] - public string ReisenderVorname { get; set; } - - [J("reisender_nachname", NullValueHandling = NV.Ignore)] - public string ReisenderNachname { get; set; } - - [J("txt", NullValueHandling = NV.Ignore)] - public string Txt { get; set; } - - [J("zb", NullValueHandling = NV.Ignore)] - public string Zb { get; set; } - - [J("ot_nr_hin", NullValueHandling = NV.Ignore)] - public string OtNrHin { get; set; } - } - - public class Bc { - [J("rbs", NullValueHandling = NV.Ignore)] - public string Rbs { get; set; } - - [J("anz", NullValueHandling = NV.Ignore)] - public string Anz { get; set; } - } - - public class Rpheader { - [J("@ts", NullValueHandling = NV.Ignore)] - public string Ts { get; set; } - - [J("@tnr", NullValueHandling = NV.Ignore)] - public string Tnr { get; set; } - } - - public class Xml { - [J("@version", NullValueHandling = NV.Ignore)] - public string Version { get; set; } - - [J("@encoding", NullValueHandling = NV.Ignore)] - public string Encoding { get; set; } - } - - public partial class TicketResponse { - public static TicketResponse FromJson(string json) => JsonConvert.DeserializeObject(json, Converter.Settings); - } - - internal static class Converter { - public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings { - MetadataPropertyHandling = MetadataPropertyHandling.Ignore, - DateParseHandling = DateParseHandling.None, - Converters = {new IsoDateTimeConverter {DateTimeStyles = DateTimeStyles.AssumeUniversal}} - }; - } - - internal class SingleOrArrayConverter : JsonConverter { - public override bool CanWrite => false; - - public override bool CanConvert(Type objectType) => objectType == typeof(List); - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - var token = JToken.Load(reader); - return token.Type == JTokenType.Array ? token.ToObject>() : new List {token.ToObject()}; - } - - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { - throw new NotImplementedException(); - } - } -} diff --git a/trainav.web/Migrations.cs b/trainav.web/Migrations.cs index 66ec099..f47df02 100644 --- a/trainav.web/Migrations.cs +++ b/trainav.web/Migrations.cs @@ -9,7 +9,7 @@ using trainav.web.database.Tables; namespace trainav.web; public static class Migrations { - private const int DbVer = 1; + private const int DbVer = 2; private static readonly List _migrations = new() { new Migration(1, @@ -19,7 +19,28 @@ public static class Migrations { new Migration(1, "CREATE TABLE Tickets(\"TicketID\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, \"UserID\" INTEGER NOT NULL, \"OrderID\" TEXT NOT NULL UNIQUE, \"TicketInfo\" TEXT NOT NULL, \"TicketQR\" BLOB NOT NULL, \"TicketPkPass\" BLOB, \"TicketSecCode\" BLOB NOT NULL, \"Traveller\" TEXT)"), new Migration(1, "INSERT INTO Tickets SELECT TicketID, UserID, OrderID, TicketInfo, TicketQR, TicketPkPass, TicketSecCode, Traveller FROM Tickets_backup"), - new Migration(1, "DROP TABLE Tickets_backup") + new Migration(1, "DROP TABLE Tickets_backup"), + new Migration(2, + "CREATE TEMPORARY TABLE Legs_backup(\"LegID\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, \"TripID\" INTEGER NOT NULL, \"UserID\" INTEGER NOT NULL, \"TrainType\" TEXT NOT NULL, \"TrainNr\" INTEGER NOT NULL, \"DepStationID\" INTEGER NOT NULL, \"DepStation\" TEXT NOT NULL, \"DepTime\" TEXT NOT NULL, \"ArrStationID\" INTEGER NOT NULL, \"ArrStation\" TEXT NOT NULL, \"ArrTime\" TEXT NOT NULL, \"TicketID\" INTEGER, Comment TEXT)"), + new Migration(2, + "INSERT INTO Legs_backup SELECT LegID, TripID, UserID, TrainType, TrainNr, DepStationID, DepStation, DepTime, ArrStationID, ArrStation, ArrTime, TicketID, Comment FROM Legs"), + new Migration(2, "DROP Table Legs"), + new Migration(2, + "CREATE TABLE Legs(\"LegID\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, \"TripID\" INTEGER NOT NULL, \"UserID\" INTEGER NOT NULL, \"TrainType\" TEXT NOT NULL, \"TrainNr\" INTEGER NOT NULL, \"DepStationID\" INTEGER NOT NULL, \"DepStation\" TEXT NOT NULL, \"DepTime\" TEXT NOT NULL, \"ArrStationID\" INTEGER NOT NULL, \"ArrStation\" TEXT NOT NULL, \"ArrTime\" TEXT NOT NULL, Comment TEXT)"), + new Migration(2, "INSERT INTO Legs SELECT LegID, TripID, UserID, TrainType, TrainNr, DepStationID, DepStation, DepTime, ArrStationID, ArrStation, ArrTime, Comment FROM Legs_backup"), + new Migration(2, + "CREATE TEMPORARY TABLE Users_backup(\"UserID\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, \"Username\" TEXT NOT NULL UNIQUE, \"Password\" TEXT NOT NULL)"), + new Migration(2, + "INSERT INTO Users_backup SELECT UserID, Username, Password FROM Users"), + new Migration(2, "DROP Table Users"), + new Migration(2, + "CREATE TABLE Users(\"UserID\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, \"Username\" TEXT NOT NULL UNIQUE)"), + new Migration(2, "INSERT INTO Users SELECT UserID, Username FROM Users_backup"), + new Migration(2, "DROP TABLE Users_backup"), + new Migration(2, "DROP TABLE Legs_backup"), + new Migration(2, "DROP TABLE Tickets"), + new Migration(2, "DROP TABLE TicketLegs"), + new Migration(2, "DROP TABLE Cards") }; public static void RunMigrations() { @@ -33,10 +54,7 @@ public static class Migrations { Console.WriteLine("Initialize Database"); db.CreateTable(); - db.CreateTable(); db.CreateTable(); - db.CreateTable(); - db.CreateTable(); db.CreateTable(); db.CreateTable(); @@ -102,4 +120,4 @@ public static class Migrations { db.Execute(_sql); } } -} \ No newline at end of file +} diff --git a/trainav.web/Pages/Card.cshtml b/trainav.web/Pages/Card.cshtml deleted file mode 100644 index b5f870d..0000000 --- a/trainav.web/Pages/Card.cshtml +++ /dev/null @@ -1,16 +0,0 @@ -@page -@using Microsoft.AspNetCore.Http -@using Microsoft.AspNetCore.Http.Extensions -@model CardModel - -@{ - ViewData["Title"] = "Card"; - Response.Redirect("/Cards"); - - if (HttpContext.Session.GetString("authorized") != "true") { - Response.Redirect($"/Login?&redir={Request.GetDisplayUrl().UrlEncode()}"); - return; - } -} - -Card saved. Redirecting... \ No newline at end of file diff --git a/trainav.web/Pages/Card.cshtml.cs b/trainav.web/Pages/Card.cshtml.cs deleted file mode 100644 index 37eb30d..0000000 --- a/trainav.web/Pages/Card.cshtml.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Linq; -using System.Net; -using System.Xml; -using System.Xml.Linq; -using LinqToDB; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Newtonsoft.Json; -using trainav.web.database; -using trainav.web.database.Tables; -using trainav.web.JSON.CardResponse; -using trainav.web.JSON.ListOrdersResponse; - -namespace trainav.web.Pages; - -public class CardModel : PageModel { - public void OnPost() { - if (HttpContext.Session.GetString("authorized") != "true") - return; - - using var db = new Database.DbConn(); - var request = new XDocument(new XElement("rqorderheadlist", - new XElement("rqheader", new XAttribute("ts", "2020-02-19T15:59:00"), new XAttribute("l", "de"), new XAttribute("v", "19120000"), - new XAttribute("d", "iPad7,5"), new XAttribute("os", "iOS_13.3.1"), new XAttribute("app", "NAVIGATOR")), - new XElement("authlogin", new XAttribute("user", Request.Form["user"]), new XAttribute("pw", Request.Form["pass"]), - new XElement("sso", new XAttribute("genToken", "FALSE"))), - new XElement("criteria", new XAttribute("validonly", "0")))).ToString(); - var response = new WebClient().UploadString("https://fahrkarten.bahn.de/mobile/dbc/xs.go", "POST", request); - var xmlobj = new XmlDocument(); - xmlobj.LoadXml(response); - var json = JsonConvert.SerializeXmlNode(xmlobj); - var parsed = ListOrdersResponse.FromJson(json); - - foreach (var order in parsed.Rporderheadlist.Orderheadlist.Orderhead.Where(order => order.On.StartsWith("EBC_"))) { - request = new XDocument(new XElement("rqorderdetails", new XAttribute("version", "1.0"), - new XElement("rqheader", new XAttribute("ts", "2019-10-31T23:20:48"), new XAttribute("l", "de"), new XAttribute("v", "19100000"), - new XAttribute("d", "iPad7,5"), new XAttribute("os", "iOS_13.1.3"), new XAttribute("app", "NAVIGATOR")), - new XElement("rqorder", new XAttribute("on", order.On)), new XElement("authname", new XAttribute("tln", Request.Form["name"])))) - .ToString(); - - response = new WebClient().UploadString("https://fahrkarten.bahn.de/mobile/dbc/xs.go", "POST", request); - xmlobj = new XmlDocument(); - xmlobj.LoadXml(response); - json = JsonConvert.SerializeXmlNode(xmlobj); - var parsedCard = CardResponse.FromJson(json); - - db.InsertWithInt32Identity(new Card { - OrderId = order.On, - UserId = int.Parse(HttpContext.Session.GetString("uid")), - Class = int.Parse(parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "klasse").Text), - Value = int.Parse(parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "rbs").Text), - CardNumber = parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "bcnummer").Text, - CardInfo = parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Txt, - CardQr = parsedCard.Rporderdetails.Order.Tcklist.Tck.Htdata.Ht.First(p => p.Name == "barcode").Text, - CardSecCode = parsedCard.Rporderdetails.Order.Tcklist.Tck.Htdata.Ht.First(p => p.Name == "sichtmerkmal").Text, - CardImage = parsedCard.Rporderdetails.Order.Tcklist.Tck.Bahncardimage.CdataSection, - Traveller = parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "inhaber").Text, - ValidFrom = parsedCard.Rporderdetails.Order.Vfrom, - ValidTo = parsedCard.Rporderdetails.Order.Vto, - QrValidFrom = parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "ebcbarcodegueltigab").Text, - QrValidTo = parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "ebcbarcodegueltigbis").Text - }); - } - } -} \ No newline at end of file diff --git a/trainav.web/Pages/Cards.cshtml b/trainav.web/Pages/Cards.cshtml deleted file mode 100644 index 3641ec8..0000000 --- a/trainav.web/Pages/Cards.cshtml +++ /dev/null @@ -1,169 +0,0 @@ -@page -@using Microsoft.AspNetCore.Http -@using Microsoft.AspNetCore.Http.Extensions -@using System.Text -@model CardsModel -@{ - ViewData["Title"] = "Cards"; - - if (HttpContext.Session.GetString("authorized") != "true") { - Response.Redirect($"/Login?&redir={Request.GetDisplayUrl().UrlEncode()}"); - return; - } - - if (Request.Query.ContainsKey("refresh")) { - Response.Redirect("?edit=true"); - return; - } -} - -@if (Request.Query["edit"] == "true") { - - - - - - - - - - - - - @foreach (var card in Model.Cards) { - - - - - - - - - } - -
CardNumberTravellerCard ValidityQR ValidityActions
@card.CardInfo.TrimEnd('#')@card.CardNumber@card.Traveller - @{ - var from = DateTime.Parse(card.ValidFrom); - var to = DateTime.Parse(card.ValidTo); - if (from > DateTime.Now) { - - @card.ValidFrom.Split("T")[0] - - } - else { - @card.ValidFrom.Split("T")[0] - } -
- if (to < DateTime.Now) { - - @card.ValidTo.Split("T")[0] - - } - else { - @card.ValidTo.Split("T")[0] - } - } -
- @{ - var qrfrom = DateTime.Parse(card.QrValidFrom); - var qrto = DateTime.Parse(card.QrValidTo); - if (qrfrom > DateTime.Now) { - - @card.QrValidFrom.Split("T")[0] - - } - else { - @card.QrValidFrom.Split("T")[0] - } -
- if (qrto < DateTime.Now) { - - @card.QrValidTo.Split("T")[0] - - } - else { - @card.QrValidTo.Split("T")[0] - } - } -
- Refresh QR - Delete -
-

- Please refresh your BahnCard list in the mobile DB Navigator before clicking "Refresh QR". This will be fixed in a later release. -

- Back -
-
-
-} -else if (Model.Cards.Any()) { - foreach (var card in Model.Cards) { - if (!card.CardQr.StartsWith("data:image/png")) - card.CardQr = Encoding.UTF8.GetString(Convert.FromBase64String(card.CardQr)); - if (!card.CardSecCode.StartsWith("data:image/png")) - card.CardSecCode = Encoding.UTF8.GetString(Convert.FromBase64String(card.CardSecCode)); - if (!card.CardImage.StartsWith(" -
- Ticketcode -
-
- Sichtmerkmal -
-
-
- Bahncardimage -
-
- - var from = DateTime.Parse(card.ValidFrom); - var to = DateTime.Parse(card.ValidTo); - var qrfrom = DateTime.Parse(card.QrValidFrom); - var qrto = DateTime.Parse(card.QrValidTo); - - if (from > DateTime.Now) { - - } - if (to < DateTime.Now) { - - } - if (qrfrom > DateTime.Now && !(from > DateTime.Now)) { - - } - if (qrto < DateTime.Now) { - - } -
- } -
- Edit cards -} - -@if (!Model.Cards.Any() || Request.Query["edit"] == "true") { -

Get Cards from bahn.de account

-
-
-
- -
-
- -
-
- -
- @Html.AntiForgeryToken() - -
-} diff --git a/trainav.web/Pages/Cards.cshtml.cs b/trainav.web/Pages/Cards.cshtml.cs deleted file mode 100644 index fc74f36..0000000 --- a/trainav.web/Pages/Cards.cshtml.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Xml; -using System.Xml.Linq; -using LinqToDB; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Newtonsoft.Json; -using trainav.web.database; -using trainav.web.database.Tables; -using trainav.web.JSON.CardResponse; - -namespace trainav.web.Pages; - -public class CardsModel : PageModel { - public List Cards; - - public void OnGet() { - if (HttpContext.Session.GetString("authorized") != "true") - return; - - using var db = new Database.DbConn(); - - if (Request.Query.ContainsKey("refresh")) { - var card = db.Cards.First(p => p.CardId == int.Parse(Request.Query["refresh"])); - if (card.UserId != int.Parse(HttpContext.Session.GetString("uid"))) - return; - - var request = new XDocument(new XElement("rqorderdetails", new XAttribute("version", "1.0"), - new XElement("rqheader", new XAttribute("ts", "2019-10-31T23:20:48"), new XAttribute("l", "de"), - new XAttribute("v", "19100000"), new XAttribute("d", "iPad7,5"), new XAttribute("os", "iOS_13.1.3"), - new XAttribute("app", "NAVIGATOR")), new XElement("rqorder", new XAttribute("on", card.OrderId)), - new XElement("authname", new XAttribute("tln", card.Traveller.Split(" ").Last())))).ToString(); - - var response = new WebClient().UploadString("https://fahrkarten.bahn.de/mobile/dbc/xs.go", "POST", request); - var xmlobj = new XmlDocument(); - xmlobj.LoadXml(response); - var json = JsonConvert.SerializeXmlNode(xmlobj); - var parsedCard = CardResponse.FromJson(json); - - card.CardQr = parsedCard.Rporderdetails.Order.Tcklist.Tck.Htdata.Ht.First(p => p.Name == "barcode").Text; - card.CardSecCode = parsedCard.Rporderdetails.Order.Tcklist.Tck.Htdata.Ht.First(p => p.Name == "sichtmerkmal").Text; - card.CardImage = parsedCard.Rporderdetails.Order.Tcklist.Tck.Bahncardimage.CdataSection; - card.QrValidFrom = parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "ebcbarcodegueltigab").Text; - card.QrValidTo = parsedCard.Rporderdetails.Order.Tcklist.Tck.Mtk.Nvplist.Nvp.First(p => p.Name == "ebcbarcodegueltigbis").Text; - - db.Update(card); - return; - } - - Cards = db.Cards.Where(p => p.UserId == int.Parse(HttpContext.Session.GetString("uid"))).ToList(); - } -} \ No newline at end of file diff --git a/trainav.web/Pages/Delete.cshtml b/trainav.web/Pages/Delete.cshtml index 8cd0455..3f7ef94 100644 --- a/trainav.web/Pages/Delete.cshtml +++ b/trainav.web/Pages/Delete.cshtml @@ -2,68 +2,50 @@ @using Microsoft.AspNetCore.Http @using Microsoft.AspNetCore.Http.Extensions @using trainav.web.database +@using trainav.web.Utils @model DeleteModel @{ - ViewData["Title"] = "Home"; + ViewData["Title"] = "Home"; + + if (Request.Query.ContainsKey("confirm") && Request.Query["confirm"] == "true") { + Layout = null; - if (HttpContext.Session.GetString("authorized") != "true") { - Response.Redirect($"/Login?&redir={Request.GetDisplayUrl().UrlEncode()}"); - return; - } + if (Request.Query.ContainsKey("redir")) { + Response.Redirect(Request.Query["redir"]); + } + else { + Response.Redirect("/"); + } - if (Request.Query.ContainsKey("confirm") && Request.Query["confirm"] == "true") { - Layout = null; + return; + } - if (Request.Query.ContainsKey("redir")) { - Response.Redirect(Request.Query["redir"]); - } - else { - Response.Redirect("/"); - } +

Are you sure?

+

+ You are attempting to delete + @{ + await using var db = new Database.DbConn(); - return; - } + switch (Request.Query["item"]) { + case "trip": { + var trip = db.Trips.First(p => p.TripId == int.Parse(Request.Query["id"])); + if (trip.UserId != Model.AuthorizedUser.UserId) { + return; + } + var legs = db.Legs.Where(p => p.TripId == int.Parse(Request.Query["id"])).OrderBy(p => p.DepTime).ToList(); -

Are you sure?

-

- You are attempting to delete - @{ - await using var db = new Database.DbConn(); - - switch (Request.Query["item"]) { - case "trip": { - var trip = db.Trips.First(p => p.TripId == int.Parse(Request.Query["id"])); - if (trip.UserId != int.Parse(HttpContext.Session.GetString("uid"))) { - return; - } - var legs = db.Legs.Where(p => p.TripId == int.Parse(Request.Query["id"])).OrderBy(p => p.DepTime).ToList(); - - - the trip from @legs.First().DepStation to @legs.Last().ArrStation, starting @legs.First().DepTime - - break; - } - case "leg": { - Response.Redirect($"/Delete?item={Request.Query["item"]}&id={Request.Query["id"]}&confirm=true&redir={Request.Query["redir"].ToString().UrlEncode()}"); - break; - } - case "ticket": { - Response.Redirect($"/Delete?item={Request.Query["item"]}&id={Request.Query["id"]}&confirm=true&redir={Request.Query["redir"].ToString().UrlEncode()}"); - break; - } - case "card": { - var card = db.Cards.First(p => p.CardId == int.Parse(Request.Query["id"])); - if (card.UserId != int.Parse(HttpContext.Session.GetString("uid"))) { - return; - } - - the card @card.CardInfo.TrimEnd('#') with the number @card.CardNumber, owned by @card.Traveller - - break; - } - } - } -

- Cancel - Confirm -} \ No newline at end of file + + the trip from @legs.First().DepStation to @legs.Last().ArrStation, starting @legs.First().DepTime + + break; + } + case "leg": { + Response.Redirect($"/Delete?item={Request.Query["item"]}&id={Request.Query["id"]}&confirm=true&redir={Request.Query["redir"].ToString().UrlEncode()}"); + break; + } + } + } +

+ Cancel + Confirm +} diff --git a/trainav.web/Pages/Delete.cshtml.cs b/trainav.web/Pages/Delete.cshtml.cs index 632eda1..892bcf6 100644 --- a/trainav.web/Pages/Delete.cshtml.cs +++ b/trainav.web/Pages/Delete.cshtml.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.RazorPages; using trainav.web.database; using trainav.web.database.Tables; +using trainav.web.Utils; namespace trainav.web.Pages; @@ -11,21 +12,17 @@ public class DeleteModel : PageModel { public User AuthorizedUser; public void OnGet() { - if (HttpContext.Session.GetString("authorized") != "true") - return; - if (!Request.Query.ContainsKey("confirm") || Request.Query["confirm"] != "true") return; - var uid = int.Parse(HttpContext.Session.GetString("uid")); using var db = new Database.DbConn(); - AuthorizedUser = db.Users.FirstOrDefault(p => p.UserId == uid); + AuthorizedUser = db.Users.FirstOrDefault(p => p.Username == AuthUtil.GetRemoteUser(HttpContext, db)); var id = int.Parse(Request.Query["id"]); switch (Request.Query["item"]) { case "trip": { var trip = db.Trips.First(p => p.TripId == id); - if (trip.UserId != int.Parse(HttpContext.Session.GetString("uid"))) + if (trip.UserId != AuthorizedUser!.UserId) return; db.Trips.Delete(p => p.TripId == id); @@ -34,7 +31,7 @@ public class DeleteModel : PageModel { } case "leg": { var leg = db.Legs.First(p => p.LegId == id); - if (leg.UserId != int.Parse(HttpContext.Session.GetString("uid"))) + if (leg.UserId != AuthorizedUser!.UserId) return; var tripid = db.Legs.First(p => p.LegId == id).TripId; @@ -62,22 +59,6 @@ public class DeleteModel : PageModel { break; } - case "ticket": { - var leg = db.Legs.First(p => p.LegId == id); - if (leg.UserId != int.Parse(HttpContext.Session.GetString("uid"))) - return; - - db.Legs.Where(p => p.LegId == id).Set(p => p.TicketId, 0).Update(); - break; - } - case "card": { - var card = db.Cards.First(p => p.CardId == id); - if (card.UserId != int.Parse(HttpContext.Session.GetString("uid"))) - return; - - db.Cards.Delete(p => p.CardId == id); - break; - } } } -} \ No newline at end of file +} diff --git a/trainav.web/Pages/Index.cshtml b/trainav.web/Pages/Index.cshtml index 35b7e33..2f90e79 100644 --- a/trainav.web/Pages/Index.cshtml +++ b/trainav.web/Pages/Index.cshtml @@ -1,101 +1,97 @@ @page +@using LinqToDB @using Microsoft.AspNetCore.Http @using Microsoft.AspNetCore.Http.Extensions -@using LinqToDB +@using Microsoft.AspNetCore.Mvc.TagHelpers +@using trainav.web.Utils @using trainav.web.database @model IndexModel @{ - ViewData["Title"] = "Home"; + ViewData["Title"] = "Home"; }
- @if (HttpContext.Session.GetString("authorized") != "true") { -

Welcome

-

Please log in to see your personal plan.

- } - else { -

- Welcome, @Model.AuthorizedUser.Username -

-

- Here are your planned trips. -

- - - - - - - - - - - - @{ - await using var db = new Database.DbConn(); - var trips = db.Trips.Where(p => p.UserId == Model.AuthorizedUser.UserId).ToList(); +

+ Welcome, @Model.AuthorizedUser.Username +

+

+ Here are your planned trips. +

+
OriginViaDestinationCommentsActions
+ + + + + + + + + + + @{ + await using var db = new Database.DbConn(); + var trips = db.Trips.Where(p => p.UserId == Model.AuthorizedUser.UserId).ToList(); - foreach (var trip in trips.Where(trip => !db.Legs.Any(p => p.TripId == trip.TripId))) { - await db.DeleteAsync(trip); - trips = db.Trips.Where(p => p.UserId == Model.AuthorizedUser.UserId).ToList(); - } + foreach (var trip in trips.Where(trip => !db.Legs.Any(p => p.TripId == trip.TripId))) { + await db.DeleteAsync(trip); + trips = db.Trips.Where(p => p.UserId == Model.AuthorizedUser.UserId).ToList(); + } - foreach (var trip in trips.OrderBy(p => db.Legs.Where(a => a.TripId == p.TripId).OrderBy(leg => leg.DepTime).First().DepTime)) { - var legs = db.Legs.Where(p => p.TripId == trip.TripId).OrderBy(p => p.DepTime).ToList(); - - - - - - - - } - } - -
OriginViaDestinationCommentsActions
- @legs.First().DepStation.Delimit(30) -
- @DateTime.Parse(legs.First().DepTime).ToString("ddd dd.MM.yyyy, HH:mm") -
- @((from index in from leg in legs where leg.TrainType == "placeholder" select legs.IndexOf(leg) select legs[index - 1].ArrStation.Delimit(30)).ToList().DefaultIfEmpty("-").Aggregate((s1, s2) => $"{s1}, {s2}")) - - @legs.Last().ArrStation.Delimit(30) -
- @DateTime.Parse(legs.Last().ArrTime).ToString("ddd dd.MM.yyyy, HH:mm") -
- @Html.Raw(legs.Where(leg => !string.IsNullOrWhiteSpace(leg.Comment)).Select(p => p.Comment.Replace(", ", "
")).DefaultIfEmpty("").Aggregate((s1, s2) => $"{s1}
{s2}")) -
- View -   - Delete -
-
-
-
-
-

Add trip from ticket

-
-
- -
-
- -
-
- -
-
-
-
-

Add trip from oeffisear.ch or transit.ztn.sh

-
-
- -
-
- -
-
-
- } + foreach (var trip in trips.OrderBy(p => db.Legs.Where(a => a.TripId == p.TripId).OrderBy(leg => leg.DepTime).First().DepTime)) { + var legs = db.Legs.Where(p => p.TripId == trip.TripId).OrderBy(p => p.DepTime).ToList(); + + + @legs.First().DepStation.Delimit(30) +
+ @DateTime.Parse(legs.First().DepTime).ToString("ddd dd.MM.yyyy, HH:mm") + + + @((from index in from leg in legs where leg.TrainType == "placeholder" select legs.IndexOf(leg) select legs[index - 1].ArrStation.Delimit(30)).ToList().DefaultIfEmpty("-").Aggregate((s1, s2) => $"{s1}, {s2}")) + + + @legs.Last().ArrStation.Delimit(30) +
+ @DateTime.Parse(legs.Last().ArrTime).ToString("ddd dd.MM.yyyy, HH:mm") + + + @Html.Raw(legs.Where(leg => !string.IsNullOrWhiteSpace(leg.Comment)).Select(p => p.Comment.Replace(", ", "
")).DefaultIfEmpty("").Aggregate((s1, s2) => $"{s1}
{s2}")) + + + View +   + Delete + + + } + } + + +
+
+
+
+

Add trip from ticket

+
+
+ +
+
+ +
+
+ +
+
+
+
+

Add trip from oeffisear.ch or transit.ztn.sh

+
+
+ +
+
+ +
+
+
diff --git a/trainav.web/Pages/Index.cshtml.cs b/trainav.web/Pages/Index.cshtml.cs index 43b7c09..9073aba 100644 --- a/trainav.web/Pages/Index.cshtml.cs +++ b/trainav.web/Pages/Index.cshtml.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.RazorPages; using trainav.web.database; using trainav.web.database.Tables; +using trainav.web.Utils; namespace trainav.web.Pages; @@ -10,11 +11,7 @@ public class IndexModel : PageModel { public User AuthorizedUser; public void OnGet() { - if (HttpContext.Session.GetString("authorized") != "true") - return; - - var uid = int.Parse(HttpContext.Session.GetString("uid")); using var db = new Database.DbConn(); - AuthorizedUser = db.Users.FirstOrDefault(p => p.UserId == uid); + AuthorizedUser = db.Users.FirstOrDefault(p => p.Username == AuthUtil.GetRemoteUser(HttpContext, db)); } -} \ No newline at end of file +} diff --git a/trainav.web/Pages/Inspection.cshtml b/trainav.web/Pages/Inspection.cshtml deleted file mode 100644 index 4be46f1..0000000 --- a/trainav.web/Pages/Inspection.cshtml +++ /dev/null @@ -1,151 +0,0 @@ -@page -@using Microsoft.AspNetCore.Http -@using Microsoft.AspNetCore.Http.Extensions -@using trainav.web.database -@using System.Text -@model InspectionModel -@{ - ViewData["Title"] = "Inspection"; - - if (HttpContext.Session.GetString("authorized") != "true") { - Response.Redirect($"/Login?&redir={Request.GetDisplayUrl().UrlEncode()}"); - return; - } - - if (Model.Leg.UserId != int.Parse(HttpContext.Session.GetString("uid"))) { - return; - } -} - -

- Ticket for @Model.Leg.TrainType @Model.Leg.TrainNr from @Model.Leg.DepStation to @Model.Leg.ArrStation, starting @DateTime.Parse(Model.Leg.DepTime).ToString("yyyy-MM-dd HH:mm") -

-
-
- Ticketcode -
-
- Sichtmerkmal -
-
-
-
-@Model.Ticket.TicketInfo -
-
-@if (Model.Ticket.TicketInfo.Contains("BC 50")) { - await using var db = new Database.DbConn(); - if (db.Cards.Any(p => p.Value == 50 && p.Traveller == Model.Ticket.Traveller && p.UserId == Model.Leg.UserId)) { - var card = db.Cards.First(p => p.Value == 50 && p.Traveller == Model.Ticket.Traveller && p.UserId == Model.Leg.UserId); - - if (!card.CardQr.StartsWith("data:image/png")) - card.CardQr = Encoding.UTF8.GetString(Convert.FromBase64String(card.CardQr)); - if (!card.CardSecCode.StartsWith("data:image/png")) - card.CardSecCode = Encoding.UTF8.GetString(Convert.FromBase64String(card.CardSecCode)); - if (!card.CardImage.StartsWith(" -
- Ticketcode -
-
- Sichtmerkmal -
-
-
- Bahncardimage -
-
- - - var from = DateTime.Parse(card.ValidFrom); - var to = DateTime.Parse(card.ValidTo); - var qrfrom = DateTime.Parse(card.QrValidFrom); - var qrto = DateTime.Parse(card.QrValidTo); - - if (from > DateTime.Now) { - - } - if (to < DateTime.Now) { - - } - if (qrfrom > DateTime.Now && !(from > DateTime.Now)) { - - } - if (qrto < DateTime.Now) { - - } - } - else { - - } -} -else if (Model.Ticket.TicketInfo.Contains("BC 25")) { - await using var db = new Database.DbConn(); - if (db.Cards.Any(p => p.Value == 25 && p.Traveller == Model.Ticket.Traveller && p.UserId == Model.Leg.UserId)) { - var card = db.Cards.First(p => p.Value == 25 && p.Traveller == Model.Ticket.Traveller && p.UserId == Model.Leg.UserId); - - if (!card.CardQr.StartsWith("data:image/png")) - card.CardQr = Encoding.UTF8.GetString(Convert.FromBase64String(card.CardQr)); - if (!card.CardSecCode.StartsWith("data:image/png")) - card.CardSecCode = Encoding.UTF8.GetString(Convert.FromBase64String(card.CardSecCode)); - if (!card.CardImage.StartsWith(" -
- Ticketcode -
-
- Sichtmerkmal -
-
-
- Bahncardimage -
-
- - - var from = DateTime.Parse(card.ValidFrom); - var to = DateTime.Parse(card.ValidTo); - var qrfrom = DateTime.Parse(card.QrValidFrom); - var qrto = DateTime.Parse(card.QrValidTo); - - if (from > DateTime.Now) { - - } - if (to < DateTime.Now) { - - } - if (qrfrom > DateTime.Now && !(from > DateTime.Now)) { - - } - if (qrto < DateTime.Now) { - - } - } - else { - - } -} diff --git a/trainav.web/Pages/Inspection.cshtml.cs b/trainav.web/Pages/Inspection.cshtml.cs deleted file mode 100644 index b857253..0000000 --- a/trainav.web/Pages/Inspection.cshtml.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Linq; -using System.Text; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.RazorPages; -using trainav.web.database; -using trainav.web.database.Tables; - -namespace trainav.web.Pages; - -public class InspectionModel : PageModel { - public Leg Leg; - public Ticket Ticket; - - public void OnGet() { - if (HttpContext.Session.GetString("authorized") != "true") - return; - - using var db = new Database.DbConn(); - Leg = db.Legs.First(p => p.LegId == int.Parse(Request.Query["leg"])); - Ticket = db.Tickets.First(p => p.TicketId == Leg.TicketId); - - if (!Ticket.TicketQr.StartsWith("data:image/png")) - Ticket.TicketQr = Encoding.UTF8.GetString(Convert.FromBase64String(Ticket.TicketQr)); - - if (!Ticket.TicketSecCode.StartsWith("data:image/png")) - Ticket.TicketSecCode = Encoding.UTF8.GetString(Convert.FromBase64String(Ticket.TicketSecCode)); - } -} \ No newline at end of file diff --git a/trainav.web/Pages/Login.cshtml b/trainav.web/Pages/Login.cshtml deleted file mode 100644 index 2b7267e..0000000 --- a/trainav.web/Pages/Login.cshtml +++ /dev/null @@ -1,30 +0,0 @@ -@page -@using Microsoft.AspNetCore.Http -@model LoginModel - -@{ - ViewData["Title"] = "Login"; - if (HttpContext.Session.GetString("authorized") == "true") { - if (Request.Query.ContainsKey("redir")) { - Response.Redirect(Request.Query["redir"]); - } - else { - Response.Redirect("/"); - } - return; - } -} - -

@ViewData["Title"]

- -
-
- - -
-
- - -
- -
\ No newline at end of file diff --git a/trainav.web/Pages/Logout.cshtml b/trainav.web/Pages/Logout.cshtml deleted file mode 100644 index e3147e1..0000000 --- a/trainav.web/Pages/Logout.cshtml +++ /dev/null @@ -1,7 +0,0 @@ -@page -@model LogoutModel - -@{ - Layout = null; - Response.Redirect("/"); -} \ No newline at end of file diff --git a/trainav.web/Pages/Logout.cshtml.cs b/trainav.web/Pages/Logout.cshtml.cs deleted file mode 100644 index f5c6cc2..0000000 --- a/trainav.web/Pages/Logout.cshtml.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Microsoft.AspNetCore.Mvc.RazorPages; - -namespace trainav.web.Pages; - -public class LogoutModel : PageModel { - public void OnGet() { - HttpContext.Session.Clear(); - } -} \ No newline at end of file diff --git a/trainav.web/Pages/OEAPI.cshtml b/trainav.web/Pages/OEAPI.cshtml index b13f3b6..e2979ac 100644 --- a/trainav.web/Pages/OEAPI.cshtml +++ b/trainav.web/Pages/OEAPI.cshtml @@ -1,16 +1,12 @@ @page @using Microsoft.AspNetCore.Http @using Microsoft.AspNetCore.Http.Extensions +@using trainav.web.Utils @model OEAPIModel @{ - ViewData["Title"] = "OEAPI"; + ViewData["Title"] = "OEAPI"; - if (HttpContext.Session.GetString("authorized") != "true") { - Response.Redirect($"/Login?&redir={Request.GetDisplayUrl().UrlEncode()}"); - return; - } - - Response.Redirect("/Trip?id=" + Model.TripId + "&edit=true"); + Response.Redirect("/Trip?id=" + Model.TripId + "&edit=true"); } -Trip saved. Redirecting... \ No newline at end of file +Trip saved. Redirecting... diff --git a/trainav.web/Pages/OEAPI.cshtml.cs b/trainav.web/Pages/OEAPI.cshtml.cs index 990d72d..69159fb 100644 --- a/trainav.web/Pages/OEAPI.cshtml.cs +++ b/trainav.web/Pages/OEAPI.cshtml.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using trainav.web.database; using trainav.web.database.Tables; using trainav.web.JSON; +using trainav.web.Utils; using Leg = trainav.web.database.Tables.Leg; // ReSharper disable PossibleInvalidOperationException @@ -18,9 +19,6 @@ public class OEAPIModel : PageModel { public int TripId; public void OnGet() { - if (HttpContext.Session.GetString("authorized") != "true") - return; - var link = Request.Query["link"].ToString(); var shortcode = link; var oepage = "oeffisear.ch"; @@ -40,13 +38,15 @@ public class OEAPIModel : PageModel { var parsed = OeapiResponse.FromJson(response); + var authorizedUser = db.Users.FirstOrDefault(p => p.Username == AuthUtil.GetRemoteUser(HttpContext, db)); + if (!string.IsNullOrWhiteSpace(Request.Query["tripid"].ToString())) - if (db.Trips.First(p => p.TripId == int.Parse(Request.Query["tripid"].ToString())).UserId != int.Parse(HttpContext.Session.GetString("uid"))) + if (db.Trips.First(p => p.TripId == int.Parse(Request.Query["tripid"].ToString())).UserId != authorizedUser!.UserId) return; var tripId = Request.Query["action"] == "addleg" ? int.Parse(Request.Query["tripid"]) - : db.InsertWithInt32Identity(new Trip { UserId = int.Parse(HttpContext.Session.GetString("uid")) }); + : db.InsertWithInt32Identity(new Trip { UserId = authorizedUser!.UserId }); foreach (var journey in parsed.Data.Journeys[jid].Legs.Where(p => p.IsTransfer != true && p.IsWalking != true)) { var arrtime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); @@ -62,7 +62,7 @@ public class OEAPIModel : PageModel { db.InsertWithInt32Identity(new Leg { TripId = tripId, - UserId = int.Parse(HttpContext.Session.GetString("uid")), + UserId = authorizedUser!.UserId, TrainType = journey.Line.ProductName, TrainNr = trainNo, ArrStation = journey.Arrival.Point.Stop.Name, @@ -76,4 +76,4 @@ public class OEAPIModel : PageModel { TripId = tripId; } -} \ No newline at end of file +} diff --git a/trainav.web/Pages/Plain.cshtml b/trainav.web/Pages/Plain.cshtml deleted file mode 100644 index db46bda..0000000 --- a/trainav.web/Pages/Plain.cshtml +++ /dev/null @@ -1,44 +0,0 @@ -@page -@using Microsoft.AspNetCore.Http -@using Microsoft.AspNetCore.Http.Extensions -@using trainav.web.database -@model PlainModel -@{ - ViewData["Title"] = "Plain"; - - if (HttpContext.Session.GetString("authorized") != "true") { - Response.Redirect($"/Login?&redir={Request.GetDisplayUrl().UrlEncode()}"); - return; - } - await using var db = new Database.DbConn(); -} - -
- - @foreach (var trip in db.Trips.Where(p => p.UserId == Model.AuthorizedUser.UserId).ToList().OrderBy(p => db.Legs.Where(l => l.TripId == p.TripId).OrderBy(l => l.DepTime).First().DepTime)) { -
-   -
- foreach (var leg in db.Legs.Where(p => p.TripId == trip.TripId).OrderBy(p => p.DepTime)) { - if (leg.TrainType == "placeholder") { -
- ... ...    ..:.. ...                  -   ... ...    -   ..:.. ...                  ... -
- continue; - } - var deptime = DateTime.Parse(leg.DepTime); - var arrtime = DateTime.Parse(leg.ArrTime); - var date = DateTime.Parse(leg.DepTime).ToString("ddd dd.MM."); - var dept = date + " " + deptime.ToString("HH:mm"); - var depst = leg.DepStation.PadRight(20, ' ').Substring(0, 20).Replace(" ", " "); - var arrt = arrtime.ToString("HH:mm"); - var arrst = leg.ArrStation.PadRight(20, ' ').Substring(0, 20).Replace(" ", " "); - var line = leg.TrainType.PadRight(3).Replace(" ", " ") + " " + leg.TrainNr.ToString().PadRight(6).Replace(" ", " "); - var comment = leg.Comment; -
- @dept @Html.Raw(depst) -   @Html.Raw(line) -   @arrt @Html.Raw(arrst) @(string.IsNullOrWhiteSpace(comment) ? "..." : comment) -
- } - } -
-
\ No newline at end of file diff --git a/trainav.web/Pages/Plain.cshtml.cs b/trainav.web/Pages/Plain.cshtml.cs deleted file mode 100644 index 5e167e2..0000000 --- a/trainav.web/Pages/Plain.cshtml.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Linq; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.RazorPages; -using trainav.web.database; -using trainav.web.database.Tables; - -namespace trainav.web.Pages; - -public class PlainModel : PageModel { - public User AuthorizedUser; - - public void OnGet() { - if (HttpContext.Session.GetString("authorized") != "true") - return; - - var uid = int.Parse(HttpContext.Session.GetString("uid")); - using var db = new Database.DbConn(); - AuthorizedUser = db.Users.FirstOrDefault(p => p.UserId == uid); - } -} \ No newline at end of file diff --git a/trainav.web/Pages/Register.cshtml b/trainav.web/Pages/Register.cshtml deleted file mode 100644 index 75d6891..0000000 --- a/trainav.web/Pages/Register.cshtml +++ /dev/null @@ -1,29 +0,0 @@ -@page -@using Microsoft.AspNetCore.Http -@model RegisterModel - -@{ - ViewData["Title"] = "Register"; - if (HttpContext.Session.GetString("authorized") == "true") { - Response.Redirect("/"); - return; - } -} - -

@ViewData["Title"]

- -
-
- - -
-
- - -
-
- - -
- -
\ No newline at end of file diff --git a/trainav.web/Pages/Register.cshtml.cs b/trainav.web/Pages/Register.cshtml.cs deleted file mode 100644 index b188eca..0000000 --- a/trainav.web/Pages/Register.cshtml.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Linq; -using LinqToDB; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.RazorPages; -using trainav.web.database; -using trainav.web.database.Tables; - -namespace trainav.web.Pages; - -public class RegisterModel : PageModel { - public void OnPost() { - if (!Request.HasFormContentType - || string.IsNullOrWhiteSpace(Request.Form["user"]) - || string.IsNullOrWhiteSpace(Request.Form["pass"]) - || string.IsNullOrWhiteSpace(Request.Form["code"])) - return; - - if (Request.Form["code"] != System.IO.File.ReadAllLines("regkey.txt")[0]) - return; - - using var db = new Database.DbConn(); - var user = db.Users.FirstOrDefault(p => p.Username == Request.Form["user"].ToString()); - if (user != null) - return; //user already exists - - var uid = db.InsertWithInt32Identity(new User { Username = Request.Form["user"].ToString(), Password = Request.Form["pass"].ToString().Sha256() }); - - HttpContext.Session.SetString("uid", uid.ToString()); - HttpContext.Session.SetString("authorized", "true"); - } -} diff --git a/trainav.web/Pages/Shared/_Layout.cshtml b/trainav.web/Pages/Shared/_Layout.cshtml index 1476992..4614785 100644 --- a/trainav.web/Pages/Shared/_Layout.cshtml +++ b/trainav.web/Pages/Shared/_Layout.cshtml @@ -1,67 +1,41 @@ -@using Microsoft.AspNetCore.Http - + - - - @ViewData["Title"] - Trainav - - + + + @ViewData["Title"] - Trainav + +
- +
-
- @RenderBody() -
+
+ @RenderBody() +
-
- © 2020-@DateTime.Now.Year - Laura Hausmann - Privacy -
+
+ © 2020-@DateTime.Now.Year - Laura Hausmann - Privacy +
@@ -70,4 +44,4 @@ @RenderSection("Scripts", false) - + \ No newline at end of file diff --git a/trainav.web/Pages/Ticket.cshtml b/trainav.web/Pages/Ticket.cshtml deleted file mode 100644 index 87e78ac..0000000 --- a/trainav.web/Pages/Ticket.cshtml +++ /dev/null @@ -1,16 +0,0 @@ -@page -@using Microsoft.AspNetCore.Http -@using Microsoft.AspNetCore.Http.Extensions -@model TicketModel -@{ - ViewData["Title"] = "Ticket"; - - if (HttpContext.Session.GetString("authorized") != "true") { - Response.Redirect($"/Login?&redir={Request.GetDisplayUrl().UrlEncode()}"); - return; - } - - Response.Redirect("/Trip?id=" + Model.TripId + "&edit=true"); -} - -Ticket saved. Redirecting... \ No newline at end of file diff --git a/trainav.web/Pages/Ticket.cshtml.cs b/trainav.web/Pages/Ticket.cshtml.cs deleted file mode 100644 index ce29ae6..0000000 --- a/trainav.web/Pages/Ticket.cshtml.cs +++ /dev/null @@ -1,255 +0,0 @@ -using System; -using System.Linq; -using System.Net; -using System.Xml; -using System.Xml.Linq; -using LinqToDB; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Newtonsoft.Json; -using trainav.web.database; -using trainav.web.database.Tables; -using trainav.web.JSON; -using Leg = trainav.web.database.Tables.Leg; - -namespace trainav.web.Pages; - -public class TicketModel : PageModel { - public int TripId; - - public void OnGet() { - if (HttpContext.Session.GetString("authorized") != "true") - return; - - using var db = new Database.DbConn(); - if (!string.IsNullOrWhiteSpace(Request.Query["tripid"].ToString())) - if (db.Trips.First(p => p.TripId == int.Parse(Request.Query["tripid"].ToString())).UserId != int.Parse(HttpContext.Session.GetString("uid"))) - return; - - if (db.Tickets.Any(p => p.OrderId == Request.Query["order"].ToString())) { - var tripId = Request.Query["action"] == "addleg" - ? int.Parse(Request.Query["tripid"]) - : db.InsertWithInt32Identity(new Trip { UserId = int.Parse(HttpContext.Session.GetString("uid")) }); - var ticketId = db.Tickets.First(p => p.OrderId == Request.Query["order"].ToString()).TicketId; - var ticketId2 = db.Tickets.FirstOrDefault(p => p.OrderId == Request.Query["order"] + "_2")?.TicketId; - - var lastleg_ticket = 0; - foreach (var leg in db.TicketLegs.Where(p => p.TicketId == ticketId).ToList()) { - if (leg.TrainType == "placeholder") { - db.Insert(new database.Tables.Leg { - TripId = tripId, - UserId = int.Parse(HttpContext.Session.GetString("uid")), - TrainType = "placeholder", - TrainNr = lastleg_ticket, - ArrStation = "_", - ArrStationId = 0, - ArrTime = "_", - DepStation = "_", - DepStationId = 0, - DepTime = db.Legs.First(p => p.LegId == lastleg_ticket).DepTime + "_placeholder" - }); - continue; - } - - lastleg_ticket = db.InsertWithInt32Identity(new database.Tables.Leg { - TripId = tripId, - UserId = int.Parse(HttpContext.Session.GetString("uid")), - TrainType = leg.TrainType, - TrainNr = leg.TrainNr, - ArrStation = leg.ArrStation, - ArrStationId = leg.ArrStationId, - ArrTime = leg.ArrTime, - DepStation = leg.DepStation, - DepStationId = leg.DepStationId, - DepTime = leg.DepTime, - TicketId = leg.TicketId - }); - } - - if (ticketId2 != null) { - var lastleg = 0; - - foreach (var leg in db.TicketLegs.Where(p => p.TicketId == ticketId2).ToList()) - db.InsertWithInt32Identity(new database.Tables.Leg { - TripId = tripId, - UserId = int.Parse(HttpContext.Session.GetString("uid")), - TrainType = leg.TrainType, - TrainNr = leg.TrainNr, - ArrStation = leg.ArrStation, - ArrStationId = leg.ArrStationId, - ArrTime = leg.ArrTime, - DepStation = leg.DepStation, - DepStationId = leg.DepStationId, - DepTime = leg.DepTime, - TicketId = leg.TicketId - }); - } - - TripId = tripId; - } - - else { - var request = new XDocument(new XElement("rqorderdetails", new XAttribute("version", "1.0"), - new XElement("rqheader", new XAttribute("ts", "2019-10-31T23:20:48"), new XAttribute("l", "de"), - new XAttribute("v", "19100000"), new XAttribute("d", "iPad7,5"), new XAttribute("os", "iOS_13.1.3"), - new XAttribute("app", "NAVIGATOR")), new XElement("rqorder", new XAttribute("on", Request.Query["order"])), - new XElement("authname", new XAttribute("tln", Request.Query["name"])))).ToString(); - var response = new WebClient().UploadString("https://fahrkarten.bahn.de/mobile/dbc/xs.go", "POST", request); - var xmlobj = new XmlDocument(); - xmlobj.LoadXml(response); - var json = JsonConvert.SerializeXmlNode(xmlobj); - var parsed = TicketResponse.FromJson(json); - - var tripId = Request.Query["action"] == "addleg" - ? int.Parse(Request.Query["tripid"]) - : db.InsertWithInt32Identity(new Trip { UserId = int.Parse(HttpContext.Session.GetString("uid")) }); - - int ticketId; - int? ticketId2 = null; - - switch (parsed.Rporderdetails.Order.Tcklist.Tck.Count) { - case 1: { - ticketId = db.InsertWithInt32Identity(new Ticket { - OrderId = Request.Query["order"], - TicketInfo = parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.Txt, - TicketQr = parsed.Rporderdetails.Order.Tcklist.Tck[0].Htdata.Ht.First(p => p.Name == "barcode").Text, - TicketSecCode = parsed.Rporderdetails.Order.Tcklist.Tck[0].Htdata.Ht.First(p => p.Name == "sichtmerkmal").Text, - UserId = int.Parse(HttpContext.Session.GetString("uid")), - TicketPkPass = - parsed.Rporderdetails.Order.Tcklist.Tck[0] - .Htdata.Ht.FirstOrDefault(p => p.Name == "pass") - ?.Text, // application/vnd.apple.pkpass;base64 - Traveller = parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.ReisenderVorname - + " " - + parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.ReisenderNachname - }); - break; - } - case 2: { - ticketId = db.InsertWithInt32Identity(new Ticket { - OrderId = Request.Query["order"], - TicketInfo = parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.Txt, - TicketQr = parsed.Rporderdetails.Order.Tcklist.Tck[0].Htdata.Ht.First(p => p.Name == "barcode").Text, - TicketSecCode = parsed.Rporderdetails.Order.Tcklist.Tck[0].Htdata.Ht.First(p => p.Name == "sichtmerkmal").Text, - UserId = int.Parse(HttpContext.Session.GetString("uid")), - TicketPkPass = - parsed.Rporderdetails.Order.Tcklist.Tck[0] - .Htdata.Ht.First(p => p.Name == "pass") - .Text, // application/vnd.apple.pkpass;base64 - Traveller = parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.ReisenderVorname - + " " - + parsed.Rporderdetails.Order.Tcklist.Tck[0].Mtk.ReisenderNachname - }); - - ticketId2 = db.InsertWithInt32Identity(new Ticket { - OrderId = Request.Query["order"] + "_2", - TicketInfo = parsed.Rporderdetails.Order.Tcklist.Tck[1].Mtk.Txt, - TicketQr = parsed.Rporderdetails.Order.Tcklist.Tck[1].Htdata.Ht.First(p => p.Name == "barcode").Text, - TicketSecCode = parsed.Rporderdetails.Order.Tcklist.Tck[1].Htdata.Ht.First(p => p.Name == "sichtmerkmal").Text, - UserId = int.Parse(HttpContext.Session.GetString("uid")), - TicketPkPass = - parsed.Rporderdetails.Order.Tcklist.Tck[1] - .Htdata.Ht.First(p => p.Name == "pass") - .Text, // application/vnd.apple.pkpass;base64 - Traveller = parsed.Rporderdetails.Order.Tcklist.Tck[1].Mtk.ReisenderVorname - + " " - + parsed.Rporderdetails.Order.Tcklist.Tck[1].Mtk.ReisenderNachname - }); - - break; - } - default: { - throw new Exception("Order contains zero or more than two tickets"); - } - } - - var lastleg = 0; - var lastticketleg = 0; - - foreach (var leg in parsed.Rporderdetails.Order.Schedulelist.Out.Trainlist.Train) { - lastleg = db.InsertWithInt32Identity(new database.Tables.Leg { - TripId = tripId, - UserId = int.Parse(HttpContext.Session.GetString("uid")), - TrainType = leg.Gattung, - TrainNr = int.Parse(leg.Zugnummer), - ArrStation = leg.Arr.Name, - ArrStationId = int.Parse(leg.Arr.BhfNr), - ArrTime = leg.Arr.Date.Replace("00:00:00", leg.Arr.Time), - DepStation = leg.Dep.Name, - DepStationId = int.Parse(leg.Dep.BhfNr), - DepTime = leg.Dep.Date.Replace("00:00:00", leg.Dep.Time), - TicketId = ticketId - }); - - lastticketleg = db.InsertWithInt32Identity(new TicketLeg { - TicketId = ticketId, - TrainType = leg.Gattung, - TrainNr = int.Parse(leg.Zugnummer), - ArrStation = leg.Arr.Name, - ArrStationId = int.Parse(leg.Arr.BhfNr), - ArrTime = leg.Arr.Date.Replace("00:00:00", leg.Arr.Time), - DepStation = leg.Dep.Name, - DepStationId = int.Parse(leg.Dep.BhfNr), - DepTime = leg.Dep.Date.Replace("00:00:00", leg.Dep.Time) - }); - } - - if (parsed.Rporderdetails.Order.Schedulelist.Ret != null) { - db.Insert(new database.Tables.Leg { - TripId = tripId, - UserId = int.Parse(HttpContext.Session.GetString("uid")), - TrainType = "placeholder", - TrainNr = lastleg, - ArrStation = "_", - ArrStationId = 0, - ArrTime = "_", - DepStation = "_", - DepStationId = 0, - DepTime = db.Legs.First(p => p.LegId == lastleg).DepTime + "_placeholder" - }); - - db.Insert(new TicketLeg { - TicketId = ticketId2 ?? ticketId, - TrainType = "placeholder", - TrainNr = lastticketleg, - ArrStation = "_", - ArrStationId = 0, - ArrTime = "_", - DepStation = "_", - DepStationId = 0, - DepTime = db.TicketLegs.First(p => p.TicketLegId == lastticketleg).DepTime + "_placeholder" - }); - - foreach (var leg in parsed.Rporderdetails.Order.Schedulelist.Ret.Trainlist.Train) { - db.InsertWithInt32Identity(new database.Tables.Leg { - TripId = tripId, - UserId = int.Parse(HttpContext.Session.GetString("uid")), - TrainType = leg.Gattung, - TrainNr = int.Parse(leg.Zugnummer), - ArrStation = leg.Arr.Name, - ArrStationId = int.Parse(leg.Arr.BhfNr), - ArrTime = leg.Arr.Date.Replace("00:00:00", leg.Arr.Time), - DepStation = leg.Dep.Name, - DepStationId = int.Parse(leg.Dep.BhfNr), - DepTime = leg.Dep.Date.Replace("00:00:00", leg.Dep.Time), - TicketId = ticketId2 ?? ticketId - }); - - db.InsertWithInt32Identity(new TicketLeg { - TicketId = ticketId2 ?? ticketId, - TrainType = leg.Gattung, - TrainNr = int.Parse(leg.Zugnummer), - ArrStation = leg.Arr.Name, - ArrStationId = int.Parse(leg.Arr.BhfNr), - ArrTime = leg.Arr.Date.Replace("00:00:00", leg.Arr.Time), - DepStation = leg.Dep.Name, - DepStationId = int.Parse(leg.Dep.BhfNr), - DepTime = leg.Dep.Date.Replace("00:00:00", leg.Dep.Time) - }); - } - } - - TripId = tripId; - } - } -} diff --git a/trainav.web/Pages/Trip.cshtml b/trainav.web/Pages/Trip.cshtml index 0b09515..abbd1a8 100644 --- a/trainav.web/Pages/Trip.cshtml +++ b/trainav.web/Pages/Trip.cshtml @@ -1,185 +1,170 @@ @page @using Microsoft.AspNetCore.Http @using Microsoft.AspNetCore.Http.Extensions +@using Microsoft.AspNetCore.Mvc.TagHelpers +@using trainav.web.Utils @model TripModel @{ - ViewData["Title"] = "Trip"; + ViewData["Title"] = "Trip"; - if (HttpContext.Session.GetString("authorized") != "true") { - Response.Redirect($"/Login?&redir={Request.GetDisplayUrl().UrlEncode()}"); - return; - } + if (Request.Query.ContainsKey("separator")) { + Response.Redirect(Request.Query["redir"]); + return; + } - if (Request.Query.ContainsKey("separator")) { - Response.Redirect(Request.Query["redir"]); - return; - } + if (Model.RedirToIndex) { + Response.Redirect("/"); + } - if (Model.RedirToIndex) { - Response.Redirect("/"); - } + if (Request.HasFormContentType) { + Response.Redirect(Request.GetEncodedUrl()); + return; + } - if (Request.HasFormContentType) { - Response.Redirect(Request.GetEncodedUrl()); - return; - } + if (!Model.Legs.Any()) { + Response.Redirect("/"); + return; + } - if (!Model.Legs.Any()) { - Response.Redirect("/"); - return; - } + if (Model.Legs.First().UserId != Model.AuthorizedUser.UserId) { + return; + } - if (Model.Legs.First().UserId != int.Parse(HttpContext.Session.GetString("uid"))) { - return; - } - - var dep = Model.Legs.First().DepStation; - var arr = Model.Legs.Last().ArrStation; + var dep = Model.Legs.First().DepStation; + var arr = Model.Legs.Last().ArrStation; }
-

- Your Trip from @dep to @arr, starting @DateTime.Parse(Model.Legs.First().DepTime).ToString("yyyy-MM-dd HH:mm") -

+

+ Your Trip from @dep to @arr, starting @DateTime.Parse(Model.Legs.First().DepTime).ToString("yyyy-MM-dd HH:mm") +

- - - - - - - - - @if (!Request.Query.ContainsKey("edit")) { - - } - else { - - } - - - - @foreach (var leg in Model.Legs) { - if (leg.TrainType == "placeholder") { - - - - - - @if (!Request.Query.ContainsKey("edit")) { - - } - else { - - } - continue; - } - var deptime = DateTime.Parse(leg.DepTime); - var arrtime = DateTime.Parse(leg.ArrTime); - var date = DateTime.Parse(leg.DepTime).ToString("ddd, dd.MM."); - var dept = deptime.ToString("HH:mm"); - var arrt = arrtime.ToString("HH:mm"); - - - - - - @if (!Request.Query.ContainsKey("edit")) { - - - } - else { - - + } + + } + +
DateDepartureArrivalTrainCommentActionsDanger zone
- - Separator -
- @date - - @dept @Html.Raw(leg.DepStation.PadRight(30, ' ').Substring(0, 30).TrimEnd()) - - @arrt @Html.Raw(leg.ArrStation.PadRight(30, ' ').Substring(0, 30).TrimEnd()) - @leg.TrainType @leg.TrainNr - @if (!string.IsNullOrWhiteSpace(leg.Comment)) { - @Html.Raw(leg.Comment) - } - - @if (leg.TicketId != 0) { - Ticket - } - else { - Ticket - } - Marudor - Travelynx - -
- - -
-
- @{ - if (Model.Legs.All(p => p.DepTime != leg.DepTime + "_placeholder") && Model.Legs.IndexOf(leg) != Model.Legs.Count - 1) { - + Separator - } - else { - + Separator - } + + + + + + + + + @if (!Request.Query.ContainsKey("edit")) { + + } + else { + + } + + + + @foreach (var leg in Model.Legs) { + if (leg.TrainType == "placeholder") { + + + + + + @if (!Request.Query.ContainsKey("edit")) { + + } + else { + + } + continue; + } + var deptime = DateTime.Parse(leg.DepTime); + var arrtime = DateTime.Parse(leg.ArrTime); + var date = DateTime.Parse(leg.DepTime).ToString("ddd, dd.MM."); + var dept = deptime.ToString("HH:mm"); + var arrt = arrtime.ToString("HH:mm"); + + + + + + @if (!Request.Query.ContainsKey("edit")) { + + + } + else { + + - } - - } - -
DateDepartureArrivalTrainCommentActionsDanger zone
+ - Separator +
+ @date + + @dept @Html.Raw(leg.DepStation.PadRight(30, ' ').Substring(0, 30).TrimEnd()) + + @arrt @Html.Raw(leg.ArrStation.PadRight(30, ' ').Substring(0, 30).TrimEnd()) + @leg.TrainType @leg.TrainNr + @if (!string.IsNullOrWhiteSpace(leg.Comment)) { + @Html.Raw(leg.Comment) + } + + Marudor + Travelynx + +
+ + +
+
+ @{ + if (Model.Legs.All(p => p.DepTime != leg.DepTime + "_placeholder") && Model.Legs.IndexOf(leg) != Model.Legs.Count - 1) { + + Separator + } + else { + + Separator + } - } - - Leg - @if (leg.TicketId != 0) { - - Ticket - } - else { - - Ticket - } -
+ } + - Leg +
@if (!Request.Query.ContainsKey("edit")) { - Share Trip - Download ICS - Edit Trip + Share Trip + Download ICS + Edit Trip } else { - Back -
-
-
-
-
-

Add leg(s) from ticket

-
- - -
- -
-
- -
-
- -
-
-
-
-

Add leg(s) from oeffisear.ch or transitztn.sh

-
- - -
- -
-
- -
-
-
+ Back +
+
+
+
+
+

Add leg(s) from ticket

+
+ + +
+ +
+
+ +
+
+ +
+
+
+
+

Add leg(s) from oeffisear.ch or transitztn.sh

+
+ + +
+ +
+
+ +
+
+
} diff --git a/trainav.web/Pages/Trip.cshtml.cs b/trainav.web/Pages/Trip.cshtml.cs index 55cffcd..9a459ee 100644 --- a/trainav.web/Pages/Trip.cshtml.cs +++ b/trainav.web/Pages/Trip.cshtml.cs @@ -5,27 +5,28 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.RazorPages; using trainav.web.database; using trainav.web.database.Tables; +using trainav.web.Utils; namespace trainav.web.Pages; public class TripModel : PageModel { public List Legs; public bool RedirToIndex; + public User AuthorizedUser; public new string User; public void OnGet() { - if (HttpContext.Session.GetString("authorized") != "true") - return; - using var db = new Database.DbConn(); + AuthorizedUser = db.Users.FirstOrDefault(p => p.Username == AuthUtil.GetRemoteUser(HttpContext, db)); + if (Request.Query.ContainsKey("separator")) { var leg = db.Legs.First(p => p.LegId == int.Parse(Request.Query["legid"])); - if (leg.UserId != int.Parse(HttpContext.Session.GetString("uid"))) + if (leg.UserId != AuthorizedUser!.UserId) return; db.Insert(new Leg { TripId = int.Parse(Request.Query["id"]), - UserId = int.Parse(HttpContext.Session.GetString("uid")), + UserId = AuthorizedUser.UserId, TrainType = "placeholder", TrainNr = int.Parse(Request.Query["legid"]), ArrStation = "_", @@ -49,19 +50,16 @@ public class TripModel : PageModel { } public void OnPost() { - if (HttpContext.Session.GetString("authorized") != "true") - return; - using var db = new Database.DbConn(); if (!Request.Form.ContainsKey("comment")) return; var leg = db.Legs.First(p => p.LegId == int.Parse(Request.Form["id"])); - if (leg.UserId != int.Parse(HttpContext.Session.GetString("uid"))) + if (leg.UserId != AuthorizedUser.UserId) return; leg.Comment = Request.Form["comment"]; db.Update(leg); } -} \ No newline at end of file +} diff --git a/trainav.web/Utils/AuthUtil.cs b/trainav.web/Utils/AuthUtil.cs new file mode 100644 index 0000000..0b5ab53 --- /dev/null +++ b/trainav.web/Utils/AuthUtil.cs @@ -0,0 +1,17 @@ +using System.Linq; +using LinqToDB; +using Microsoft.AspNetCore.Http; +using trainav.web.database; +using trainav.web.database.Tables; + +namespace trainav.web.Utils; + +public static class AuthUtil { + public static string GetRemoteUser(HttpContext ctx, Database.DbConn db) { + var remoteUser = ctx.Request.Headers["Remote-User"]; + if (!db.Users.Any(p => p.Username == remoteUser)) { + db.InsertWithInt32Identity(new User {Username = remoteUser}); + } + return ctx.Request.Headers["Remote-User"]; + } +} diff --git a/trainav.web/Pages/Login.cshtml.cs b/trainav.web/Utils/StringExtensions.cs similarity index 55% rename from trainav.web/Pages/Login.cshtml.cs rename to trainav.web/Utils/StringExtensions.cs index c4bb8f0..7dcd95d 100644 --- a/trainav.web/Pages/Login.cshtml.cs +++ b/trainav.web/Utils/StringExtensions.cs @@ -1,45 +1,20 @@ using System; -using System.Linq; using System.Security.Cryptography; using System.Text; using System.Web; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc.RazorPages; -using trainav.web.database; -namespace trainav.web.Pages; - -public class LoginModel : PageModel { - public void OnPost() { - if (!Request.HasFormContentType || string.IsNullOrWhiteSpace(Request.Form["user"]) || string.IsNullOrWhiteSpace(Request.Form["pass"])) - return; - - using var db = new Database.DbConn(); - var user = db.Users.FirstOrDefault(p => p.Username == Request.Form["user"].ToString() && p.Password == Request.Form["pass"].ToString().Sha256()); - if (user == null) - return; - - var uid = user.UserId; - HttpContext.Session.SetString("uid", uid.ToString()); - HttpContext.Session.SetString("authorized", "true"); - - //TODO - } -} +namespace trainav.web.Utils; public static class StringExtensions { public static string Sha256(this string rawData) { // Create a SHA256 using var sha256Hash = SHA256.Create(); - // ComputeHash - returns byte array var bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData)); - // Convert byte array to a string var builder = new StringBuilder(); for (var i = 0; i < bytes.Length; i++) builder.Append(bytes[i].ToString("x2")); - return builder.ToString(); } diff --git a/trainav.web/database/Database.cs b/trainav.web/database/Database.cs index d8586a1..2e440c0 100644 --- a/trainav.web/database/Database.cs +++ b/trainav.web/database/Database.cs @@ -32,9 +32,6 @@ public class Database { public ITable Users => GetTable(); public ITable Legs => GetTable(); - public ITable Tickets => GetTable(); - public ITable TicketLegs => GetTable(); public ITable Trips => GetTable(); - public ITable Cards => GetTable(); } -} \ No newline at end of file +} diff --git a/trainav.web/database/Tables/Card.cs b/trainav.web/database/Tables/Card.cs deleted file mode 100644 index 90a852f..0000000 --- a/trainav.web/database/Tables/Card.cs +++ /dev/null @@ -1,36 +0,0 @@ -using LinqToDB.Mapping; - -namespace trainav.web.database.Tables; - -[Table(Name = "Cards")] -public class Card { - [Column(Name = "CardID"), PrimaryKey, Identity, NotNull] public int CardId { get; set; } - - [Column(Name = "OrderID"), NotNull] public string OrderId { get; set; } - - [Column(Name = "UserID"), NotNull] public int UserId { get; set; } - - [Column(Name = "CardNumber"), NotNull] public string CardNumber { get; set; } - - [Column(Name = "Class"), NotNull] public int Class { get; set; } - - [Column(Name = "Value"), NotNull] public int Value { get; set; } - - [Column(Name = "Traveller")] public string Traveller { get; set; } - - [Column(Name = "CardQR")] public string CardQr { get; set; } - - [Column(Name = "CardSecCode")] public string CardSecCode { get; set; } - - [Column(Name = "CardImage")] public string CardImage { get; set; } - - [Column(Name = "CardInfo")] public string CardInfo { get; set; } - - [Column(Name = "ValidFrom")] public string ValidFrom { get; set; } - - [Column(Name = "ValidTo")] public string ValidTo { get; set; } - - [Column(Name = "QRValidFrom")] public string QrValidFrom { get; set; } - - [Column(Name = "QRValidTo")] public string QrValidTo { get; set; } -} \ No newline at end of file diff --git a/trainav.web/database/Tables/Leg.cs b/trainav.web/database/Tables/Leg.cs index 4c7e0c1..e6eeb95 100644 --- a/trainav.web/database/Tables/Leg.cs +++ b/trainav.web/database/Tables/Leg.cs @@ -26,7 +26,5 @@ public class Leg { [Column(Name = "ArrTime"), NotNull] public string ArrTime { get; set; } - [Column(Name = "TicketID")] public int TicketId { get; set; } - [Column(Name = "Comment")] public string Comment { get; set; } -} \ No newline at end of file +} diff --git a/trainav.web/database/Tables/Ticket.cs b/trainav.web/database/Tables/Ticket.cs deleted file mode 100644 index 08b85df..0000000 --- a/trainav.web/database/Tables/Ticket.cs +++ /dev/null @@ -1,22 +0,0 @@ -using LinqToDB.Mapping; - -namespace trainav.web.database.Tables; - -[Table(Name = "Tickets")] -public class Ticket { - [Column(Name = "TicketID"), PrimaryKey, Identity, NotNull] public int TicketId { get; set; } - - [Column(Name = "OrderID"), NotNull] public string OrderId { get; set; } - - [Column(Name = "UserID"), NotNull] public int UserId { get; set; } - - [Column(Name = "TicketInfo"), NotNull] public string TicketInfo { get; set; } - - [Column(Name = "TicketQR"), NotNull] public string TicketQr { get; set; } - - [Column(Name = "TicketSecCode"), NotNull] public string TicketSecCode { get; set; } - - [Column(Name = "TicketPkPass")] public string TicketPkPass { get; set; } - - [Column(Name = "Traveller")] public string Traveller { get; set; } -} \ No newline at end of file diff --git a/trainav.web/database/Tables/TicketLeg.cs b/trainav.web/database/Tables/TicketLeg.cs deleted file mode 100644 index 986ab80..0000000 --- a/trainav.web/database/Tables/TicketLeg.cs +++ /dev/null @@ -1,27 +0,0 @@ -using LinqToDB.Mapping; - -namespace trainav.web.database.Tables; - -[Table(Name = "TicketLegs")] -public class TicketLeg { - [Column(Name = "TicketLegID"), PrimaryKey, Identity, NotNull] - public int TicketLegId { get; set; } - - [Column(Name = "TicketID"), NotNull] public int TicketId { get; set; } - - [Column(Name = "TrainType"), NotNull] public string TrainType { get; set; } - - [Column(Name = "TrainNr"), NotNull] public int TrainNr { get; set; } - - [Column(Name = "DepStationID"), NotNull] public int DepStationId { get; set; } - - [Column(Name = "DepStation"), NotNull] public string DepStation { get; set; } - - [Column(Name = "DepTime"), NotNull] public string DepTime { get; set; } - - [Column(Name = "ArrStationID"), NotNull] public int ArrStationId { get; set; } - - [Column(Name = "ArrStation"), NotNull] public string ArrStation { get; set; } - - [Column(Name = "ArrTime"), NotNull] public string ArrTime { get; set; } -} \ No newline at end of file diff --git a/trainav.web/database/Tables/User.cs b/trainav.web/database/Tables/User.cs index e6c145f..f00d6dc 100644 --- a/trainav.web/database/Tables/User.cs +++ b/trainav.web/database/Tables/User.cs @@ -7,6 +7,4 @@ public class User { [Column(Name = "UserID"), PrimaryKey, Identity, NotNull] public int UserId { get; set; } [Column(Name = "Username"), NotNull] public string Username { get; set; } - - [Column(Name = "Password"), NotNull] public string Password { get; set; } -} \ No newline at end of file +} diff --git a/trainav.web/trainav.web.csproj b/trainav.web/trainav.web.csproj index 2865278..f060742 100644 --- a/trainav.web/trainav.web.csproj +++ b/trainav.web/trainav.web.csproj @@ -6,66 +6,27 @@ - - true - PreserveNewest - true PreserveNewest - - true - PreserveNewest - true PreserveNewest - - true - PreserveNewest - true PreserveNewest - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - Ticket.cshtml - - - Logout.cshtml - OEAPI.cshtml - - Inspection.cshtml - Delete.cshtml - - Cards.cshtml - - - Plain.cshtml - diff --git a/trainav.web/wwwroot/css/site.css b/trainav.web/wwwroot/css/site.css index fff0426..d84b609 100644 --- a/trainav.web/wwwroot/css/site.css +++ b/trainav.web/wwwroot/css/site.css @@ -2,105 +2,97 @@ for details on configuring this project to bundle and minify static web assets. */ a.navbar-brand { - white-space: normal; - text-align: center; - word-break: break-all; + white-space: normal; + text-align: center; + word-break: break-all; } /* Provide sufficient contrast against white background */ a { - color: #0366d6; + color: #0366d6; } /* oeffisear.ch link */ h3 a, h3 a:hover { - color: #212529; + color: #212529; } h3 a { - text-decoration: underline; - text-decoration-style: dotted; - text-decoration-thickness: 1.5pt; + text-decoration: underline; + text-decoration-style: dotted; + text-decoration-thickness: 1.5pt; } .btn-primary { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; } .nav-pills .nav-link.active, .nav-pills .show > .nav-link { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; } /* Sticky footer styles -------------------------------------------------- */ html { - font-size: 14px; + font-size: 14px; } + @media (min-width: 768px) { - html { - font-size: 16px; - } + html { + font-size: 16px; + } } .border-top { - border-top: 1px solid #e5e5e5; + border-top: 1px solid #e5e5e5; } + .border-bottom { - border-bottom: 1px solid #e5e5e5; + border-bottom: 1px solid #e5e5e5; } .box-shadow { - box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); + box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); } button.accept-policy { - font-size: 1rem; - line-height: inherit; + font-size: 1rem; + line-height: inherit; } /* Sticky footer styles -------------------------------------------------- */ html { - position: relative; - min-height: 100%; + position: relative; + min-height: 100%; } body { - /* Margin bottom by footer height */ - margin-bottom: 60px; + /* Margin bottom by footer height */ + margin-bottom: 60px; } + .footer { - position: absolute; - bottom: 0; - width: 100%; - white-space: nowrap; - line-height: 60px; /* Vertically center the text there */ + position: absolute; + bottom: 0; + width: 100%; + white-space: nowrap; + line-height: 60px; /* Vertically center the text there */ } td { - vertical-align: middle !important; + vertical-align: middle !important; } .flex-grid { - display: flex; - flex-wrap: wrap; + display: flex; + flex-wrap: wrap; } .flex-col { - margin: 3px 3px 10px; + margin: 3px 3px 10px; } - -.bahncard-outer { - width: 400px; - height: 260px; -} - -.bahncard { - height: 400px; - transform-origin: top left; - transform: rotate(-90deg) translate(-100%); -} \ No newline at end of file