From f5ef33f16aedf8f9f60930de1d39836b309321e3 Mon Sep 17 00:00:00 2001 From: rfi Date: Sun, 15 Oct 2023 12:07:04 +0700 Subject: [PATCH] i forgor, the verify route for krsdk --- .../Controllers/AccountController.cs | 32 +++++++++++++++++++ AscNet.SDKServer/Models/AscNetAuth.cs | 3 ++ 2 files changed, 35 insertions(+) diff --git a/AscNet.SDKServer/Controllers/AccountController.cs b/AscNet.SDKServer/Controllers/AccountController.cs index 9838400..6bbe1e7 100644 --- a/AscNet.SDKServer/Controllers/AccountController.cs +++ b/AscNet.SDKServer/Controllers/AccountController.cs @@ -75,6 +75,38 @@ namespace AscNet.SDKServer.Controllers account }); }); + + app.MapPost("/api/AscNet/verify", (HttpContext ctx) => + { + AuthRequest? req = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(ctx.Request.BodyReader.ReadAsync().Result.Buffer)); + + if (req is null || req.Token == string.Empty) + { + return JsonConvert.SerializeObject(new + { + code = -1, + msg = "Invalid request" + }); + } + + Account? account = Account.FromToken(req.Token); + + if (account == null) + { + return JsonConvert.SerializeObject(new + { + code = -1, + msg = "Invalid credentials!" + }); + } + + return JsonConvert.SerializeObject(new + { + code = 0, + msg = "OK", + account + }); + }); } } } diff --git a/AscNet.SDKServer/Models/AscNetAuth.cs b/AscNet.SDKServer/Models/AscNetAuth.cs index df026b3..5168ede 100644 --- a/AscNet.SDKServer/Models/AscNetAuth.cs +++ b/AscNet.SDKServer/Models/AscNetAuth.cs @@ -10,5 +10,8 @@ namespace AscNet.SDKServer.Models [JsonProperty("password", NullValueHandling = NullValueHandling.Ignore)] public string Password { get; set; } + + [JsonProperty("token", NullValueHandling = NullValueHandling.Ignore)] + public string Token { get; set; } } }