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

Fix false emailVerified on user model update #3053

Merged
merged 2 commits into from
Jan 5, 2017

Conversation

yumenohosi
Copy link
Contributor

@yumenohosi yumenohosi commented Dec 23, 2016

Description

Yesterday, the loopback we are using in our system was upgraded
via npm, and since the upgrade, we noticed that every time
the user model updates, the emailVerified column would change to false.

I took a look and realized there might be an error in eb640d8

The intent of the commit just mention is to make emailVerified false
when the email gets changed, but notice that ctx.data.email is null
on updates, so the condition is always met and emailVerified always
becomes false.

This commit fixes the issue just mentioned.

Related issues

  • None

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

Yesterday, the loopback we are using in our system was upgraded
via npm, and since the upgrade, we noticed that every time
the user model updates, the emailVerified column would change to false.

I took a look and realized there might be an error in
strongloop@eb640d8

The intent of the commit just mention is to make emailVerified false
when the email gets changed, but notice that ctx.data.email is null
on updates, so the condition is always met and emailVerified always
becomes false.

This commit fixes the issue just mentioned.
@slnode
Copy link

slnode commented Dec 23, 2016

Can one of the admins verify this patch?

3 similar comments
@slnode
Copy link

slnode commented Dec 23, 2016

Can one of the admins verify this patch?

@slnode
Copy link

slnode commented Dec 23, 2016

Can one of the admins verify this patch?

@slnode
Copy link

slnode commented Dec 23, 2016

Can one of the admins verify this patch?

@slnode
Copy link

slnode commented Dec 23, 2016

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@@ -860,7 +860,7 @@ module.exports = function(User) {
}
} else {
var emailChanged = ctx.hookState.originalUserData.some(function(data) {
return data.email != ctx.data.email;
return ctx.data.email && data.email != ctx.data.email;

Choose a reason for hiding this comment

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

It seems that with the falsy ctx.data.email, you don't even need to iterate over ctx.hookState.originalUserData

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@davidcheung
Copy link
Contributor

@slnode ok to test

@davidcheung
Copy link
Contributor

the patch LGTM, @bajtos @loay can you guys PTAL

@bajtos bajtos self-assigned this Jan 4, 2017
@bajtos
Copy link
Member

bajtos commented Jan 4, 2017

@yumenohosi thank you for the pull request, and thank you @davidcheung for the first round of review. I have assigned the patch to myself and I'll take a look in next few days.

@benbrown
Copy link

benbrown commented Jan 4, 2017

This also threw a major monkeywrench into our application and caused 2 days of lost progress.

I think all of @loay's recent changes to the emailVerified process should be carefully reviewed. For example, it is NOT desirable to log users out of applications just because they change their email address.

@bajtos
Copy link
Member

bajtos commented Jan 5, 2017

@benbrown thank you for chiming in, we are sorry for the difficulties created :(

For example, it is NOT desirable to log users out of applications just because they change their email address.

Logging out users is important for security reasons. Consider the case when somebody hacks your email that you used when registering with a LoopBack-powered app. After you find this, you log into the app and change the email to a different one that wasn't hacked. Without session (access token) invalidation, the attacker would remain logged into your account and you would have no way how to log them out.

Having said that, I agree that this makes the user experience less optimal. I am proposing to allow the end user to decide whether they want to log out other sessions or not, see #3071

@bajtos bajtos merged commit f4b1676 into strongloop:master Jan 5, 2017
@bajtos
Copy link
Member

bajtos commented Jan 5, 2017

Landed 🎉 Thank you @yumenohosi for your contribution! 👏

@bajtos
Copy link
Member

bajtos commented Jan 5, 2017

For posterity: I did not realise there were two commits in this pull request and I forgot to squash them before landing. My fault :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants