Lookup for email in username field to match docs if email is undefined (#2732)
* Lookup for email in username field to match docs if email is undefined * Adds support for sendMail option to when email is selected * Proper does not exists clause
This commit is contained in:
@@ -2,9 +2,20 @@ module.exports = options => {
|
|||||||
if (!options) {
|
if (!options) {
|
||||||
throw "Options were not provided"
|
throw "Options were not provided"
|
||||||
}
|
}
|
||||||
return {
|
let adapter = {
|
||||||
sendVerificationEmail: () => Promise.resolve(),
|
sendVerificationEmail: () => Promise.resolve(),
|
||||||
sendPasswordResetEmail: () => Promise.resolve(),
|
sendPasswordResetEmail: () => Promise.resolve(),
|
||||||
sendMail: () => 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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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: 'parse@example.com',
|
||||||
|
apiKey: 'k',
|
||||||
|
domain: 'd',
|
||||||
|
sendMail: function(options) {
|
||||||
|
expect(options.to).toEqual('testValidConfig@parse.com');
|
||||||
|
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("testValidConfig@parse.com");
|
||||||
|
user.signUp(null)
|
||||||
|
.then(user => Parse.User.requestPasswordReset("testValidConfig@parse.com"))
|
||||||
|
.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 => {
|
it('does not send verification email if email verification is disabled', done => {
|
||||||
var emailAdapter = {
|
var emailAdapter = {
|
||||||
sendVerificationEmail: () => Promise.resolve(),
|
sendVerificationEmail: () => Promise.resolve(),
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ export class UserController extends AdaptableController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setPasswordResetToken(email) {
|
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) {
|
sendPasswordResetEmail(email) {
|
||||||
@@ -181,7 +181,7 @@ export class UserController extends AdaptableController {
|
|||||||
"You requested to reset your password for " + appName + ".\n\n" +
|
"You requested to reset your password for " + appName + ".\n\n" +
|
||||||
"" +
|
"" +
|
||||||
"Click here to reset it:\n" + link;
|
"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;
|
let subject = 'Password Reset for ' + appName;
|
||||||
return { text, to, subject };
|
return { text, to, subject };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user