2015-02-23 112 views

回答

0

FX允許您僅允許註冊用戶登錄。有一個標誌來檢查用戶是否確認了他們的電子郵件。該應用程序可以檢查這一點,並阻止用戶登錄,直到他們確認他們的電子郵件。在你的情況下,你可以添加另一個標誌,並在允許他們登錄之前檢查管理員是否批准了用戶。 您可以參閱代碼的電子郵件確認http://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity

+0

我看了一下,但更新我的模型後無法'update-database -force'來更改'aspnet_Users'模式。所以然後我看到這個http://typecastexception.com/post/2013/11/11/Extending-Identity-Accounts-and-Implementing-Role-Based-Authentication-in-ASPNET-MVC-5.aspx,並認爲我可以只是限制我想要的「驗證用戶」角色並完成相同的任務。 – 2015-02-24 00:14:10

1

新的屬性添加到應用程序的用戶

public partial class ApplicationUser : IdentityUser 
{ 
     public Boolean IsApproved { get; set; } 
} 

然後你就可以添加在ApplicationUserManager類實現CheckPasswordAsync覆蓋了晚飯方法UserManager像下面

public override Task<bool> CheckPasswordAsync(ApplicationUser user, string password) 
{ 
     if (!user.IsApproved) 
     { 
      return Task.FromResult<bool>(false); 
     } 
     return base.CheckPasswordAsync(user, password); 
} 

這種方法的唯一缺點是即使對於未經批准的用戶,我們也會收到「無效的登錄嘗試」消息。