gpt4 book ai didi

c# - 如何检查 "User"在 ASP.NET 身份(Web 窗体)中是否有确认的电子邮件?

转载 作者:太空狗 更新时间:2023-10-30 01:34:07 35 4
gpt4 key购买 nike

在我的登录页面上,我想实现一个系统,如果用户存在但没有确认的电子邮件 (IsEmailConfirmed),则用户需要验证/确认电子邮件。

我重新发送确认码没有任何问题,我的问题是在哪里放置声明以及如何确保用户输入正确的用户名和密码(用户应该是有效的)。

登录(代码隐藏)

protected void LogIn(object sender, EventArgs e)
{
// Validate the user password
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signinManager = Context.GetOwinContext().GetUserManager<ApplicationSignInManager>();

// Require the user to have a confirmed email before they can log on.
var user = manager.FindByName(username.Text);

if (IsValid)
{
if (user != null)
{
// This doen't count login failures towards account lockout
// To enable password failures to trigger lockout, change to shouldLockout: true
var result = signinManager.PasswordSignIn(username.Text, Password.Text, RememberMe.Checked, shouldLockout: true);

switch (result)
{
case SignInStatus.Success:
IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"],
Response);
break;

case SignInStatus.LockedOut:
//Response.Redirect("/Account/Lockout");
FailureText.Text = "This account has been locked out, please try again later.";
ErrorMessage.Visible = true;
return;

case SignInStatus.RequiresVerification:
Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
Request.QueryString["ReturnUrl"],
RememberMe.Checked),
true);
break;

case SignInStatus.Failure:
default:
FailureText.Text = "Invalid login attempt";
ErrorMessage.Visible = true;
break;
}
}
}
else
{
FailureText.Text = "Account not found.";
ErrorMessage.Visible = true;
}

//else if (IsValid & !manager.IsEmailConfirmed(user.Id))
//{
// ScriptManager.RegisterStartupScript(this, this.GetType(), "LaunchServerSide", "$(function() { OpenLoginModal(); });", true);
// LoginModalTitle.Text = "Account Verification".ToUpper();
// LoginModalDetails.Text = "You must have a confirmed email account.";
// //ErrorMessage.Visible = true;
// //ResendConfirm.Visible = true;
//}
}

感谢您为解决我的问题所做的努力

最佳答案

如果我理解正确:在我们检查帐户是否处于事件状态之前,您想确保用户名和密码都正确吗?

protected void LogIn(object sender, EventArgs e)
{
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signinManager = Context.GetOwinContext().GetUserManager<ApplicationSignInManager>();
var user = manager.FindByName(username.Text);

if (IsValid)
{
if (user != null)
{
var result = signinManager.PasswordSignIn(username.Text, Password.Text, RememberMe.Checked, shouldLockout: true);

// If username and password is correct check if account is activated.
if(!user.EmailConfirmed && result == SignInStatus.Success)
{
FailureText.Text = "Invalid login attempt. You must have a confirmed email account.";
ErrorMessage.Visible = true;
return;
}

switch (result)
{
case SignInStatus.Success:
IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"],
Response);
break;
case SignInStatus.LockedOut:
//Response.Redirect("/Account/Lockout");
FailureText.Text = "This account has been locked out, please try again later.";
ErrorMessage.Visible = true;
return;

case SignInStatus.RequiresVerification:
Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
Request.QueryString["ReturnUrl"],
RememberMe.Checked),
true);
break;
case SignInStatus.Failure:
default:
FailureText.Text = "Invalid login attempt";
ErrorMessage.Visible = true;
break;
}
}
else
{
FailureText.Text = "Account not found.";
ErrorMessage.Visible = true;
}
}
}

关于c# - 如何检查 "User"在 ASP.NET 身份(Web 窗体)中是否有确认的电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31855018/

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