Improves validation of email parameters in Configuration

This commit is contained in:
Florent Vilmart
2016-02-28 00:15:59 -05:00
parent 2183b0be82
commit 6aa38ea8ca
4 changed files with 34 additions and 30 deletions

View File

@@ -39,6 +39,29 @@ export class Config {
this.mount = mount; this.mount = mount;
} }
static validate(options) {
this.validateEmailConfiguration({verifyUserEmails: options.verifyUserEmails,
appName: options.appName,
publicServerURL: options.publicServerURL})
}
static validateEmailConfiguration({verifyUserEmails, appName, publicServerURL}) {
if (verifyUserEmails) {
if (typeof appName !== 'string') {
throw 'An app name is required when using email verification.';
}
if (!process.env.TESTING && typeof publicServerURL !== 'string') {
if (process.env.NODE_ENV === 'production') {
throw 'A public server url is required when using email verification.';
} else {
console.warn("");
console.warn("You should set publicServerURL to serve the public pages");
console.warn("");
}
}
}
}
get linksServerURL() { get linksServerURL() {
return this.publicServerURL || this.serverURL; return this.publicServerURL || this.serverURL;
} }

View File

@@ -16,8 +16,8 @@ export class AdaptableController {
constructor(adapter, appId, options) { constructor(adapter, appId, options) {
this.options = options; this.options = options;
this.adapter = adapter;
this.appId = appId; this.appId = appId;
this.adapter = adapter;
} }
set adapter(adapter) { set adapter(adapter) {
@@ -62,8 +62,7 @@ export class AdaptableController {
}, {}); }, {});
if (Object.keys(mismatches).length > 0) { if (Object.keys(mismatches).length > 0) {
console.error(adapter, mismatches); throw new Error("Adapter prototype don't match expected prototype", adapter, mismatches);
throw new Error("Adapter prototype don't match expected prototype");
} }
} }
} }

View File

@@ -163,15 +163,11 @@ export class UserController extends AdaptableController {
const username = encodeURIComponent(user.username); const username = encodeURIComponent(user.username);
let link = `${this.config.requestResetPasswordURL}?token=${token}&username=${username}` let link = `${this.config.requestResetPasswordURL}?token=${token}&username=${username}`
if (!user.username) {
console.log('No username...');
}
let options = { let options = {
appName: this.config.appName, appName: this.config.appName,
link: link, link: link,
user: inflate('_User', user), user: inflate('_User', user),
}; };
if (this.adapter.sendPasswordResetEmail) { if (this.adapter.sendPasswordResetEmail) {
this.adapter.sendPasswordResetEmail(options); this.adapter.sendPasswordResetEmail(options);

View File

@@ -11,6 +11,7 @@ var batch = require('./batch'),
Parse = require('parse/node').Parse; Parse = require('parse/node').Parse;
import cache from './cache'; import cache from './cache';
import Config from './Config';
import ParsePushAdapter from './Adapters/Push/ParsePushAdapter'; import ParsePushAdapter from './Adapters/Push/ParsePushAdapter';
//import passwordReset from './passwordReset'; //import passwordReset from './passwordReset';
@@ -72,17 +73,6 @@ addParseCloud();
// "javascriptKey": optional key from Parse dashboard // "javascriptKey": optional key from Parse dashboard
// "push": optional key from configure push // "push": optional key from configure push
let validateEmailConfiguration = (verifyUserEmails, appName, emailAdapter) => {
if (verifyUserEmails) {
if (typeof appName !== 'string') {
throw 'An app name is required when using email verification.';
}
if (!emailAdapter) {
throw 'User email verification was enabled, but no email adapter was provided';
}
}
}
function ParseServer({ function ParseServer({
appId = requiredParameter('You must provide an appId!'), appId = requiredParameter('You must provide an appId!'),
masterKey = requiredParameter('You must provide a masterKey!'), masterKey = requiredParameter('You must provide a masterKey!'),
@@ -128,12 +118,6 @@ function ParseServer({
DatabaseAdapter.setAppDatabaseURI(appId, databaseURI); DatabaseAdapter.setAppDatabaseURI(appId, databaseURI);
} }
if (verifyUserEmails && !publicServerURL && !process.env.TESTING) {
console.warn("");
console.warn("You should set publicServerURL to serve the public pages");
console.warn("");
}
if (cloud) { if (cloud) {
addParseCloud(); addParseCloud();
if (typeof cloud === 'function') { if (typeof cloud === 'function') {
@@ -187,6 +171,8 @@ function ParseServer({
cache.apps.get(appId)['facebookAppIds'].push(process.env.FACEBOOK_APP_ID); cache.apps.get(appId)['facebookAppIds'].push(process.env.FACEBOOK_APP_ID);
} }
Config.validate(cache.apps.get(appId));
// This app serves the Parse API directly. // This app serves the Parse API directly.
// It's the equivalent of https://api.parse.com/1 in the hosted Parse API. // It's the equivalent of https://api.parse.com/1 in the hosted Parse API.
var api = express(); var api = express();