From dcf6f9dc0143eb50b702eb7dcd9e5dadd140537c Mon Sep 17 00:00:00 2001 From: vnugent Date: Fri, 8 Sep 2023 23:20:19 -0400 Subject: Resource, argon2, accounts. sessions core updates --- lib/Plugins.Essentials/src/Sessions/ISession.cs | 14 ++++++++++++++ lib/Plugins.Essentials/src/Sessions/SessionBase.cs | 5 +++++ lib/Plugins.Essentials/src/Sessions/SessionInfo.cs | 14 ++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-) (limited to 'lib/Plugins.Essentials/src/Sessions') diff --git a/lib/Plugins.Essentials/src/Sessions/ISession.cs b/lib/Plugins.Essentials/src/Sessions/ISession.cs index e15c6e2..d2e0ee1 100644 --- a/lib/Plugins.Essentials/src/Sessions/ISession.cs +++ b/lib/Plugins.Essentials/src/Sessions/ISession.cs @@ -53,34 +53,42 @@ namespace VNLib.Plugins.Essentials.Sessions /// A value specifying the type of the loaded session /// SessionType SessionType { get; } + /// /// UTC time in when the session was created /// DateTimeOffset Created { get; } + /// /// Privilages associated with user specified during login /// ulong Privilages { get; set; } + /// /// Key that identifies the current session. (Identical to cookie::sessionid) /// string SessionID { get; } + /// /// User ID associated with session /// string UserID { get; set; } + /// /// Marks the session as invalid /// void Invalidate(bool all = false); + /// /// Gets or sets the session's authorization token /// string Token { get; set; } + /// /// The IP address belonging to the client /// IPAddress UserIP { get; } + /// /// Sets the session ID to be regenerated if applicable /// @@ -90,5 +98,11 @@ namespace VNLib.Plugins.Essentials.Sessions /// A value that indicates this session was newly created /// bool IsNew { get; } + + /// + /// This is a special function that requests the session to be detached from the current http connection + /// but allow it to remain available. + /// + void Detach(); } } \ No newline at end of file diff --git a/lib/Plugins.Essentials/src/Sessions/SessionBase.cs b/lib/Plugins.Essentials/src/Sessions/SessionBase.cs index 33a0dbd..038fd2c 100644 --- a/lib/Plugins.Essentials/src/Sessions/SessionBase.cs +++ b/lib/Plugins.Essentials/src/Sessions/SessionBase.cs @@ -40,6 +40,7 @@ namespace VNLib.Plugins.Essentials.Sessions protected const ulong IS_NEW_MSK = 0b0000000000000010UL; protected const ulong REGEN_ID_MSK = 0b0000000000000100UL; protected const ulong INVALID_MSK = 0b0000000000001000UL; + protected const ulong DETACHED_MSK = 0b0000000000010000UL; protected const ulong ALL_INVALID_MSK = 0b0000000000100000UL; protected const string USER_ID_ENTRY = "__.i.uid"; @@ -145,6 +146,10 @@ namespace VNLib.Plugins.Essentials.Sessions /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public virtual void RegenID() => Flags.Set(REGEN_ID_MSK); + + /// + public virtual void Detach() => Flags.Set(DETACHED_MSK); + /// /// Invoked when the indexer is is called to /// diff --git a/lib/Plugins.Essentials/src/Sessions/SessionInfo.cs b/lib/Plugins.Essentials/src/Sessions/SessionInfo.cs index a5d7c4d..d6d5456 100644 --- a/lib/Plugins.Essentials/src/Sessions/SessionInfo.cs +++ b/lib/Plugins.Essentials/src/Sessions/SessionInfo.cs @@ -224,21 +224,27 @@ namespace VNLib.Plugins.Essentials.Sessions /// Flags the session as invalid. IMPORTANT: the user's session data is no longer valid, no data /// will be saved to the session store when the session closes /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Invalidate(bool all = false) => UserSession.Invalidate(all); + /// /// Marks the session ID to be regenerated during closing event /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RegenID() => UserSession.RegenID(); + /// + /// Marks the session to be detached from the current connection. + /// + public void Detach() => UserSession.Detach(); + + #nullable disable + /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public T GetObject(string key) => JsonSerializer.Deserialize(this[key], SR_OPTIONS); + /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetObject(string key, T obj) => this[key] = obj == null ? null: JsonSerializer.Serialize(obj, SR_OPTIONS); + #nullable enable /// -- cgit