mirror of https://github.com/abpframework/abp.git
13 changed files with 160 additions and 0 deletions
@ -0,0 +1,10 @@ |
|||
namespace Volo.Abp.Identity; |
|||
|
|||
public class IdentitySessionConsts |
|||
{ |
|||
public static int MaxDeviceLength { get; set; } = 128; |
|||
|
|||
public static int MaxClientIdLength { get; set; } = 64; |
|||
|
|||
public static int MaxIpAddressesLength { get; set; } = 256; |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.Abp.Identity; |
|||
|
|||
public interface IIdentitySessionRepository : IBasicRepository<IdentitySession, Guid> |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,81 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.Abp.Identity; |
|||
|
|||
public class IdentitySession : BasicAggregateRoot<Guid> |
|||
{ |
|||
/// <summary>
|
|||
/// Web, CLI, STUDIO, ...
|
|||
/// </summary>
|
|||
public virtual string Device { get; protected set; } |
|||
|
|||
public virtual Guid? TenantId { get; protected set; } |
|||
|
|||
public virtual Guid UserId { get; protected set; } |
|||
|
|||
public virtual string ClientId { get; set; } |
|||
|
|||
public virtual string IpAddresses { get; protected set; } |
|||
|
|||
public virtual DateTime SignedIn { get; protected set; } |
|||
|
|||
public virtual DateTime? LastAccessed { get; protected set; } |
|||
|
|||
protected IdentitySession() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public IdentitySession( |
|||
Guid id, |
|||
string device, |
|||
Guid userId, |
|||
Guid? tenantId, |
|||
string clientId, |
|||
string ipAddresses, |
|||
DateTime signedIn, |
|||
DateTime? lastAccessed) |
|||
{ |
|||
Id = id; |
|||
Device = device; |
|||
UserId = userId; |
|||
TenantId = tenantId; |
|||
ClientId = clientId; |
|||
IpAddresses = ipAddresses; |
|||
SignedIn = signedIn; |
|||
LastAccessed = lastAccessed; |
|||
} |
|||
|
|||
public void SetSignedInTime(DateTime signedIn) |
|||
{ |
|||
SignedIn = signedIn; |
|||
} |
|||
|
|||
public void UpdateLastAccessedTime(DateTime? lastAccessed) |
|||
{ |
|||
LastAccessed = lastAccessed; |
|||
} |
|||
|
|||
public void SetIpAddresses(IEnumerable<string> ipAddresses) |
|||
{ |
|||
IpAddresses = JoinAsString(ipAddresses); |
|||
} |
|||
|
|||
public IEnumerable<string> GetIpAddresses() |
|||
{ |
|||
return GetArrayFromString(IpAddresses); |
|||
} |
|||
|
|||
private static string JoinAsString(IEnumerable<string> list) |
|||
{ |
|||
var serialized = string.Join(",", list); |
|||
return serialized.IsNullOrWhiteSpace() ? null : serialized; |
|||
} |
|||
|
|||
private string[] GetArrayFromString(string str) |
|||
{ |
|||
return str?.Split(",", StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>(); |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.Identity.EntityFrameworkCore; |
|||
|
|||
public class EfCoreIdentitySessionRepository : EfCoreRepository<IIdentityDbContext, IdentitySession, Guid>, IIdentitySessionRepository |
|||
{ |
|||
public EfCoreIdentitySessionRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
|
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.Identity.MongoDB; |
|||
|
|||
public class MongoIdentitySessionRepository : MongoDbRepository<IAbpIdentityMongoDbContext, IdentitySession, Guid>, IIdentitySessionRepository |
|||
{ |
|||
public MongoIdentitySessionRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
Loading…
Reference in new issue