aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Utils
diff options
context:
space:
mode:
authorRoy Ben Shabat <roy.mail.net@gmail.com>2025-09-07 06:47:24 +0300
committerRoy Ben Shabat <roy.mail.net@gmail.com>2025-09-07 06:47:24 +0300
commit9ba1902ee9dbac3b3c48d735b3bbcc3ba867dd2e (patch)
treeea0617d8dc1a4e83439a65b32e8720ab78a5c973 /Software/Visual_Studio_22/Tango.Portal.Chat.Web/Utils
parent2ff424e4b00ed154ae5febd1827d0d31d69c34ad (diff)
downloadTango-9ba1902ee9dbac3b3c48d735b3bbcc3ba867dd2e.tar.gz
Tango-9ba1902ee9dbac3b3c48d735b3bbcc3ba867dd2e.zip
Added seesion, chat history on ADX...
Diffstat (limited to 'Software/Visual_Studio_22/Tango.Portal.Chat.Web/Utils')
-rw-r--r--Software/Visual_Studio_22/Tango.Portal.Chat.Web/Utils/SessionUtils.cs36
1 files changed, 36 insertions, 0 deletions
diff --git a/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Utils/SessionUtils.cs b/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Utils/SessionUtils.cs
new file mode 100644
index 000000000..91f118e0d
--- /dev/null
+++ b/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Utils/SessionUtils.cs
@@ -0,0 +1,36 @@
+using Tango.Portal.Chat.Web.Models;
+
+namespace Tango.Portal.Chat.Web.Utils
+{
+ public class SessionUtils
+ {
+ public static void SetSessionUser(HttpContext context, SessionUser user)
+ {
+ if (context == null) throw new ArgumentNullException(nameof(context));
+ if (user == null) throw new ArgumentNullException(nameof(user));
+
+ var json = System.Text.Json.JsonSerializer.Serialize(user);
+ context.Session.SetString("SessionUser", json);
+ }
+
+ public static SessionUser? GetSessionUser(HttpContext context)
+ {
+ if (context == null) throw new ArgumentNullException(nameof(context));
+
+ var json = context.Session.GetString("SessionUser");
+ if (string.IsNullOrWhiteSpace(json))
+ {
+ return null;
+ }
+
+ return System.Text.Json.JsonSerializer.Deserialize<SessionUser>(json);
+ }
+
+ public static bool IsUserAuthenticated(HttpContext context)
+ {
+ if (context == null) throw new ArgumentNullException(nameof(context));
+ var user = GetSessionUser(context);
+ return user != null;
+ }
+ }
+}