gpt4 book ai didi

c# - 限制访问,直到用户确认电子邮件链接

转载 作者:可可西里 更新时间:2023-11-01 02:59:58 26 4
gpt4 key购买 nike

我正在玩 Identity.Samples 示例,发现用户在注册后仍然可以登录,而无需单击电子邮件确认。是否有一个标志可以打开以限制用户在他/她单击他/她的电子邮件中的确认链接之前登录?或者我需要编写任何额外的代码来防止这种情况发生?

编辑:添加示例中的登录操作代码

    [HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}

// This doen't count login failures towards lockout only two factor authentication
// To enable password failures to trigger lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
}

最佳答案

如果您需要 emailConfirmation,只需在尝试密码登录之前添加这样的额外检查:

        var user = await UserManager.FindByNameAsync(model.Email);
if (user != null)
{
if (!await UserManager.IsEmailConfirmedAsync(user.Id)) return View("ErrorNotConfirmed");
}

关于c# - 限制访问,直到用户确认电子邮件链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24236304/

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