gpt4 book ai didi

asp.net-core - SignInManager 的 CanSignInAsync(xyz) 方法如何工作?

转载 作者:行者123 更新时间:2023-12-05 03:54:10 34 4
gpt4 key购买 nike

在 ASP.NET Core Identity 中,SignInManager 的 CanSignInAsync(xyz) 方法是如何工作的,它的真正目的是什么,它会影响自定义商店提供程序接口(interface)(例如 IUserStore)实现的哪些方法?

最佳答案

来自 source code of CanSignInAsync(TUser) Method ,我们可以发现这个方法可以帮助检查指定用户是否可以根据确认状态登录,如下所示。

public virtual async Task<bool> CanSignInAsync(TUser user)
{
if (Options.SignIn.RequireConfirmedEmail && !(await UserManager.IsEmailConfirmedAsync(user)))
{
Logger.LogWarning(0, "User {userId} cannot sign in without a confirmed email.", await UserManager.GetUserIdAsync(user));
return false;
}
if (Options.SignIn.RequireConfirmedPhoneNumber && !(await UserManager.IsPhoneNumberConfirmedAsync(user)))
{
Logger.LogWarning(1, "User {userId} cannot sign in without a confirmed phone number.", await UserManager.GetUserIdAsync(user));
return false;
}
if (Options.SignIn.RequireConfirmedAccount && !(await _confirmation.IsConfirmedAsync(UserManager, user)))
{
Logger.LogWarning(4, "User {userId} cannot sign in without a confirmed account.", await UserManager.GetUserIdAsync(user));
return false;
}
return true;
}

关于asp.net-core - SignInManager 的 CanSignInAsync(xyz) 方法如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61219449/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com