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?
1 Answer(s)
-
0
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.csprevents 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.- You could introduce a flag like
IsSystemUserfor users such as the default admin, and handle email change logic differently for them. - 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
UserNameinstead 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; } }UserNameis 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 supportedCopy & paste or drag & drop images (max 30 MB per image) - You could introduce a flag like