From e30798270e70fcb7ba49c4b534a302bb8c344e9f Mon Sep 17 00:00:00 2001 From: Spirtix Date: Mon, 19 Jun 2023 20:33:49 +0200 Subject: [PATCH] Fix get/set pair issues - add mitmproxy endpoints - fix indentation - pass UserId and VikingId rather than session --- mitm-redirect.py | 2 +- src/Controllers/Common/ContentController.cs | 18 +++++------------- src/Services/KeyValueService.cs | 18 +++++++++--------- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/mitm-redirect.py b/mitm-redirect.py index c2d5f37..564c9e7 100644 --- a/mitm-redirect.py +++ b/mitm-redirect.py @@ -3,7 +3,7 @@ import mitmproxy.http def routable(path): - methods = ['GetRules', 'LoginParent', 'RegisterParent', 'GetSubscriptionInfo', 'GetUserInfoByApiToken', 'IsValidApiToken_V2', 'ValidateName', 'GetDefaultNameSuggestion', 'RegisterChild', 'GetProfileByUserId', 'LoginChild', 'GetUserProfileByUserID', 'GetKeyValuePair', 'SetKeyValuePair'] + methods = ['GetRules', 'LoginParent', 'RegisterParent', 'GetSubscriptionInfo', 'GetUserInfoByApiToken', 'IsValidApiToken_V2', 'ValidateName', 'GetDefaultNameSuggestion', 'RegisterChild', 'GetProfileByUserId', 'LoginChild', 'GetUserProfileByUserID', 'GetKeyValuePair', 'SetKeyValuePair', 'GetKeyValuePairByUserID', 'SetKeyValuePairByUserID'] for method in methods: if method in path: return True diff --git a/src/Controllers/Common/ContentController.cs b/src/Controllers/Common/ContentController.cs index ef3054e..276fb43 100644 --- a/src/Controllers/Common/ContentController.cs +++ b/src/Controllers/Common/ContentController.cs @@ -65,7 +65,7 @@ public class ContentController : Controller { return null; // Get the pair - Model.PairData? pair = keyValueService.GetPairData(session, pairId); + Model.PairData? pair = keyValueService.GetPairData(session.UserId, session.VikingId, pairId); return keyValueService.ModelToSchema(pair); } @@ -80,8 +80,8 @@ public class ContentController : Controller { Session? session = ctx.Sessions.FirstOrDefault(s => s.ApiToken == apiToken); if (session is null) return Ok(false); - - bool result = keyValueService.SetPairData(session, pairId, schemaData); + + bool result = keyValueService.SetPairData(session.UserId, session.VikingId, pairId, schemaData); return Ok(result); } @@ -94,11 +94,7 @@ public class ContentController : Controller { if (session is null) return null; - ctx.Entry(session).State = EntityState.Detached; // Don't update the entity - session.VikingId = null; - session.UserId = userId; - - Model.PairData? pair = keyValueService.GetPairData(session, pairId); + Model.PairData? pair = keyValueService.GetPairData(userId, null, pairId); return keyValueService.ModelToSchema(pair); } @@ -113,11 +109,7 @@ public class ContentController : Controller { if (session is null || string.IsNullOrEmpty(userId)) return Ok(false); - ctx.Entry(session).State = EntityState.Detached; // Don't update the entity - session.VikingId = null; - session.UserId = userId; - - bool result = keyValueService.SetPairData(session, pairId, schemaData); + bool result = keyValueService.SetPairData(userId, null, pairId, schemaData); return Ok(result); } diff --git a/src/Services/KeyValueService.cs b/src/Services/KeyValueService.cs index 10240c6..756b943 100644 --- a/src/Services/KeyValueService.cs +++ b/src/Services/KeyValueService.cs @@ -10,27 +10,27 @@ public class KeyValueService { this.ctx = ctx; } - public Model.PairData? GetPairData(Session session, int pairId) { + public Model.PairData? GetPairData(string? UserId, string? VikingId, int pairId) { Model.PairData? pair = null; - if (session.VikingId != null) - pair = ctx.PairData.FirstOrDefault(e => e.PairId == pairId && e.VikingId == session.VikingId); - else if (session.UserId != null) - pair = ctx.PairData.FirstOrDefault(e => e.PairId == pairId && e.UserId == session.UserId); + if (VikingId != null) + pair = ctx.PairData.FirstOrDefault(e => e.PairId == pairId && e.VikingId == VikingId); + else if (UserId != null) + pair = ctx.PairData.FirstOrDefault(e => e.PairId == pairId && e.UserId == UserId); return pair; } - public bool SetPairData(Session session, int pairId, Schema.PairData schemaData) { + public bool SetPairData(string? UserId, string? VikingId, int pairId, Schema.PairData schemaData) { // Get the pair - Model.PairData? pair = GetPairData(session, pairId); + Model.PairData? pair = GetPairData(UserId, VikingId, pairId); // Create the pair if it doesn't exist bool exists = true; if (pair is null) { pair = new Model.PairData { PairId = pairId, - UserId = session.UserId, - VikingId = session.VikingId, + UserId = UserId, + VikingId = VikingId, Pairs = new List() }; exists = false;