MemberLoginLog.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. namespace Domain.Entities.Members.Logs
  2. {
  3. /// <summary>
  4. /// 로그인 기록
  5. /// </summary>
  6. public class MemberLoginLog
  7. {
  8. public virtual Member Member { get; private set; } = null!;
  9. public int ID { get; private set; }
  10. public int? MemberID { get; private set; }
  11. public bool Success { get; private set; } = false;
  12. public string Account { get; private set; } = null!;
  13. public string? Reason { get; private set; }
  14. public string? Referer { get; private set; }
  15. public string? Url { get; private set; }
  16. public string? IpAddress { get; private set; }
  17. public string? UserAgent { get; private set; }
  18. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  19. private MemberLoginLog() { }
  20. private MemberLoginLog(int? memberID, bool success, string account, string? reason, string? referer, string? url, string? ipAddress, string? userAgent)
  21. {
  22. if (string.IsNullOrWhiteSpace(account))
  23. {
  24. throw new ArgumentException("Account is required.", nameof(account));
  25. }
  26. if (account.Length > 120)
  27. {
  28. throw new ArgumentOutOfRangeException(nameof(account));
  29. }
  30. if (reason is not null && reason.Length > 225)
  31. {
  32. throw new ArgumentOutOfRangeException(nameof(reason));
  33. }
  34. if (url is not null && url.Length > 500)
  35. {
  36. throw new ArgumentOutOfRangeException(nameof(url));
  37. }
  38. if (ipAddress is not null && ipAddress.Length > 45)
  39. {
  40. throw new ArgumentOutOfRangeException(nameof(ipAddress));
  41. }
  42. if (userAgent is not null && userAgent.Length > 512)
  43. {
  44. throw new ArgumentOutOfRangeException(nameof(userAgent));
  45. }
  46. MemberID = memberID;
  47. Success = success;
  48. Account = account;
  49. Reason = reason;
  50. Referer = referer;
  51. Url = url;
  52. IpAddress = ipAddress;
  53. UserAgent = userAgent;
  54. CreatedAt = DateTime.UtcNow;
  55. }
  56. public static MemberLoginLog Create(int? memberID, bool success, string account, string? reason = null, string? referer = null, string? url = null, string? ipAddress = null, string? userAgent = null)
  57. {
  58. return new(memberID, success, account, reason, referer, url, ipAddress, userAgent);
  59. }
  60. }
  61. }