Skip to content

Commit

Permalink
Added 'Name' property that replaces first and last name
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLazarescu committed Feb 22, 2024
1 parent 890f9f8 commit 66ad61c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 16 deletions.
8 changes: 6 additions & 2 deletions src/Application/Common/DTOs/Users/RegisterDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]
Expand Down
6 changes: 6 additions & 0 deletions src/Application/Common/DTOs/Users/UserForUpdateDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
4 changes: 4 additions & 0 deletions src/Application/Common/DTOs/Users/UserOutDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
19 changes: 13 additions & 6 deletions src/Application/Utility/EmailSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" +
Expand Down Expand Up @@ -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."
Expand All @@ -96,11 +101,13 @@ public async Task SendDowngradeWarningEmail(User user)
var message = new MimeMessage();
message.From.Add (new MailboxAddress ("Librum", "[email protected]"));

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 " +
Expand Down
8 changes: 6 additions & 2 deletions src/Domain/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,13 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("bit");

b.Property<string>("FirstName")
.IsRequired()
.HasMaxLength(40)
.HasColumnType("nvarchar(40)");

b.Property<bool>("HasProfilePicture")
.HasColumnType("bit");

b.Property<string>("LastName")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");

Expand All @@ -368,6 +366,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("datetimeoffset");

b.Property<string>("Name")
.HasMaxLength(150)
.HasColumnType("nvarchar(150)");

b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
Expand Down
6 changes: 2 additions & 4 deletions src/Presentation/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@
async Task SeedWithAdminUser(IServiceProvider services)
{
var config = services.GetRequiredService<IConfiguration>();
string firstName = "Admin";
string lastName = "Admin";
string name = "Admin";
string email = config["AdminEmail"];
string password = config["AdminPassword"];

Expand All @@ -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
Expand Down

0 comments on commit 66ad61c

Please sign in to comment.