CodeLiturgy.Dashboard/CodeLiturgy.Data.Application/SessionToken/SessionToken.cs

43 lines
1.0 KiB
C#

using BlueWest.Data.Application.Users;
using MapTo;
using Redis.OM.Modeling;
namespace BlueWest.Data.Application
{
[Document(StorageType = StorageType.Json, Prefixes = new []{"SessionToken"})]
[MapFrom(new []
{
typeof(SessionTokenUnique)
})]
public partial class SessionToken
{
[IgnoreMemberMapTo]
[Indexed] public string Id { get; set; }
[Indexed] public long ValidFor { get; set;}
[Indexed] public bool IsValid { get; set; }
[Indexed] public long CreatedDate { get; set; }
[Indexed] public string UserId { get; set; }
[Indexed] public string AccessToken { get; set; }
public bool Validate()
{
var expirationDate = CreatedDate + ValidFor;
var timeNow = DateTimeOffset.Now.ToUnixTimeMilliseconds();
if (expirationDate < timeNow)
{
IsValid = false;
return true;
}
return false;
}
}
}