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;
}
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() {
return this.publicServerURL || this.serverURL;
}

View File

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

View File

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

View File

@@ -11,6 +11,7 @@ var batch = require('./batch'),
Parse = require('parse/node').Parse;
import cache from './cache';
import Config from './Config';
import ParsePushAdapter from './Adapters/Push/ParsePushAdapter';
//import passwordReset from './passwordReset';
@@ -72,17 +73,6 @@ addParseCloud();
// "javascriptKey": optional key from Parse dashboard
// "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({
appId = requiredParameter('You must provide an appId!'),
masterKey = requiredParameter('You must provide a masterKey!'),
@@ -127,13 +117,7 @@ function ParseServer({
if (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) {
addParseCloud();
if (typeof cloud === 'function') {
@@ -186,6 +170,8 @@ function ParseServer({
if (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.
// It's the equivalent of https://api.parse.com/1 in the hosted Parse API.