2017-04-06 70 views
1

我正在使用IdentityServer 3進行身份驗證。我正在使用asp.net身份框架將用戶存儲在SQL數據庫中。 IndentityServer團隊已經爲管理員提供了簡單的IdentityManager.AspNetIdentity庫來管理用戶。創建新用戶時,電子郵件不能爲空或空白?

我跟着video here並配置我的應用程序。

我有我自己的ApplicationUserApplicationUserManager類,如下

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")); 
     } 
    }  
} 

當我嘗試創建用戶時,收到錯誤

電子郵件不能爲空或空。

enter image description here

我可以在ApplicationUserManager設置RequireUniqueEmailfalse擺脫這種錯誤的。但這不是我的要求。我想保持RequireUniqueEmailtrue

問題
我如何獲得電子郵件地址字段中出現在創建新的用戶頁面。請注意,ApplicationUser源自已具有Email屬性的IdentityUser。所以我不知道爲什麼它不出現在創建新的用戶頁面?

更新1
所以我看了看代碼new user in github,但其在角發展。我不熟悉的角度語法:(該模型是如何傳遞進行查看。我不知道我需要在消費應用程序執行,以使新用戶屏幕上的電子郵件字段的內容。

回答

0

我部分地解決我的問題

創建用戶頁面顯示的IndetityUser只需要屬性(在我的情況下,它是從IdentityUser衍生ApplicationUser)的Email屬性是IdentityUser類,但它是虛擬的。因此,我可以簡單地重寫屬性在ApplicationUser並添加所需的屬性

public class ApplicationUser : IdentityUser 
{ 
    [Required] 
    public override string Email { get; set; } 
} 

這將上創建用戶頁面,因爲我想添加電子郵件領域。但是,當我編輯用戶它顯示電子郵件字段兩次。 (對我來說它的好時間是因爲此功能僅限內部使用)

相關問題