When i click on the email confirmation link send when registering a user, sometimes it thorws a error and sometimes it passes. Can i please know why this is hapenning? The error occures when user clicks the activation link from mobile. After retrying sometimes then it passes.
If i click the link from the computer web application it pasees.
below is the error received,
Can anyone help on understanding why this issue happens?
27 Answer(s)
-
0
Can you modify your code to write the detailed reason in the log? Such as: user == null, or user.EmailConfirmationCode.IsNullOrEmpty()
You can also write the UserId and ConfirmationCode to the log at the same time to help you find the cause of the problem.
https://github.com/aspnetzero/aspnet-zero-core/blob/f4ac9540a18a5446f6843277e0bd0b046daa51ff/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Application/Authorization/Accounts/AccountAppService.cs#L161
-
0
Hi,
public async Task ActivateEmail(ActivateEmailInput input) { var user = await UserManager.GetUserByIdAsync(input.UserId); Logger.InfoFormat("user is null: {0}", user == null); if (user != null) { Logger.InfoFormat("user confirmaion code: {0}", user.EmailConfirmationCode); Logger.InfoFormat("input confirmaion code: {0}", input.ConfirmationCode); Logger.InfoFormat("confirmaion code match: {0}", user.EmailConfirmationCode == input.ConfirmationCode); } if (user == null || user.EmailConfirmationCode.IsNullOrEmpty() || user.EmailConfirmationCode != input.ConfirmationCode) { throw new UserFriendlyException(L("InvalidEmailConfirmationCode"), L("InvalidEmailConfirmationCode_Detail")); } user.IsEmailConfirmed = true; user.EmailConfirmationCode = null; await UserManager.UpdateAsync(user); }
I added logging. The issue occures only sometimes. The issue comes frequently on chrome incognito mode.
INFO 2019-07-22 08:46:45,059 [28 ] Authorization.Accounts.AccountAppService - user is null: False INFO 2019-07-22 08:46:45,059 [28 ] Authorization.Accounts.AccountAppService - user confirmaion code: INFO 2019-07-22 08:46:45,059 [28 ] Authorization.Accounts.AccountAppService - input confirmaion code: 9d347ae77dfb4cddb9dc0d5f1219280f INFO 2019-07-22 08:46:45,059 [28 ] Authorization.Accounts.AccountAppService - confirmaion code match: False
Any idea why this happens?
-
0
what is the history API? I think this is due to the # in the url. I had to change the confirmation code generating code becuse it was not generating the correct encryption.
private string EncryptQueryParameters(string link, string encrptedParameterName = "c") { if (!link.Contains("?")) { return link; } var basePath = link.Substring(0, link.IndexOf('?')); if (link.Contains("#/")) { link = link.Replace("#/", string.Empty); } var uri = new Uri(link); var query = uri.Query.TrimStart('?'); return basePath + "?" + encrptedParameterName + "=" + HttpUtility.UrlEncode(SimpleStringCipher.Instance.Encrypt(query)); }
-
0
what is the history API?
I mean using PathLocationStrategy to see if the above problem still occurs.
I think this is due to the # in the url. I had to change the confirmation code generating code becuse it was not generating the correct encryption.
Does this solve your problem?
-
0
If link is 404, please see:
https://aspnetzero.com/LicenseManagement
You can invite anyone to become a member of the ASP.NET Zero organization using their GitHub username. And they can access the ASP.NET Zero private GitHub repositories. Your license plan allows you to add up to 20 users. Right after you add a GitHub user, the user will receive an invitation email. If there is problem receiving the invitation email, alternatively user can visit github.com/orgs/aspnetzero page and accept the invitation.
-
0
hi @firnas, contact to [email protected] for your license issue.
-
0
hi firnas.
Try replace the
EncryptQueryParameters
method with the following code.private string EncryptQueryParameters(string link, string encrptedParameterName = "c") { if (!link.Contains("?")) { return link; } var basePath = link.Substring(0, link.IndexOf('?')); var query = link.Substring(link.IndexOf('?')).TrimStart('?'); return basePath + "?" + encrptedParameterName + "=" + HttpUtility.UrlEncode(SimpleStringCipher.Instance.Encrypt(query)); }
-
0
I guess this may be related to your browser.
If you can't solve the problem that the link is accessed multiple times, you can modify the ActivateEmail method.
Skip detection logic if the user's mail has been activated.
public async Task ActivateEmail(ActivateEmailInput input) { var user = await UserManager.GetUserByIdAsync(input.UserId); if(user != null && user.IsEmailConfirmed) { return; } if (user == null || user.EmailConfirmationCode.IsNullOrEmpty() || user.EmailConfirmationCode != input.ConfirmationCode) { throw new UserFriendlyException(L("InvalidEmailConfirmationCode"), L("InvalidEmailConfirmationCode_Detail")); } user.IsEmailConfirmed = true; user.EmailConfirmationCode = null; await UserManager.UpdateAsync(user); }