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

Lookup for email in username field to match docs if email is undefined #2732

Merged
merged 3 commits into from
Sep 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion spec/MockEmailAdapterWithOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ module.exports = options => {
if (!options) {
throw "Options were not provided"
}
return {
let adapter = {
sendVerificationEmail: () => Promise.resolve(),
sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => Promise.resolve()
};
if (options.sendMail) {
adapter.sendMail = options.sendMail
}
if (options.sendPasswordResetEmail) {
adapter.sendPasswordResetEmail = options.sendPasswordResetEmail
}
if (options.sendVerificationEmail) {
adapter.sendVerificationEmail = options.sendVerificationEmail;
}

return adapter;
}
39 changes: 39 additions & 0 deletions spec/ValidationAndPasswordsReset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,45 @@ describe("Custom Pages, Email Verification, Password Reset", () => {
});
});

it('succeeds sending a password reset username if appName, publicServerURL, and email adapter are prodvided', done => {
let adapter = MockEmailAdapterWithOptions({
fromAddress: '[email protected]',
apiKey: 'k',
domain: 'd',
sendMail: function(options) {
expect(options.to).toEqual('[email protected]');
return Promise.resolve();
}
});

// delete that handler to force using the default
delete adapter.sendPasswordResetEmail;

spyOn(adapter, 'sendMail').and.callThrough();
reconfigureServer({
appName: 'coolapp',
publicServerURL: 'http://localhost:1337/1',
emailAdapter: adapter
})
.then(() => {
let user = new Parse.User();
user.setPassword("asdf");
user.setUsername("[email protected]");
user.signUp(null)
.then(user => Parse.User.requestPasswordReset("[email protected]"))
.then(result => {
expect(adapter.sendMail).toHaveBeenCalled();
done();
}, error => {
done(error);
});
})
.catch(error => {
fail(JSON.stringify(error));
done();
});
});

it('does not send verification email if email verification is disabled', done => {
var emailAdapter = {
sendVerificationEmail: () => Promise.resolve(),
Expand Down
4 changes: 2 additions & 2 deletions src/Controllers/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class UserController extends AdaptableController {
}

setPasswordResetToken(email) {
return this.config.database.update('_User', { email }, { _perishable_token: randomString(25) }, {}, true)
return this.config.database.update('_User', { $or: [{email}, {username: email, email: {$exists: false}}] }, { _perishable_token: randomString(25) }, {}, true)
}

sendPasswordResetEmail(email) {
Expand Down Expand Up @@ -181,7 +181,7 @@ export class UserController extends AdaptableController {
"You requested to reset your password for " + appName + ".\n\n" +
"" +
"Click here to reset it:\n" + link;
let to = user.get("email");
let to = user.get("email") || user.get('username');
let subject = 'Password Reset for ' + appName;
return { text, to, subject };
}
Expand Down