Skip to content

Commit

Permalink
Fixed Normalized(Email|UserName) fields management in admin panel. Cl…
Browse files Browse the repository at this point in the history
…oses impworks#166.
  • Loading branch information
impworks committed Jul 30, 2020
1 parent f35b56a commit 2b09bde
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Bonsai/Areas/Admin/ViewModels/Users/UserEditorVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ public override void Configure(IProfileExpression profile)
.MapMember(x => x.MiddleName, x => x.MiddleName)
.MapMember(x => x.LastName, x => x.LastName)
.MapMember(x => x.Email, x => x.Email)
.MapMember(x => x.NormalizedEmail, x => x.Email.ToUpperInvariant())
.MapMember(x => x.PageId, x => x.PersonalPageId)
.ForMember(x => x.UserName, opt => opt.MapFrom(x => Regex.Replace(x.Email, "[^a-z0-9]", "")))
.ForMember(x => x.UserName, opt => opt.MapFrom(x => ClearEmail(x.Email)))
.ForMember(x => x.NormalizedUserName, opt => opt.MapFrom(x => ClearEmail(x.Email).ToUpperInvariant()))
.ForAllOtherMembers(x => x.Ignore());

profile.CreateMap<AppUser, UserEditorVM>()
Expand All @@ -62,5 +64,7 @@ public override void Configure(IProfileExpression profile)
.ForMember(x => x.Password, opt => opt.Ignore())
.ForMember(x => x.PasswordCopy, opt => opt.Ignore());
}

private static string ClearEmail(string email) => Regex.Replace(email, "[^a-z0-9]", "");
}
}

0 comments on commit 2b09bde

Please sign in to comment.