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 changing email requires new password #2764

Merged
merged 10 commits into from
Mar 17, 2015

Conversation

viddo
Copy link
Contributor

@viddo viddo commented Mar 13, 2015

Fixes #2650 (and #2770 while at it)

Same behaviour as on current account page

Nicklas Gummesson added 3 commits March 13, 2015 18:39
@viddo
Copy link
Contributor Author

viddo commented Mar 13, 2015

ping @Kartones can you please review since you did the last changes related to the new account page? Basically, only change password if any password field is set.

Although, from a security perspective I wonder I wonder if we really should allow changing email without the user confirming it and/or require current password?

cc @xavijam

@viddo
Copy link
Contributor Author

viddo commented Mar 13, 2015

cc @rochoa for reporting the issue

@Kartones
Copy link
Contributor

That's why current code flow (at user.rb) doesn't triggers any password change if the old password field comes nil, but does as soon as that one comes (and will trigger validation errors so UI can display proper messages).

With your change there would be no error feedback to the user if forgot to set any or two of the three password fields...

@viddo
Copy link
Contributor Author

viddo commented Mar 13, 2015

The behaviour you describe sounds great, but that is not how it works I'm afraid. With the change I did it displays the proper messages. I propose you checkout the branch and try yourself then.

Without this change you'll get the unwanted behaviour @rochoa reported

@Kartones
Copy link
Contributor

Ok, I now read #2650 , the different title mislead me.

I would enforce the 3 fields only if attributes[:email].present? is true. But as will probably be always, the issue here is we should have a "new email" field, so if that field gets filled we trigger an email change. Right now is quite dangerous, without any confirmation we change the user email (and yes, that forces a password to be set, the issue).

@viddo viddo changed the title Only change password if password has changed Fix changing email requires new password Mar 13, 2015
@Kartones
Copy link
Contributor

If it shows the messages in the ui I'm ok. Backend has tests which is the part that worries me really, other stuff is UI/UX so if works... fine by me :P

@juanignaciosl
Copy link
Contributor

Google+ users have a random password for security reasons. If you need to reason about actual password existence you must user last_password_change_date, if it's not null it's because user changed it.

@viddo
Copy link
Contributor Author

viddo commented Mar 13, 2015

@Kartones @juanignaciosl so.. to sum up, what would you have me change here? Or are the changes OK to go as they are now?

@Cartofante
Copy link
Collaborator

Frontend tests were OK 👍 (details)

@Kartones
Copy link
Contributor

Sorry for drifting out of the main conversation.

For me:

  • Your change is ok, and we can go with that...
  • Except that I'm not sure it covers Google scenario then. If I understood correctly, for detecting a "from Google first password change" we need last_password_change_date.nil? && (attributes[:new_password].present? || attributes[:confirm_password].present?) ? *
  • We definetly need to document this at the user model, in the change password and/or validation code

@juanignaciosl
Copy link
Contributor

There's a can_change_email method that "document" this ;-)

1026   def can_change_email
1027     return !self.google_sign_in || self.last_password_change_date.present?
1028   end

@viddo
Copy link
Contributor Author

viddo commented Mar 16, 2015

@juanignaciosl Looking at existing code I could do something similar as where this method is used on organization pages, i.e. disable input field and show message indicating that a password must be set:
screen shot 2015-03-16 at 17 37 03

But does it make sense to show "old password"? What do user.change_password require in this case/how does it behave?

@juanignaciosl
Copy link
Contributor

Uhm. It looks like this haven't been brought from Central, where previous user account page belonged. Code suggestion:

def should_display_old_password?
  self.google_sign_in.nil? || !self.google_sign_in || !self.last_password_change_date.nil?
end

And validate_old_password should not validate the first password change of a Google user:

def validate_old_password(old_password)
  (self.class.password_digest(old_password, self.salt) == self.crypted_password) || (self.google_sign_in && self.last_password_change_date.nil?)
end

I think this is all you need, but please let me know if it doesn't work as expected.

Nicklas Gummesson added 6 commits March 16, 2015 18:13
Also fixes #2770 by replacing it with the google-user use-case text
Old password is not required due to google sign-in case (where the user
might not have a “old” password yet
Only update last password date if password is fully valid
@viddo
Copy link
Contributor Author

viddo commented Mar 17, 2015

Finally managed to set up staging to verify this. So with latest modifications to the user model. I've added a test case for the google sign-in to verify password change working.

So now the user would see a message why email can't be changed just yet, in addition to knowing that the account is linked with a google account:
screen shot 2015-03-17 at 12 26 05

Once a password is set the email and/or password can be changed as for a normal user:
screen shot 2015-03-17 at 12 27 10

Please review the code again and let me know if there is anything more that needs to be done, or if this is good to go, please, @juanignaciosl @Kartones @xavijam

@Kartones
Copy link
Contributor

+1 looks great!

@@ -391,11 +391,18 @@ def change_password(old_password, new_password_value, new_password_confirmation_

return unless new_password_value == new_password_confirmation_value && !new_password_value.nil?

# Must be set AFTER validations
set_last_password_change_date
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a note about this: in production we detected there's a rake task that passed through password change date and thus triggered last_password_change_date change. That's why it's done in confirmation in Central. 1.- Please check that you can sign up with Google a new user in staging and last_password_change is still nil after a minute or two. 2.- After deploying this to production, check it as well (both environments have different tasks running).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In staging:

irb(main):003:0> u.first.google_sign_in
=> false
irb(main):004:0> u.first.last_password_change_date
=> nil

Copy link
Contributor

Choose a reason for hiding this comment

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

That would mean it's not working, either you've taken a wrong user, or it's not deployed or something similar...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Btw, do you mean signup using google sign-in? Or both a normal sign-up and using the google sign-in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(...the console out above was using the normal sign-up btw)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, re-created an user (using google sign-up this time), yields same result:

irb(main):007:0> u.google_sign_in
=> true
irb(main):008:0> u.last_password_change_date
=> nil

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, google_sign_in is true, that's what scared me the most 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack, will merge & deploy, and reassure that it's the same for production afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI, confirmed

Copy link
Contributor

Choose a reason for hiding this comment

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

Great, thanks :)

@juanignaciosl
Copy link
Contributor

👍 , but take a look at my comment about environments and deployments.

viddo added a commit that referenced this pull request Mar 17, 2015
…e-passwd

Fix changing email requires new password
@viddo viddo merged commit de4a869 into master Mar 17, 2015
@viddo viddo deleted the 2650-fix-new-account-page-change-passwd branch March 17, 2015 15:10
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.

Changing email requires new password
4 participants