-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Add beforePasswordResetRequest hook
#9906
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
base: alpha
Are you sure you want to change the base?
Changes from 1 commit
c354da3
e30572d
2971acf
8076a65
659ab5e
fce3723
2045d87
8bfc13b
39f0e47
73aa8dd
0b3b21d
57712ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import { | |
| Types as TriggerTypes, | ||
| getRequestObject, | ||
| resolveError, | ||
| inflate, | ||
| } from '../triggers'; | ||
| import { promiseEnsureIdempotency } from '../middlewares'; | ||
| import RestWrite from '../RestWrite'; | ||
|
|
@@ -444,21 +445,58 @@ export class UsersRouter extends ClassesRouter { | |
| if (!email && !token) { | ||
| throw new Parse.Error(Parse.Error.EMAIL_MISSING, 'you must provide an email'); | ||
| } | ||
|
|
||
| let userResults = null; | ||
| let userData = null; | ||
|
|
||
| // We can find the user using token | ||
| if (token) { | ||
| const results = await req.config.database.find('_User', { | ||
| userResults = await req.config.database.find('_User', { | ||
| _perishable_token: token, | ||
| _perishable_token_expires_at: { $lt: Parse._encode(new Date()) }, | ||
| }); | ||
| if (results && results[0] && results[0].email) { | ||
| email = results[0].email; | ||
| if (userResults && userResults.length > 0) { | ||
| userData = userResults[0]; | ||
| if (userData.email) { | ||
| email = userData.email; | ||
| } | ||
| } | ||
| // Or using email if no token provided | ||
| } else if (typeof email === 'string') { | ||
| userResults = await req.config.database.find( | ||
| '_User', | ||
| { $or: [{ email }, { username: email, email: { $exists: false } }] }, | ||
| { limit: 1 }, | ||
| Auth.maintenance(req.config) | ||
| ); | ||
|
Comment on lines
+454
to
+471
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Token lookup uses inverted expiry comparator and lacks Auth.maintenance/limit.
Apply: - userResults = await req.config.database.find('_User', {
- _perishable_token: token,
- _perishable_token_expires_at: { $lt: Parse._encode(new Date()) },
- });
+ userResults = await req.config.database.find(
+ '_User',
+ {
+ _perishable_token: token,
+ _perishable_token_expires_at: { $gt: Parse._encode(new Date()) },
+ },
+ { limit: 1 },
+ Auth.maintenance(req.config)
+ );🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mtrezza an opininion since this code already exists before my modifcations ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (userResults && userResults.length > 0) { | ||
| userData = userResults[0]; | ||
| } | ||
| } | ||
|
|
||
| if (typeof email !== 'string') { | ||
| throw new Parse.Error( | ||
| Parse.Error.INVALID_EMAIL_ADDRESS, | ||
| 'you must provide a valid email string' | ||
| ); | ||
| } | ||
|
|
||
| if (userData) { | ||
| // Useful to get User attached files in the trigger (photo picture for example) | ||
| await req.config.filesController.expandFilesInObject(req.config, userData); | ||
|
|
||
| const user = inflate('_User', userData); | ||
|
|
||
| await maybeRunTrigger( | ||
| TriggerTypes.beforePasswordResetRequest, | ||
| req.auth, | ||
| user, | ||
| null, | ||
| req.config, | ||
| req.info.context | ||
| ); | ||
| } | ||
coratgerl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const userController = req.config.userController; | ||
| try { | ||
| await userController.sendPasswordResetEmail(email); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.