在我的登录页面上,我想实现一个系统,如果用户存在,但没有确认的电子邮件(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;
//}
}
我感谢你为我的问题找到解决办法所做的努力
3条答案
按热度按时间5vf7fwbs1#
如果我理解正确的话:在我们检查帐户是否处于活动状态之前,您要确保用户名和密码都正确吗?
72qzrwbm2#
要检查用户是否已确认,需要做一些小的修改,您需要检查
IsEmailConfirmed
属性,以查看用户是否已确认帐户。This article很好地解释了流程以及如何执行这些操作。下面的代码片段摘自那篇文章。
cygmwpex3#
在.NET 7中登录. cshtml.cs