Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Asp Core: You need to confirm your email.

27.07.2018 (👁11445)


Fehlermeldung:

  • You need to confirm your email.

 

Logik-Problem:

Wenn man unter der Standard-Vorgabe des Asp.Net Core MVC Identiy Controllers sich in einer Webseite anmeldet und dann aber die Account-Anmeldung verpasst, dann kommt man in das Problem, dass man immer die Meldung

You need to confirm your email antrifft, diese Bestätigungsemail aber nicht erneut erzeugen kann.

Lösung:

1) Confirmation bei ResetPasswort

Deshalb muss entweder in der ResetPassword Logik beim Reset auch automatisch die EmailConfirmation aktualisiert werden.

//< additional confirm email >

if(user.EmailConfirmed==false )

    user.EmailConfirmed = true;

    await _dbContext.SaveChangesAsync();

}

//</ additional confirm email >

 

return RedirectToAction(nameof(ResetPasswordConfirmation));

 

 

2) oder erneuetes Senden der Confirmation beim Versuch des Login

Controllers/AccountController.cs->Login(..)

[HttpPost]

        [AllowAnonymous]

        [ValidateAntiForgeryToken]

        public async Task<IActionResultLogin(LoginViewModel model, string returnUrl = null)

        {

            //--------------< Login_Postback() >--------------

            ViewData["ReturnUrl"] = returnUrl;

            if (ModelState.IsValid)

            {

..

..

//--< check email-confirmation >--

//*rp: if login fails succeeded, then check confirmation again

if (await _userManager.IsEmailConfirmedAsync(user) == false)

{

    //< confirm >

    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);

    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

    //</ confirm >

 

    ModelState.AddModelError("""You need to confirm your email. Confirmation-Email was send again");

    return View(model);

}

//--</ check email-confirmation >--

 

 

 

 

Unter Login

https://angebotsuche.de/Account/Login

Geänderte ResetPassword Logik

[HttpPost]

[AllowAnonymous]

[ValidateAntiForgeryToken]

public async Task<IActionResult> ResetPassword(ResetPasswordViewModel model)

{

    //--------------< ResetPassword_Postback() >--------------

    //< check datamodel >

    if (!ModelState.IsValid)

    {

        return View(model);

    }

    //</ check datamodel >

 

    //--< check user >--

    var user = await _userManager.FindByEmailAsync(model.Email);

    if (user == null)

    {

        // Don't reveal that the user does not exist

        return RedirectToAction(nameof(ResetPasswordConfirmation));

    }

    //--</ check user >--

 

    //--< Reset Password >--

    //string sTest = user.PasswordHash;

    var result = await _userManager.ResetPasswordAsync(user, model.Code, model.Password);

    if (result.Succeeded)

    {

        //< additional confirm email >

        if(user.EmailConfirmed==false )

        { 

            user.EmailConfirmed = true;

            await _dbContext.SaveChangesAsync();

        }

        //</ additional confirm email >

 

        return RedirectToAction(nameof(ResetPasswordConfirmation));

    }

    //--</ Reset Password >--

 

    //< view >

    AddErrors(result);

    return View();

    //</ view >

    //--------------</ ResetPassword_Postback() >--------------

}