diff --git a/src/Application/Common/DTOs/Users/RegisterDto.cs b/src/Application/Common/DTOs/Users/RegisterDto.cs index 7d1a776..66c7f54 100644 --- a/src/Application/Common/DTOs/Users/RegisterDto.cs +++ b/src/Application/Common/DTOs/Users/RegisterDto.cs @@ -4,15 +4,19 @@ namespace Application.Common.DTOs.Users; public class RegisterDto { - [Required] + // Legacy - to be removed [MinLength(2, ErrorMessage = "13 The firstname is too short")] [MaxLength(40, ErrorMessage = "14 The firstname is too long")] public string FirstName { get; set; } - [Required] + // Legacy - to be removed [MinLength(2, ErrorMessage = "15 The lastname is too short")] [MaxLength(50, ErrorMessage = "16 The lastname is too long")] public string LastName { get; set; } + + [MinLength(2, ErrorMessage = "23 The name is too short")] + [MaxLength(150, ErrorMessage = "24 The name is too long")] + public string Name { get; set; } [Required] [EmailAddress(ErrorMessage = "8 Invalid email address format.")] diff --git a/src/Application/Common/DTOs/Users/UserForUpdateDto.cs b/src/Application/Common/DTOs/Users/UserForUpdateDto.cs index beb1db6..c5eedbd 100644 --- a/src/Application/Common/DTOs/Users/UserForUpdateDto.cs +++ b/src/Application/Common/DTOs/Users/UserForUpdateDto.cs @@ -4,14 +4,20 @@ namespace Application.Common.DTOs.Users; public class UserForUpdateDto { + // Legacy - to be removed [MinLength(2, ErrorMessage = "The firstname is too short")] [MaxLength(40, ErrorMessage = "The firstname is too long")] public string FirstName { get; set; } + // Legacy - to be removed [MinLength(2, ErrorMessage = "The lastname is too short")] [MaxLength(50, ErrorMessage = "The lastname is too long")] public string LastName { get; set; } + [MinLength(2, ErrorMessage = "23 The name is too short")] + [MaxLength(150, ErrorMessage = "24 The name is too long")] + public string Name { get; set; } + public DateTime ProfilePictureLastUpdated { get; set; } public bool HasProfilePicture { get; set; } diff --git a/src/Application/Common/DTOs/Users/UserOutDto.cs b/src/Application/Common/DTOs/Users/UserOutDto.cs index 626abe1..8c93dfd 100644 --- a/src/Application/Common/DTOs/Users/UserOutDto.cs +++ b/src/Application/Common/DTOs/Users/UserOutDto.cs @@ -4,9 +4,13 @@ namespace Application.Common.DTOs.Users; public class UserOutDto { + // Legacy - to be removed public string FirstName { get; set; } + // Legacy - to be removed public string LastName { get; set; } + + public string Name { get; set; } public string Email { get; set; } diff --git a/src/Application/Utility/EmailSender.cs b/src/Application/Utility/EmailSender.cs index c6e10a4..61e6059 100644 --- a/src/Application/Utility/EmailSender.cs +++ b/src/Application/Utility/EmailSender.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Tokens; using MimeKit; namespace Application.Utility; @@ -40,11 +41,13 @@ public async Task SendEmailConfirmationEmail(User user, string token) message.From.Add (new MailboxAddress ("Librum", messFrom)); } - message.To.Add (new MailboxAddress (user.FirstName, user.Email)); + // Legacy - to be removed + var userName = user.Name.IsNullOrEmpty() ? user.FirstName : user.Name; + message.To.Add (new MailboxAddress (userName, user.Email)); message.Subject = "Confirm Your Email"; message.Body = new TextPart ("plain") { - Text = $"Hello { user.FirstName }.\n\nThank you for choosing Librum! " + + Text = $"Hello { userName }.\n\nThank you for choosing Librum! " + "We are happy to tell you, that your account has successfully been created. " + "The final step remaining is to confirm it, and you're all set to go.\n" + $"To confirm your email, please click the link below:\n{confirmationLink}\n\n" + @@ -78,11 +81,13 @@ public async Task SendPasswordResetEmail(User user, string token) message.From.Add (new MailboxAddress ("Librum",messFrom)); } - message.To.Add (new MailboxAddress (user.FirstName, user.Email)); + // Legacy - to be removed + var userName = user.Name.IsNullOrEmpty() ? user.FirstName : user.Name; + message.To.Add (new MailboxAddress (userName, user.Email)); message.Subject = "Reset Your Password"; message.Body = new TextPart ("plain") { - Text = $"Hello { user.FirstName }.\n\nYou can find the link to reset your password below. " + + Text = $"Hello { userName }.\n\nYou can find the link to reset your password below. " + "Follow the link and continue the password reset on our website.\n" + $"{resetLink}\n\n" + "If you didn't request this email, just ignore it." @@ -96,11 +101,13 @@ public async Task SendDowngradeWarningEmail(User user) var message = new MimeMessage(); message.From.Add (new MailboxAddress ("Librum", "noreply@librumreader.com")); - message.To.Add (new MailboxAddress (user.FirstName, user.Email)); + // Legacy - to be removed + var userName = user.Name.IsNullOrEmpty() ? user.FirstName : user.Name; + message.To.Add (new MailboxAddress (userName, user.Email)); message.Subject = "Your books may be deleted in 7 days! - Take Action"; message.Body = new TextPart ("plain") { - Text = $"Hello { user.FirstName },\n\nYou have recently downgraded your Account. " + + Text = $"Hello { userName },\n\nYou have recently downgraded your Account. " + "Due to the downgrade your online storage was reduced and your current library " + "size may exceed your new storage limit.\n" + $"Please reduce your library size if that is the case, otherwise books from your account will automatically be DELETED until " + diff --git a/src/Domain/Entities/User.cs b/src/Domain/Entities/User.cs index d7ccc24..e6b0668 100644 --- a/src/Domain/Entities/User.cs +++ b/src/Domain/Entities/User.cs @@ -7,15 +7,19 @@ namespace Domain.Entities; [Index(nameof(Email), IsUnique = true)] public class User : IdentityUser { - [Required] + // Legacy - to be removed [MinLength(2, ErrorMessage = "The firstname is too short")] [MaxLength(40, ErrorMessage = "The firstname is too long")] public string FirstName { get; set; } - [Required] + // Legacy - to be removed [MinLength(2, ErrorMessage = "The lastname is too short")] [MaxLength(50, ErrorMessage = "The lastname is too long")] public string LastName { get; set; } + + [MinLength(2, ErrorMessage = "The name is too short")] + [MaxLength(150, ErrorMessage = "The name is too long")] + public string Name { get; set; } [Required] [MinLength(6, ErrorMessage = "The email is too short")] diff --git a/src/Infrastructure/Persistence/Migrations/DataContextModelSnapshot.cs b/src/Infrastructure/Persistence/Migrations/DataContextModelSnapshot.cs index adff587..5b18336 100644 --- a/src/Infrastructure/Persistence/Migrations/DataContextModelSnapshot.cs +++ b/src/Infrastructure/Persistence/Migrations/DataContextModelSnapshot.cs @@ -350,7 +350,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("bit"); b.Property("FirstName") - .IsRequired() .HasMaxLength(40) .HasColumnType("nvarchar(40)"); @@ -358,7 +357,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("bit"); b.Property("LastName") - .IsRequired() .HasMaxLength(50) .HasColumnType("nvarchar(50)"); @@ -368,6 +366,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("LockoutEnd") .HasColumnType("datetimeoffset"); + b.Property("Name") + .HasMaxLength(150) + .HasColumnType("nvarchar(150)"); + b.Property("NormalizedEmail") .HasMaxLength(256) .HasColumnType("nvarchar(256)"); diff --git a/src/Presentation/Program.cs b/src/Presentation/Program.cs index 5fcd4b0..989b183 100644 --- a/src/Presentation/Program.cs +++ b/src/Presentation/Program.cs @@ -89,8 +89,7 @@ async Task SeedWithAdminUser(IServiceProvider services) { var config = services.GetRequiredService(); - string firstName = "Admin"; - string lastName = "Admin"; + string name = "Admin"; string email = config["AdminEmail"]; string password = config["AdminPassword"]; @@ -99,8 +98,7 @@ async Task SeedWithAdminUser(IServiceProvider services) { var user = new User { - FirstName = firstName, - LastName = lastName, + Name = name, Email = email, UserName = email, AccountCreation = DateTime.UtcNow