Stop requiring verifyUserEmails for password reset functionality (#2166)

This commit is contained in:
Tyler Brock
2016-06-28 19:25:44 -07:00
committed by Florent Vilmart
parent a73f150a1a
commit 799e59618c
3 changed files with 14 additions and 13 deletions

View File

@@ -238,10 +238,10 @@ describe("Custom Pages, Email Verification, Password Reset", () => {
}); });
}); });
it_exclude_dbs(['postgres'])('fails if you include an emailAdapter, set verifyUserEmails to false, dont set a publicServerURL, and try to send a password reset email (regression test for #1649)', done => { it_exclude_dbs(['postgres'])('fails if you include an emailAdapter, set a publicServerURL, but have no appName and send a password reset email', done => {
reconfigureServer({ reconfigureServer({
appName: 'unused', appName: undefined,
verifyUserEmails: false, publicServerURL: 'http://localhost:1337/1',
emailAdapter: MockEmailAdapterWithOptions({ emailAdapter: MockEmailAdapterWithOptions({
fromAddress: 'parse@example.com', fromAddress: 'parse@example.com',
apiKey: 'k', apiKey: 'k',
@@ -278,6 +278,7 @@ describe("Custom Pages, Email Verification, Password Reset", () => {
} }
reconfigureServer({ reconfigureServer({
appName: 'unused', appName: 'unused',
publicServerURL: 'http://localhost:1337/1',
verifyUserEmails: false, verifyUserEmails: false,
emailAdapter: emailAdapter, emailAdapter: emailAdapter,
}) })

View File

@@ -56,17 +56,17 @@ export class Config {
static validate({ static validate({
verifyUserEmails, verifyUserEmails,
userController,
appName, appName,
publicServerURL, publicServerURL,
revokeSessionOnPasswordReset, revokeSessionOnPasswordReset,
expireInactiveSessions, expireInactiveSessions,
sessionLength, sessionLength,
}) { }) {
this.validateEmailConfiguration({ const emailAdapter = userController.adapter;
verifyUserEmails: verifyUserEmails, if (verifyUserEmails) {
appName: appName, this.validateEmailConfiguration({emailAdapter, appName, publicServerURL});
publicServerURL: publicServerURL }
})
if (typeof revokeSessionOnPasswordReset !== 'boolean') { if (typeof revokeSessionOnPasswordReset !== 'boolean') {
throw 'revokeSessionOnPasswordReset must be a boolean value'; throw 'revokeSessionOnPasswordReset must be a boolean value';
@@ -81,13 +81,13 @@ export class Config {
this.validateSessionConfiguration(sessionLength, expireInactiveSessions); this.validateSessionConfiguration(sessionLength, expireInactiveSessions);
} }
static validateEmailConfiguration({verifyUserEmails, appName, publicServerURL}) { static validateEmailConfiguration({emailAdapter, appName, publicServerURL}) {
if (verifyUserEmails) { if (emailAdapter) {
if (typeof appName !== 'string') { if (typeof appName !== 'string') {
throw 'An app name is required when using email verification.'; throw 'An app name is required for e-mail verification and password resets.';
} }
if (typeof publicServerURL !== 'string') { if (typeof publicServerURL !== 'string') {
throw 'A public server url is required when using email verification.'; throw 'A public server url is required for e-mail verification and password resets.';
} }
} }
} }

View File

@@ -158,7 +158,7 @@ export class UsersRouter extends ClassesRouter {
handleResetRequest(req) { handleResetRequest(req) {
try { try {
Config.validateEmailConfiguration({ Config.validateEmailConfiguration({
verifyUserEmails: true, //A bit of a hack, as this isn't the intended purpose of this parameter emailAdapter: req.config.userController,
appName: req.config.appName, appName: req.config.appName,
publicServerURL: req.config.publicServerURL, publicServerURL: req.config.publicServerURL,
}); });