- ABP Framework version: v7.2.2
- UI Type: Angular
- Database System: EF Core (SQL Server)
- Tiered (for MVC) or Auth Server Separated (for Angular): Auth Server separated
Hey Team,
Currently we are facing an issue when the user uses the registration and the confirmation email setting is on, the user gets the email for him to confirm hisaccount but he gets an "Invalid Token" error in the EmailConfirmation page.
I've seen in the forum that this is an issue in this current version that we are using (7.2.2) and that was fixed somewhere in 7.3. Is there a way for us to fix this issue in the current version? Is there a way to override the EmailConfirmation page? I tried adding it in the /Pages/Account/EmailConfirmation but throws an error saying that it already exist in the project.
How can we fix this issue?
I've seen that this is kind of the fix but not entirely sure how to implement it: https://support.abp.io/QA/Questions/5422/Customize-email-confirmation-token-after-successfully-confirm-email
Regards
11 Answer(s)
-
0
Hi,
You can override the
AccountAppService
andEmailConfirmation
[Dependency(ReplaceServices = true)] [ExposeServices(typeof(AccountAppService))] public class MyAccountAppService : AccountAppService { .... public override async Task ConfirmEmailAsync(ConfirmEmailInput input) { var user = await UserManager.GetByIdAsync(input.UserId); if (user.EmailConfirmed) { return; } (await UserManager.ConfirmEmailAsync(user, input.Token)).CheckErrors(); (await UserManager.UpdateSecurityStampAsync(user)).CheckErrors(); await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext { Identity = IdentitySecurityLogIdentityConsts.Identity, Action = IdentitySecurityLogActionConsts.ChangeEmail }); } }
[Dependency(ReplaceServices = true)] [ExposeServices(typeof(EmailConfirmationModel))] public class MyEmailConfirmationModel : EmailConfirmationModel { ... public override async Task<IActionResult> OnGetAsync() { ReturnUrl = GetRedirectUrl(ReturnUrl, ReturnUrlHash); try { var user = await UserManager.GetByIdAsync(UserId); if (user.EmailConfirmed) { EmailConfirmed = true; return Page(); } ValidateModel(); InvalidToken = !await AccountAppService.VerifyEmailConfirmationTokenAsync( new VerifyEmailConfirmationTokenInput() { UserId = UserId, Token = ConfirmationToken } ); if (!InvalidToken) { await _accountAppService.ConfirmEmailAsync(new ConfirmEmailInput { UserId = UserId, Token = ConfirmationToken }); EmailConfirmed = true; } } catch (Exception e) { if (e is AbpIdentityResultException && !string.IsNullOrWhiteSpace(e.Message)) { Alerts.Warning(GetLocalizeExceptionMessage(e)); return Page(); } if (e is AbpValidationException) { return Page(); } throw; } return Page(); } }
-
0
You can also consider upgrading to 7.3,
-
0
Hi,
You can override the
AccountAppService
andEmailConfirmation
[Dependency(ReplaceServices = true)] [ExposeServices(typeof(AccountAppService))] public class MyAccountAppService : AccountAppService { .... public override async Task ConfirmEmailAsync(ConfirmEmailInput input) { var user = await UserManager.GetByIdAsync(input.UserId); if (user.EmailConfirmed) { return; } (await UserManager.ConfirmEmailAsync(user, input.Token)).CheckErrors(); (await UserManager.UpdateSecurityStampAsync(user)).CheckErrors(); await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext { Identity = IdentitySecurityLogIdentityConsts.Identity, Action = IdentitySecurityLogActionConsts.ChangeEmail }); } }
[Dependency(ReplaceServices = true)] [ExposeServices(typeof(EmailConfirmationModel))] public class MyEmailConfirmationModel : EmailConfirmationModel { ... public override async Task<IActionResult> OnGetAsync() { ReturnUrl = GetRedirectUrl(ReturnUrl, ReturnUrlHash); try { var user = await UserManager.GetByIdAsync(UserId); if (user.EmailConfirmed) { EmailConfirmed = true; return Page(); } ValidateModel(); InvalidToken = !await AccountAppService.VerifyEmailConfirmationTokenAsync( new VerifyEmailConfirmationTokenInput() { UserId = UserId, Token = ConfirmationToken } ); if (!InvalidToken) { await _accountAppService.ConfirmEmailAsync(new ConfirmEmailInput { UserId = UserId, Token = ConfirmationToken }); EmailConfirmed = true; } } catch (Exception e) { if (e is AbpIdentityResultException && !string.IsNullOrWhiteSpace(e.Message)) { Alerts.Warning(GetLocalizeExceptionMessage(e)); return Page(); } if (e is AbpValidationException) { return Page(); } throw; } return Page(); } }
Hi Liang, thanks for the answer. I replaced the ConfirmEmail by adding a "CustomEmailConfirmation" Page under /Pages/Account/CustomEmailConfirmationModel.html and CustomEmailConfirmationModel.cs
I am not sure for the "AppService". I added it under the same /Pages/Account and just a class with the code you sent.
I added these changes and the Token that I get on the email still shows as invalid
Am I adding in the wrong section the override for the "AppService"?
Here it is how I added it:
Regards,
-
0
Hi,
The position looks like no problem, have you added this attrubute?
[Dependency(ReplaceServices = true)] [ExposeServices(typeof(AccountAppService))]
[Dependency(ReplaceServices = true)] [ExposeServices(typeof(EmailConfirmationModel))]
-
0
-
0
-
0
Hi,
Could you share the full logs?
-
0
Hi,
Sure, I have them with the app insight telemetry, can I send you those or you want them in a specific way?
-
0
Hi,
I guess the user's email address was not confirmed, but there was a problem when confirming the email address.
Please share it with email: shiwei.liang@volosoft.com
Thanks.
-
0
Hi,
I guess the user's email address was not confirmed, but there was a problem when confirming the email address.
Please share it with email: shiwei.liang@volosoft.com
Thanks.
Hi Liang,
Done. I sent them to you.
-
0
Hi,
I have checked but didn't find anything.
I could not reproduce the problem in my local.
Could you provide the full steps to reproduce? I will check it. thanks