-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId()); | ||
|
||
var profile = ObjectMapper.Map<IdentityUser, ProfileDto>(currentUser); | ||
profile.IsExternalLoggedIn = currentUser.IsExternal; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
resolves #4982