Asp.net core 强制用户确认邮件

Ste*_*fan 2 asp.net-core asp.net-core-webapi asp.net-core-identity

就像标题一样,我试图强迫用户在让他登录之前确认电子邮件。我是根据 Microsoft 教程做的事情,并且有人写到我必须添加

o.SignIn.RequireConfirmedEmail = true;

我做了什么,但它不会阻止我登录,即使我没有确认我的电子邮件

 services.AddIdentity<Company, IdentityRole>
      (o =>
      {
        // configure identity options
        o.Password.RequireDigit = false;
        o.Password.RequireLowercase = false;
        o.Password.RequireUppercase = false;
        o.Password.RequireNonAlphanumeric = false;
        o.Password.RequiredLength = 6;
        o.SignIn.RequireConfirmedEmail = true;
        o.Tokens.EmailConfirmationTokenProvider = EmailConfirmationTokenProviderName;
      })
      .AddEntityFrameworkStores<ShopContext>()
      .AddTokenProvider<ConfirmEmailDataProtectorTokenProvider<Company>>(EmailConfirmationTokenProviderName);
Run Code Online (Sandbox Code Playgroud)

我正在使用 jwt 令牌身份验证在这种情况下我是否做了比我展示的更多的事情?

J. *_*Doe 5

添加检查,如果账户在开始确认Login动作

var user = await _userManager.FindByEmailAsync(model.Email);
        if (user != null)
        {
            if (!await _userManager.IsEmailConfirmedAsync(user))
            {
                ModelState.AddModelError(string.Empty, 
                              "You must have a confirmed email to log in.");
                return View(model);
            }
        }
Run Code Online (Sandbox Code Playgroud)

还记得关于防止新注册用户的评论自动登录await _signInManager.SignInAsync(user, isPersistent: false);Register行动

更多阅读官方文档