Base solution for your next web application
Open Closed

Cant change email address for admin #12487


User avatar
0
philipcj created

In 14.2, I cannot change the email address for the admin user.

There is code in ProfileAppService that tries to email the original email ([email protected]).

Also this problem could apply to the default tenant email address too ([email protected]).

The problem is there is code in ProfileAppService.cs that says

     if (user.EmailAddress != input.EmailAddress)
     {
         await _userEmailer.SendEmailChangeRequestLinkAsync(
             user,
             input.EmailAddress,
             AppUrlService.CreateEmailChangeRequestUrlFormat(AbpSession.TenantId)
         );

         input.EmailAddress = user.EmailAddress;
     }

I wanted to report this to you - I have solved the problem by doing this:

     if (user.EmailAddress != input.EmailAddress && user.EmailAddress != "[email protected]" && user.EmailAddress != "[email protected]")
     {
         await _userEmailer.SendEmailChangeRequestLinkAsync(
             user,
             input.EmailAddress,
             AppUrlService.CreateEmailChangeRequestUrlFormat(AbpSession.TenantId)
         );

         input.EmailAddress = user.EmailAddress;
     }

Is there a better solution?

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

1 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi @philipcj

    First of all, thank you very much for sharing this issue and explaining it in detail.

    As you pointed out, the logic in ProfileAppService.cs prevents changing the email address for default admin users like [email protected] or [email protected]. While your workaround using hardcoded email checks works in the short term, relying on hardcoded values is generally not recommended for long-term maintenance. However, the method you specified can still be used.

    1. You could introduce a flag like IsSystemUser for users such as the default admin, and handle email change logic differently for them.
    2. Alternatively, instead of sending the email change confirmation, you can directly allow email changes for specific users like the admin.

    Here’s an example of a cleaner approach using the UserName instead of hardcoded email addresses:

    if (user.EmailAddress != input.EmailAddress)
    {
        if (user.UserName == "admin")
        {
            user.EmailAddress = input.EmailAddress;
            user.NormalizedEmailAddress = input.EmailAddress.ToUpperInvariant();
        }
        else
        {
            await _userEmailer.SendEmailChangeRequestLinkAsync(
                user,
                input.EmailAddress,
                AppUrlService.CreateEmailChangeRequestUrlFormat(AbpSession.TenantId)
            );
    
            input.EmailAddress = user.EmailAddress;
        }
    }
    
    • UserName is unique and consistent across environments.
    • Email addresses may change, but usernames typically remain fixed.

    We’ll consider this feedback for future releases to make handling such cases more flexible.

    Thanks again

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)