How to disable email confirmation when a user creates an account in mvc asp identity

I need to disable email confirmation when a user creates an account in asp.net identity 2.0 MVC

+4
source share
2 answers

Just confirm it while you register it.

public async Task<ActionResult> Register(RegisterViewModel model)
{
    if (ModelState.IsValid)
    {
        var user = new ApplicationUser 
        { 
            UserName = model.Email, 
            Email = model.Email, 
            EmailConfirmed = true,
        };
        var result = await UserManager.CreateAsync(user, model.Password);
        if (result.Succeeded)
        {
            await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

            return RedirectToAction("Index", "Home");
        }
        AddErrors(result);
    }
    return View(model);
 }
+4
source

When setting aspnet id at startup

use the following:

In ConfigureServices ()

services.AddIdentity<ApplicationUser, IdentityRole>(config =>
{
   config.SignIn.RequireConfirmedEmail = false;
})

The Aspnet ID then does not check the EmailConfirmed flag when validating credentials during login.

0
source

Source: https://habr.com/ru/post/1629247/


All Articles