Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EmailConfirmed set to false when updating name #7430

Closed
martenw opened this issue Jan 23, 2021 · 3 comments · Fixed by #7459
Closed

EmailConfirmed set to false when updating name #7430

martenw opened this issue Jan 23, 2021 · 3 comments · Fixed by #7459
Assignees
Milestone

Comments

@martenw
Copy link

martenw commented Jan 23, 2021

Generally having the same problem as described in #2140.

When a user changes the name field in UI and click save (without changing their email) the value of EmailConfirmed is set to false. As a visitor I would not expect to need to re-confirm a mail that has not been modified.

Using Razor pages 4.1.

@maliming maliming self-assigned this Jan 23, 2021
@maliming maliming modified the milestone: 4.3-preview Jan 23, 2021
@maliming
Copy link
Member

Unable reproduce.

@maliming maliming removed their assignment Jan 25, 2021
@martenw
Copy link
Author

martenw commented Jan 25, 2021

@maliming try this code and see if you get the same result.

Steps to reproduce

  1. Use the code below to add a new Razor page named "ConfirmEmail" in a clean 4.1.2 razor pages installation
  2. Navigate to /confirmemail - If your current users email is confirmed you get a green "User email is already confirmed!"
  3. Edit your profile and just change last name, nothing else
  4. Navigate to /confirmemail - Email is no longer confirmed so a new confirmation token is created and displayed
  5. If you want to set the email to confirmed again then just navigate to the full token-url displayed (in my created scenario I send this url in a mail)

Code

ConfirmEmail.cs

@page
@model Test.Abp412Clean.Web.Pages.ConfirmEmailModel
@{
}

ConfirmEmail.cshtml.cs

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Identity;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Abp.Identity;
using IdentityUser = Volo.Abp.Identity.IdentityUser;

namespace Test.Abp412Clean.Web.Pages
{
    public class ConfirmEmailModel : AbpPageModel
    {
        private readonly IdentityUserManager _identityUserManager;

        public ConfirmEmailModel(IdentityUserManager identityUserManager)
        {
            _identityUserManager = identityUserManager;
        }

        public async Task OnGet(string token)
        {
            try
            {
                if (!CurrentUser.IsAuthenticated)
                {
                    Alerts.Danger("Log in first");
                    return;
                }

                var user = await _identityUserManager.GetByIdAsync((Guid) CurrentUser.Id);

                if (!string.IsNullOrEmpty(token))
                {
                    Alerts.Info($"Token received, validating token");
                    await ValidateToken(user, token);
                    return;
                }

                if (user.EmailConfirmed)
                {
                    Alerts.Success("User email is already confirmed!");
                    return;
                }

                Alerts.Info("Creating a new email confirmation token to send to user");
                var newToken = await _identityUserManager.GenerateEmailConfirmationTokenAsync(user);
                var url = $"{Request.GetDisplayUrl()}?token={Uri.EscapeDataString(newToken)}";
                Alerts.Info($"Navigate to this url to set mail to confirmed again: {url}");
            }
            catch (Exception exception)
            {
                Alerts.Danger(exception.Message);
            }
        }

        private async Task ValidateToken(IdentityUser user, string token)
        {
            var result = await _identityUserManager.ConfirmEmailAsync(user, token);
            if (result.Succeeded)
            {
                Alerts.Success("The token was verified!");
                return;
            }

            foreach (var identityError in result.Errors ?? new List<IdentityError>())
            {
                Alerts.Danger($"Token validation error {identityError.Code}:{identityError.Description}");
            }
        }
    }
}

@martenw
Copy link
Author

martenw commented Jan 25, 2021

I have issues with CurrentUser not updating (#6335) which I still think is strange logic, was that the reason you could not reproduce perhaps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants