Skip to content

Reset password fix#1133

Merged
drew-gross merged 4 commits intoparse-community:masterfrom
carmenlau:reset-password-fix
Mar 24, 2016
Merged

Reset password fix#1133
drew-gross merged 4 commits intoparse-community:masterfrom
carmenlau:reset-password-fix

Conversation

@carmenlau
Copy link
Contributor

refs #951

There are 2 updates in this PR.
1. Fix cannot reset password, when the app defined user before save.
In the original implementation, updateUserPassword update the password directly through RestWrite but the originalData argument is missing. So if the app has defined user before save, reset password will be fail. To fix this, I updated updateUserPassword function to reuse rest lib update function.

2. _perishable_token is a private field, clear it through RestWrite will cause "Permission denied for this action." error.
Fix this by access db directly when clear _perishable_token after reset password.

Let me know for any problems about the PR, hope this help!:)

return this.config.database.adaptiveCollection('_User').then(function (collection) {
// Need direct database access because verification token is not a parse field
return collection.findOneAndUpdate({ username: username },// query
{ $set: { _perishable_token: null } } // update
Copy link
Contributor

Choose a reason for hiding this comment

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

should we not unset that? to delete value altogether, I recall we had problems with $set: { key: null } with oAuth

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean change it to { $unset: { _perishable_token: null } } instead of setting it to null or we should keep the token there? I am open to this. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Change to $unset :)

@codecov-io
Copy link

Current coverage is 91.24%

Merging #1133 into master will decrease coverage by -0.63% as of cbedf67

@@            master   #1133   diff @@
======================================
  Files           93      93       
  Stmts         5812    5814     +2
  Branches      1056    1056       
  Methods          0       0       
======================================
- Hit           5340    5305    -35
  Partial         11      11       
- Missed         461     498    +37

Review entire Coverage Diff as of cbedf67

Powered by Codecov. Updated on successful CI builds.

@facebook-github-bot
Copy link

@carmenlau updated the pull request.

@flovilmart
Copy link
Contributor

last tiny thing, can you add a unit test that would get the user from the DB and check that the update it OK? we had a previous unit test and it seemed to be working where it wasn't

@facebook-github-bot
Copy link

@carmenlau updated the pull request.

1 similar comment
@facebook-github-bot
Copy link

@carmenlau updated the pull request.

@carmenlau carmenlau force-pushed the reset-password-fix branch from 271de12 to ebbda59 Compare March 23, 2016 12:19
@carmenlau
Copy link
Contributor Author

Updated!


Parse.User.logIn("zxcv", "hello").then(function(user){
done();
let config = new Config('test');
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@flovilmart
Copy link
Contributor

Travis seems to be drunk...

@flovilmart
Copy link
Contributor

can you rebase on master, a fix was pushed earlier for the failing builds

@carmenlau carmenlau force-pushed the reset-password-fix branch from ebbda59 to 603bf97 Compare March 24, 2016 02:22
@carmenlau
Copy link
Contributor Author

Done :)

@drew-gross
Copy link
Contributor

Sweet, glad to see a fix :) If you want to help with some optimization, the current method does 1 database read (to find the user) and two writes (to update the password, and clear the token) but it could be done with no reads and one write (by making the token and the $unset part of the update)

@drew-gross drew-gross merged commit 82ebba4 into parse-community:master Mar 24, 2016
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.

6 participants