| | | 1 | | namespace KT.Domain |
| | | 2 | | { |
| | | 3 | | internal class User |
| | | 4 | | { |
| | 10 | 5 | | public User(string id, string username, string realName, string email, string passwordHash) |
| | 10 | 6 | | { |
| | 10 | 7 | | if (string.IsNullOrWhiteSpace(id)) |
| | 0 | 8 | | throw new ArgumentException("The user identifier cannot be empty.", nameof(id)); |
| | | 9 | | |
| | 10 | 10 | | if (string.IsNullOrWhiteSpace(username) || username.Length < 3) |
| | 0 | 11 | | throw new ArgumentException("The username must be at least 3 characters long.", nameof(username)); |
| | | 12 | | |
| | 10 | 13 | | if (string.IsNullOrWhiteSpace(realName)) |
| | 0 | 14 | | throw new ArgumentException("The real name cannot be empty.", nameof(realName)); |
| | | 15 | | |
| | 10 | 16 | | if (string.IsNullOrWhiteSpace(email) || !IsValidEmail(email)) |
| | 0 | 17 | | throw new ArgumentException("The email address is invalid.", nameof(email)); |
| | | 18 | | |
| | 10 | 19 | | if (string.IsNullOrWhiteSpace(passwordHash)) |
| | 0 | 20 | | throw new ArgumentException("The password hash cannot be empty.", nameof(passwordHash)); |
| | 10 | 21 | | Id = id; |
| | 10 | 22 | | Username = username.ToLower(); |
| | 10 | 23 | | UsernameDisplay = username; |
| | 10 | 24 | | RealName = realName; |
| | 10 | 25 | | Email = email.ToLower(); |
| | 10 | 26 | | PasswordHash = passwordHash; |
| | 10 | 27 | | CreatedAt = DateTime.UtcNow; |
| | 10 | 28 | | } |
| | 22 | 29 | | public string Id { get; private set; } |
| | 13 | 30 | | public string Username { get; private set; } |
| | 15 | 31 | | public string UsernameDisplay { get; private set; } |
| | 12 | 32 | | public string RealName { get; private set; } |
| | 13 | 33 | | public string Email { get; private set; } |
| | 13 | 34 | | public string PasswordHash { get; private set; } |
| | 11 | 35 | | public DateTime CreatedAt { get; private set; } |
| | | 36 | | private static bool IsValidEmail(string email) |
| | 10 | 37 | | { |
| | | 38 | | try |
| | 10 | 39 | | { |
| | 10 | 40 | | var addr = new System.Net.Mail.MailAddress(email); |
| | 10 | 41 | | return addr.Address == email; |
| | | 42 | | } |
| | 0 | 43 | | catch |
| | 0 | 44 | | { |
| | 0 | 45 | | return false; |
| | | 46 | | } |
| | 10 | 47 | | } |
| | | 48 | | } |
| | | 49 | | } |