-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: Add conditional email verification via dynamic Parse Server options verifyUserEmails
, sendUserEmailVerification
that now accept functions
#8425
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
39c0ada
feat: add conditional email
dblythy f68cdef
Merge branch 'alpha' into conditional-email
dblythy 29b279c
Merge branch 'alpha' into conditional-email
mtrezza f399e5c
wip
dblythy 620aa27
Merge branch 'alpha' into conditional-email
dblythy edd3495
Update EmailVerificationToken.spec.js
dblythy ce9f3f5
refactor
dblythy 85119fc
Merge branch 'alpha' into conditional-email
dblythy 88c687c
Merge branch 'alpha' into conditional-email
dblythy 95785e2
add sendUserEmailVerification
dblythy 051810d
Merge branch 'conditional-email' of https://github.com/dblythy/parse-…
dblythy 006356a
tests
dblythy ed71cfd
tests
dblythy e64410a
Merge branch 'alpha' into conditional-email
mtrezza bba6750
fix typo
mtrezza 5283b60
fix typo in definitions
mtrezza 4d40339
fix typo
mtrezza 50314b3
wip
dblythy 860c2dd
Merge branch 'alpha' into conditional-email
mtrezza bb1ed0f
Merge branch 'alpha' into conditional-email
dblythy d9eb91f
tests
dblythy 51ca662
Merge branch 'alpha' into conditional-email
mtrezza c9b873c
Merge branch 'alpha' into conditional-email
dblythy 2a6b0d7
wip
dblythy d457358
Merge branch 'conditional-email' of https://github.com/dblythy/parse-…
dblythy 9d87f1e
Merge branch 'alpha' into conditional-email
mtrezza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -288,6 +288,112 @@ describe('Email Verification Token Expiration: ', () => { | |
}); | ||
}); | ||
|
||
it('can conditionally send emails', async () => { | ||
let sendEmailOptions; | ||
const emailAdapter = { | ||
sendVerificationEmail: options => { | ||
sendEmailOptions = options; | ||
}, | ||
sendPasswordResetEmail: () => Promise.resolve(), | ||
sendMail: () => {}, | ||
}; | ||
await reconfigureServer({ | ||
appName: 'emailVerifyToken', | ||
verifyUserEmails: true, | ||
emailAdapter: emailAdapter, | ||
emailVerifyTokenValidityDuration: 5, // 5 seconds | ||
publicServerURL: 'http://localhost:8378/1', | ||
}); | ||
const beforeSave = { | ||
method(req) { | ||
expect(req.setSendEmailVerificationEmail).toBeTrue(); | ||
expect(req.setEmailVerified).toBeFalse(); | ||
req.setSendEmailVerificationEmail = false; | ||
req.setEmailVerified = true; | ||
}, | ||
}; | ||
const saveSpy = spyOn(beforeSave, 'method').and.callThrough(); | ||
const emailSpy = spyOn(emailAdapter, 'sendVerificationEmail').and.callThrough(); | ||
Parse.Cloud.beforeSave(Parse.User, beforeSave.method); | ||
const user = new Parse.User(); | ||
user.setUsername('sets_email_verify_token_expires_at'); | ||
user.setPassword('expiringToken'); | ||
user.set('email', '[email protected]'); | ||
await user.signUp(); | ||
|
||
const config = Config.get('test'); | ||
const results = await config.database.find( | ||
'_User', | ||
{ | ||
username: 'sets_email_verify_token_expires_at', | ||
}, | ||
{}, | ||
Auth.maintenance(config) | ||
); | ||
|
||
expect(results.length).toBe(1); | ||
const user_data = results[0]; | ||
expect(typeof user_data).toBe('object'); | ||
expect(user_data.emailVerified).toEqual(true); | ||
expect(user_data._email_verify_token).toBeUndefined(); | ||
expect(user_data._email_verify_token_expires_at).toBeUndefined(); | ||
expect(emailSpy).not.toHaveBeenCalled(); | ||
expect(saveSpy).toHaveBeenCalled(); | ||
expect(sendEmailOptions).toBeUndefined(); | ||
}); | ||
|
||
it('beforeSave options do not change existing behaviour', async () => { | ||
let sendEmailOptions; | ||
const emailAdapter = { | ||
sendVerificationEmail: options => { | ||
sendEmailOptions = options; | ||
}, | ||
sendPasswordResetEmail: () => Promise.resolve(), | ||
sendMail: () => {}, | ||
}; | ||
await reconfigureServer({ | ||
appName: 'emailVerifyToken', | ||
verifyUserEmails: true, | ||
emailAdapter: emailAdapter, | ||
emailVerifyTokenValidityDuration: 5, // 5 seconds | ||
publicServerURL: 'http://localhost:8378/1', | ||
}); | ||
const beforeSave = { | ||
method(req) { | ||
if (!req.original) { | ||
expect(req.setSendEmailVerificationEmail).toBeTrue(); | ||
expect(req.setEmailVerified).toBeFalse(); | ||
} | ||
}, | ||
}; | ||
const saveSpy = spyOn(beforeSave, 'method').and.callThrough(); | ||
const emailSpy = spyOn(emailAdapter, 'sendVerificationEmail').and.callThrough(); | ||
Parse.Cloud.beforeSave(Parse.User, beforeSave.method); | ||
const newUser = new Parse.User(); | ||
newUser.setUsername('unsets_email_verify_token_expires_at'); | ||
newUser.setPassword('expiringToken'); | ||
newUser.set('email', '[email protected]'); | ||
await newUser.signUp(); | ||
const response = await request({ | ||
url: sendEmailOptions.link, | ||
followRedirects: false, | ||
}); | ||
expect(response.status).toEqual(302); | ||
const config = Config.get('test'); | ||
const results = await config.database.find('_User', { | ||
username: 'unsets_email_verify_token_expires_at', | ||
}); | ||
|
||
expect(results.length).toBe(1); | ||
const user = results[0]; | ||
expect(typeof user).toBe('object'); | ||
expect(user.emailVerified).toEqual(true); | ||
expect(typeof user._email_verify_token).toBe('undefined'); | ||
expect(typeof user._email_verify_token_expires_at).toBe('undefined'); | ||
expect(saveSpy).toHaveBeenCalled(); | ||
expect(emailSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('unsets the _email_verify_token_expires_at and _email_verify_token fields in the User class if email verification is successful', done => { | ||
const user = new Parse.User(); | ||
let sendEmailOptions; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.