I am using IdentityServer 3 for authentication. I am storing users in SQL DB using asp.net identity framework. IndentityServer team has provided simple IdentityManager.AspNetIdentity library for administrators to manage users.
I followed the video here and configured my application.
I have my own ApplicationUser and ApplicationUserManager class as below
public class ApplicationUser : Microsoft.AspNet.Identity.EntityFramework.IdentityUser
{
}
public class ApplicationUserManager : Microsoft.AspNet.Identity.UserManager<ApplicationUser, string>
{
    public ApplicationUserManager(ApplicationUserStore store, IDataProtectionProvider dataProtectionProvider)
        : base(store)
    {
        // Configure validation logic for usernames
        UserValidator = new UserValidator<ApplicationUser>(this)
        {
            AllowOnlyAlphanumericUserNames = false,
            RequireUniqueEmail = true                
        };
        // Configure validation logic for passwords
        PasswordValidator = new PasswordValidator
        {
            RequiredLength = 6,
            RequireNonLetterOrDigit = true,
            RequireDigit = true,
            RequireLowercase = true,
            RequireUppercase = true,
        };
        // Configure user lockout defaults
        UserLockoutEnabledByDefault = true;
        DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
        MaxFailedAccessAttemptsBeforeLockout = 5;
        EmailService = new EmailService();
        SmsService = new SmsService();
        if (dataProtectionProvider != null)
        {
            UserTokenProvider =
                new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("UserToken"));
        }
    }       
}
When i try to create user, i get error
email cannot be null or empty.
 
I can get rid of this error by setting RequireUniqueEmail to false in ApplicationUserManager. However that is not my requirement. I want to keep RequireUniqueEmail to true
Question
How do i get Email address field to appear on create new user page. Note that ApplicationUser is derived from IdentityUser that already has Email property. So i am not sure why its not appearing on create new user page?
Update 1
So i looked at the code for new user in github, however its developed in angular. I'm not familiar with angular syntax :( and how the model is passed to view. I am not sure what do i need to do in consumer application to enable email field on new user screen.
I partially solved my problem
The create user page shows only required property of IndetityUser ( in my case it ApplicationUser that is derived from IdentityUser). The Email property is in IdentityUser class but its virtual. So i can simply override the property in ApplicationUser and add required attribute
public class ApplicationUser : IdentityUser
{
    [Required]
    public override string Email { get; set; }
}
This will add email field on Create User Page as i want. However when i edit user it shows email field twice. ( for me its okay for time being since this functionality is internal only)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With