-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Implement Email Verification #583
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
24f9176
fix spacing
40d37e9
FIX : User Roles not added to create, update or delete calls
3c31e1f
Exploring the interface of a mail adapter
drew-gross e953953
Implement and test sending of signup email
drew-gross 8f643c7
Finish implementation of email verification on create
drew-gross 817ef97
Cleanup reset logic (that will come in another PR)
drew-gross 317d6ea
Remove reset routes
drew-gross 0a982b7
Add some tests and demonstrate the adapter loading interface
drew-gross 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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
sendVerificationEmail: () => Promise.resolve(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = options => { | ||
if (!options) { | ||
throw "Options were not provided" | ||
} | ||
return { | ||
sendVerificationEmail: () => Promise.resolve() | ||
} | ||
} |
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 |
---|---|---|
|
@@ -47,6 +47,217 @@ describe('Parse.User testing', () => { | |
}); | ||
}); | ||
|
||
it('sends verification email if email verification is enabled', done => { | ||
var emailAdapter = { | ||
sendVerificationEmail: () => Promise.resolve() | ||
} | ||
setServerConfiguration({ | ||
serverURL: 'http://localhost:8378/1', | ||
appId: 'test', | ||
appName: 'unused', | ||
javascriptKey: 'test', | ||
dotNetKey: 'windows', | ||
clientKey: 'client', | ||
restAPIKey: 'rest', | ||
masterKey: 'test', | ||
collectionPrefix: 'test_', | ||
fileKey: 'test', | ||
verifyUserEmails: true, | ||
emailAdapter: emailAdapter, | ||
}); | ||
spyOn(emailAdapter, 'sendVerificationEmail'); | ||
var user = new Parse.User(); | ||
user.setPassword("asdf"); | ||
user.setUsername("zxcv"); | ||
user.signUp(null, { | ||
success: function(user) { | ||
expect(emailAdapter.sendVerificationEmail).toHaveBeenCalled(); | ||
user.fetch() | ||
.then(() => { | ||
expect(user.get('emailVerified')).toEqual(false); | ||
done(); | ||
}); | ||
}, | ||
error: function(userAgain, error) { | ||
fail('Failed to save user'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
|
||
it('does not send verification email if email verification is disabled', done => { | ||
var emailAdapter = { | ||
sendVerificationEmail: () => Promise.resolve() | ||
} | ||
setServerConfiguration({ | ||
serverURL: 'http://localhost:8378/1', | ||
appId: 'test', | ||
appName: 'unused', | ||
javascriptKey: 'test', | ||
dotNetKey: 'windows', | ||
clientKey: 'client', | ||
restAPIKey: 'rest', | ||
masterKey: 'test', | ||
collectionPrefix: 'test_', | ||
fileKey: 'test', | ||
verifyUserEmails: false, | ||
emailAdapter: emailAdapter, | ||
}); | ||
spyOn(emailAdapter, 'sendVerificationEmail'); | ||
var user = new Parse.User(); | ||
user.setPassword("asdf"); | ||
user.setUsername("zxcv"); | ||
user.signUp(null, { | ||
success: function(user) { | ||
user.fetch() | ||
.then(() => { | ||
expect(emailAdapter.sendVerificationEmail.calls.count()).toEqual(0); | ||
expect(user.get('emailVerified')).toEqual(undefined); | ||
done(); | ||
}); | ||
}, | ||
error: function(userAgain, error) { | ||
fail('Failed to save user'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
|
||
it('receives the app name and user in the adapter', done => { | ||
var emailAdapter = { | ||
sendVerificationEmail: options => { | ||
expect(options.appName).toEqual('emailing app'); | ||
expect(options.user.get('email')).toEqual('[email protected]'); | ||
done(); | ||
} | ||
} | ||
setServerConfiguration({ | ||
serverURL: 'http://localhost:8378/1', | ||
appId: 'test', | ||
appName: 'emailing app', | ||
javascriptKey: 'test', | ||
dotNetKey: 'windows', | ||
clientKey: 'client', | ||
restAPIKey: 'rest', | ||
masterKey: 'test', | ||
collectionPrefix: 'test_', | ||
fileKey: 'test', | ||
verifyUserEmails: true, | ||
emailAdapter: emailAdapter, | ||
}); | ||
var user = new Parse.User(); | ||
user.setPassword("asdf"); | ||
user.setUsername("zxcv"); | ||
user.set('email', '[email protected]'); | ||
user.signUp(null, { | ||
success: () => {}, | ||
error: function(userAgain, error) { | ||
fail('Failed to save user'); | ||
done(); | ||
} | ||
}); | ||
}) | ||
|
||
it('when you click the link in the email it sets emailVerified to true and redirects you', done => { | ||
var user = new Parse.User(); | ||
var emailAdapter = { | ||
sendVerificationEmail: options => { | ||
request.get(options.link, { | ||
followRedirect: false, | ||
}, (error, response, body) => { | ||
expect(response.statusCode).toEqual(302); | ||
expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/verify_email_success.html?username=zxcv'); | ||
user.fetch() | ||
.then(() => { | ||
expect(user.get('emailVerified')).toEqual(true); | ||
done(); | ||
}); | ||
}); | ||
} | ||
} | ||
setServerConfiguration({ | ||
serverURL: 'http://localhost:8378/1', | ||
appId: 'test', | ||
appName: 'emailing app', | ||
javascriptKey: 'test', | ||
dotNetKey: 'windows', | ||
clientKey: 'client', | ||
restAPIKey: 'rest', | ||
masterKey: 'test', | ||
collectionPrefix: 'test_', | ||
fileKey: 'test', | ||
verifyUserEmails: true, | ||
emailAdapter: emailAdapter, | ||
}); | ||
user.setPassword("asdf"); | ||
user.setUsername("zxcv"); | ||
user.set('email', '[email protected]'); | ||
user.signUp(); | ||
}); | ||
|
||
it('redirects you to invalid link if you try to verify email incorrecly', done => { | ||
request.get('http://localhost:8378/1/verify_email', { | ||
followRedirect: false, | ||
}, (error, response, body) => { | ||
expect(response.statusCode).toEqual(302); | ||
expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/invalid_link.html'); | ||
done() | ||
}); | ||
}); | ||
|
||
it('redirects you to invalid link if you try to validate a nonexistant users email', done => { | ||
request.get('http://localhost:8378/1/verify_email?token=asdfasdf&username=sadfasga', { | ||
followRedirect: false, | ||
}, (error, response, body) => { | ||
expect(response.statusCode).toEqual(302); | ||
expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/invalid_link.html'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('does not update email verified if you use an invalid token', done => { | ||
var user = new Parse.User(); | ||
var emailAdapter = { | ||
sendVerificationEmail: options => { | ||
request.get('http://localhost:8378/1/verify_email?token=invalid&username=zxcv', { | ||
followRedirect: false, | ||
}, (error, response, body) => { | ||
expect(response.statusCode).toEqual(302); | ||
expect(response.body).toEqual('Found. Redirecting to http://localhost:8378/1/invalid_link.html'); | ||
user.fetch() | ||
.then(() => { | ||
expect(user.get('emailVerified')).toEqual(false); | ||
done(); | ||
}); | ||
}); | ||
} | ||
} | ||
setServerConfiguration({ | ||
serverURL: 'http://localhost:8378/1', | ||
appId: 'test', | ||
appName: 'emailing app', | ||
javascriptKey: 'test', | ||
dotNetKey: 'windows', | ||
clientKey: 'client', | ||
restAPIKey: 'rest', | ||
masterKey: 'test', | ||
collectionPrefix: 'test_', | ||
fileKey: 'test', | ||
verifyUserEmails: true, | ||
emailAdapter: emailAdapter, | ||
}); | ||
user.setPassword("asdf"); | ||
user.setUsername("zxcv"); | ||
user.set('email', '[email protected]'); | ||
user.signUp(null, { | ||
success: () => {}, | ||
error: function(userAgain, error) { | ||
fail('Failed to save user'); | ||
done(); | ||
} | ||
}); | ||
}); | ||
|
||
it("user login wrong username", (done) => { | ||
Parse.User.signUp("asdf", "zxcv", null, { | ||
success: function(user) { | ||
|
@@ -1628,7 +1839,7 @@ describe('Parse.User testing', () => { | |
done(); | ||
}); | ||
}); | ||
|
||
it('test parse user become', (done) => { | ||
var sessionToken = null; | ||
Parse.Promise.as().then(function() { | ||
|
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: ES6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed actually as the export is at the top