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

Revise how to change the password for external logins #4975

Merged
merged 5 commits into from
Aug 10, 2020
Merged

Conversation

yekalkan
Copy link
Member

@yekalkan yekalkan commented Aug 6, 2020

resolves #4982

@yekalkan yekalkan added this to the 3.1 milestone Aug 6, 2020
@yekalkan yekalkan requested a review from hikalkan August 6, 2020 07:58
@yekalkan yekalkan changed the title Do not show "password change" if the user has registered via social login Revise how to change the password for external logins Aug 7, 2020
var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId());

var profile = ObjectMapper.Map<IdentityUser, ProfileDto>(currentUser);
profile.IsExternalLoggedIn = currentUser.IsExternal;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you rename profile.IsExternalLoggedIn to currentUser.IsExternal then you don't need to manually map.

CreateMap<IdentityUser, ProfileDto>()
.Ignore(x=>x.IsExternalLoggedIn)
.Ignore(x=>x.HasPassword)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of ignoring HasPassword, you can map it with a custom lambda expression that checks PasswordHash != null. In this way, you don't need to manual mapping later.

profile.IsExternalLoggedIn = currentUser.IsExternal;
profile.HasPassword = currentUser.PasswordHash != null;

return profile;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After changing the mapping to fully use automapper, you can rollback changes in this method.


if (currentUser.PasswordHash == null)
{
(await UserManager.RemovePasswordAsync(currentUser)).CheckErrors();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really need to UserManager.RemovePasswordAsync. I suppose it is not needed because you are already checking if currentUser.PasswordHash == null.

@hikalkan hikalkan merged commit 967c47a into dev Aug 10, 2020
@hikalkan hikalkan deleted the issue/4928 branch August 10, 2020 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revise how to change the password for external logins
2 participants