diff options
author | vnugent <public@vaughnnugent.com> | 2023-09-08 23:20:19 -0400 |
---|---|---|
committer | vnugent <public@vaughnnugent.com> | 2023-09-08 23:20:19 -0400 |
commit | dcf6f9dc0143eb50b702eb7dcd9e5dadd140537c (patch) | |
tree | 41efba0de085e6d49a0228b3f942824b2395383d /lib/Plugins.Essentials/src/Sessions | |
parent | c38d794d808b06240b778b5b320f506382215e29 (diff) |
Resource, argon2, accounts. sessions core updates
Diffstat (limited to 'lib/Plugins.Essentials/src/Sessions')
-rw-r--r-- | lib/Plugins.Essentials/src/Sessions/ISession.cs | 14 | ||||
-rw-r--r-- | lib/Plugins.Essentials/src/Sessions/SessionBase.cs | 5 | ||||
-rw-r--r-- | lib/Plugins.Essentials/src/Sessions/SessionInfo.cs | 14 |
3 files changed, 29 insertions, 4 deletions
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 /// </summary> SessionType SessionType { get; } + /// <summary> /// UTC time in when the session was created /// </summary> DateTimeOffset Created { get; } + /// <summary> /// Privilages associated with user specified during login /// </summary> ulong Privilages { get; set; } + /// <summary> /// Key that identifies the current session. (Identical to cookie::sessionid) /// </summary> string SessionID { get; } + /// <summary> /// User ID associated with session /// </summary> string UserID { get; set; } + /// <summary> /// Marks the session as invalid /// </summary> void Invalidate(bool all = false); + /// <summary> /// Gets or sets the session's authorization token /// </summary> string Token { get; set; } + /// <summary> /// The IP address belonging to the client /// </summary> IPAddress UserIP { get; } + /// <summary> /// Sets the session ID to be regenerated if applicable /// </summary> @@ -90,5 +98,11 @@ namespace VNLib.Plugins.Essentials.Sessions /// A value that indicates this session was newly created /// </summary> bool IsNew { get; } + + /// <summary> + /// This is a special function that requests the session to be detached from the current http connection + /// but allow it to remain available. + /// </summary> + 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 ///<inheritdoc/> [MethodImpl(MethodImplOptions.AggressiveInlining)] public virtual void RegenID() => Flags.Set(REGEN_ID_MSK); + + /// <inheritdoc/> + public virtual void Detach() => Flags.Set(DETACHED_MSK); + /// <summary> /// Invoked when the indexer is is called to /// </summary> 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 /// </summary> - [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Invalidate(bool all = false) => UserSession.Invalidate(all); + /// <summary> /// Marks the session ID to be regenerated during closing event /// </summary> - [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RegenID() => UserSession.RegenID(); + /// <summary> + /// Marks the session to be detached from the current connection. + /// </summary> + public void Detach() => UserSession.Detach(); + + #nullable disable + ///<inheritdoc/> - [MethodImpl(MethodImplOptions.AggressiveInlining)] public T GetObject<T>(string key) => JsonSerializer.Deserialize<T>(this[key], SR_OPTIONS); + ///<inheritdoc/> - [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetObject<T>(string key, T obj) => this[key] = obj == null ? null: JsonSerializer.Serialize(obj, SR_OPTIONS); + #nullable enable /// <summary> |