2022-09-17 22:13:35 +03:00
|
|
|
using BlueWest.WebApi.Context.Users;
|
|
|
|
using MapTo;
|
2022-09-18 04:00:24 +03:00
|
|
|
using Redis.OM.Modeling;
|
2022-09-17 22:13:35 +03:00
|
|
|
|
|
|
|
namespace BlueWest.Data.Application
|
|
|
|
{
|
2022-09-18 04:00:24 +03:00
|
|
|
[Document(StorageType = StorageType.Json, Prefixes = new []{"SessionToken"})]
|
2022-09-17 22:13:35 +03:00
|
|
|
[MapFrom(new []
|
|
|
|
{
|
|
|
|
typeof(SessionTokenUnique)
|
|
|
|
})]
|
|
|
|
public partial class SessionToken
|
|
|
|
{
|
|
|
|
[IgnoreMemberMapTo]
|
2022-09-18 04:00:24 +03:00
|
|
|
[Indexed] public string Id { get; set; }
|
2022-09-17 22:13:35 +03:00
|
|
|
|
2022-09-19 05:50:15 +03:00
|
|
|
[Indexed] public long ValidFor { get; set;}
|
2022-09-17 22:13:35 +03:00
|
|
|
|
2022-09-18 04:00:24 +03:00
|
|
|
[Indexed] public bool IsValid { get; set; }
|
2022-09-17 22:13:35 +03:00
|
|
|
|
2022-09-18 04:00:24 +03:00
|
|
|
[Indexed] public long CreatedDate { get; set; }
|
2022-09-17 22:13:35 +03:00
|
|
|
|
2022-09-18 04:00:24 +03:00
|
|
|
[Indexed] public string UserId { get; set; }
|
2022-09-17 22:13:35 +03:00
|
|
|
|
2022-09-18 04:00:24 +03:00
|
|
|
[Indexed] public string AccessToken { get; set; }
|
|
|
|
|
2022-09-17 22:13:35 +03:00
|
|
|
|
2022-09-19 05:50:15 +03:00
|
|
|
public bool Validate()
|
|
|
|
{
|
|
|
|
var expirationDate = CreatedDate + ValidFor;
|
|
|
|
var timeNow = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
|
|
|
if (expirationDate < timeNow)
|
|
|
|
{
|
|
|
|
IsValid = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2022-09-17 22:13:35 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|