-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gets user session management tracking via the database including dete…
…cting stale sessions, generating and removing them along with cleaning them up. This takes into account legacy code too. The session is revalidated on a one minute threshold per user so that it's not hammering the databse on every request.
- Loading branch information
Showing
31 changed files
with
665 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using Umbraco.Core.Persistence; | ||
using Umbraco.Core.Persistence.DatabaseAnnotations; | ||
|
||
namespace Umbraco.Core.Models.Rdbms | ||
{ | ||
[TableName("umbracoUserLogin")] | ||
[PrimaryKey("sessionId", autoIncrement = false)] | ||
[ExplicitColumns] | ||
internal class UserLoginDto | ||
{ | ||
[Column("sessionId")] | ||
[PrimaryKeyColumn(AutoIncrement = false)] | ||
public Guid SessionId { get; set; } | ||
|
||
[Column("userId")] | ||
[ForeignKey(typeof(UserDto), Name = "FK_umbracoUserLogin_umbracoUser_id")] | ||
public int UserId { get; set; } | ||
|
||
/// <summary> | ||
/// Tracks when the session is created | ||
/// </summary> | ||
[Column("loggedInUtc")] | ||
[NullSetting(NullSetting = NullSettings.NotNull)] | ||
public DateTime LoggedInUtc { get; set; } | ||
|
||
/// <summary> | ||
/// Updated every time a user's session is validated | ||
/// </summary> | ||
/// <remarks> | ||
/// This allows us to guess if a session is timed out if a user doesn't actively log out | ||
/// and also allows us to trim the data in the table | ||
/// </remarks> | ||
[Column("lastValidatedUtc")] | ||
[NullSetting(NullSetting = NullSettings.NotNull)] | ||
public DateTime LastValidatedUtc { get; set; } | ||
|
||
/// <summary> | ||
/// Tracks when the session is removed when the user's account is logged out | ||
/// </summary> | ||
[Column("loggedOutUtc")] | ||
[NullSetting(NullSetting = NullSettings.Null)] | ||
public DateTime? LoggedOutUtc { get; set; } | ||
|
||
/// <summary> | ||
/// Logs the IP address of the session if available | ||
/// </summary> | ||
[Column("ipAddress")] | ||
[NullSetting(NullSetting = NullSettings.Null)] | ||
public string IpAddress { get; set; } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
...aco.Core/Persistence/Migrations/Upgrades/TargetVersionSevenEightZero/AddUserLoginTable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Linq; | ||
using Umbraco.Core.Logging; | ||
using Umbraco.Core.Models.Rdbms; | ||
using Umbraco.Core.Persistence.SqlSyntax; | ||
|
||
namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenEightZero | ||
{ | ||
[Migration("7.8.0", 4, Constants.System.UmbracoMigrationName)] | ||
public class AddUserLoginTable : MigrationBase | ||
{ | ||
public AddUserLoginTable(ISqlSyntaxProvider sqlSyntax, ILogger logger) : base(sqlSyntax, logger) | ||
{ | ||
} | ||
|
||
public override void Up() | ||
{ | ||
var tables = SqlSyntax.GetTablesInSchema(Context.Database).ToArray(); | ||
|
||
if (tables.InvariantContains("umbracoUserLogin") == false) | ||
{ | ||
Create.Table<UserLoginDto>(); | ||
} | ||
} | ||
|
||
public override void Down() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.