insight/src/Core/Insight.Infrastructure/Entities/Identity.cs

95 lines
2.5 KiB
C#
Raw Normal View History

2023-09-21 18:58:32 +02:00
using AspNetCore.Identity.MongoDbCore.Models;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDbGenericRepository.Attributes;
using System.Text.Json.Serialization;
2023-09-22 22:16:56 +02:00
namespace Insight.Infrastructure.Entities;
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[CollectionName("user"), BsonIgnoreExtraElements]
public class InsightUser : MongoIdentityUser<ObjectId>
{
public InsightUser() : base() { }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
public InsightUser(string userName, string email) : base(userName, email) { }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[JsonPropertyName("refresh_tokens")]
public List<RefreshToken>? RefreshTokens { get; set; }
}
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonIgnoreExtraElements]
public class InsightUserLogEntity
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonElement("_user"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("user")]
public string? User { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonElement("insert")]
public DateTime? Insert { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonElement("timestamp")]
public DateTime? Timestamp { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonElement("message")]
public string? Message { get; set; }
}
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[CollectionName("user_pref"), BsonIgnoreExtraElements]
public class InsightUserPreferences
{
[BsonId, BsonRepresentation(BsonType.ObjectId), JsonPropertyName("id")]
public string? Id { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonElement("_user"), BsonRepresentation(BsonType.ObjectId), JsonPropertyName("user")]
public string? User { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonElement("insert")]
public DateTime? Insert { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonElement("update")]
public DateTime? Update { get; set; }
[BsonElement("darkmode")]
public bool DarkMode { get; set; }
}
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[CollectionName("role")]
public class InsightRole : MongoIdentityRole<ObjectId>
{
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
}
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonIgnoreExtraElements]
public class RefreshToken
{
[BsonElement("token")]
public string? Token { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonElement("created")]
public DateTime Created { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonElement("created_ip")]
public string? CreatedByIp { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonElement("expires")]
public DateTime Expires { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonElement("revoked")]
public DateTime? Revoked { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonElement("revoked_ip")]
public string? RevokedByIp { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonElement("revoked_reason")]
public string? ReasonRevoked { get; set; }
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonIgnore, JsonIgnore]
public bool IsExpired => DateTime.Now >= Expires.ToLocalTime();
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonIgnore, JsonIgnore]
public bool IsRevoked => Revoked != null;
2023-09-21 18:58:32 +02:00
2023-09-22 22:16:56 +02:00
[BsonIgnore, JsonIgnore]
public bool IsActive => !IsRevoked && !IsExpired;
2023-09-21 18:58:32 +02:00
}