From bff2d9cd176cc1451e0950008c18c5bf6dc3d933 Mon Sep 17 00:00:00 2001 From: Mathew Henson Date: Mon, 13 Mar 2017 22:36:11 +0000 Subject: [PATCH] Updating/mergin config file --- src/controllers/auth-controller.ts | 24 ++--- src/controllers/error-controller.ts | 2 +- src/controllers/user-controller.ts | 4 +- src/definitions/custom/modepress.d.ts | 124 ++++++++++++++++++++++++++ src/dist-src/example-config.json | 19 ++++ src/references.d.ts | 2 +- src/socket-api/comms-controller.ts | 6 +- 7 files changed, 162 insertions(+), 19 deletions(-) diff --git a/src/controllers/auth-controller.ts b/src/controllers/auth-controller.ts index d6af5cde..44c8d64b 100644 --- a/src/controllers/auth-controller.ts +++ b/src/controllers/auth-controller.ts @@ -16,7 +16,7 @@ import { UsersModel } from '../models/users-model'; * Main class to use for managing users */ export class AuthController extends Controller { - private _config: def.IConfig; + private _config: Modepress.IConfig; /** * Creates an instance of the user manager @@ -24,7 +24,7 @@ export class AuthController extends Controller { * @param sessionCollection The mongo collection that stores the session data * @param The config options of this manager */ - constructor( e: express.Express, config: def.IConfig ) { + constructor( e: express.Express, config: Modepress.IConfig ) { super([ Model.registerModel(UsersModel) ]); this._config = config; @@ -36,18 +36,18 @@ export class AuthController extends Controller { router.use( bodyParser.json() ); router.use( bodyParser.json( { type: 'application/vnd.api+json' } ) ); - router.get( '/auth/authenticated', this.authenticated.bind( this ) ); - router.get( '/auth/logout', this.logout.bind( this ) ); - router.get( '/auth/activate-account', this.activateAccount.bind( this ) ); - router.post( '/auth/login', this.login.bind( this ) ); - router.post( '/auth/register', this.register.bind( this ) ); - router.put( '/auth/password-reset', this.passwordReset.bind( this ) ); - router.get( '/auth/:user/resend-activation', this.resendActivation.bind( this ) ); - router.get( '/auth/:user/request-password-reset', this.requestPasswordReset.bind( this ) ); - router.put( '/auth/:user/approve-activation', [ ownerRights, this.approveActivation.bind( this ) ] ); + router.get( '/authenticated', this.authenticated.bind( this ) ); + router.get( '/logout', this.logout.bind( this ) ); + router.get( '/activate-account', this.activateAccount.bind( this ) ); + router.post( '/login', this.login.bind( this ) ); + router.post( '/register', this.register.bind( this ) ); + router.put( '/password-reset', this.passwordReset.bind( this ) ); + router.get( '/:user/resend-activation', this.resendActivation.bind( this ) ); + router.get( '/:user/request-password-reset', this.requestPasswordReset.bind( this ) ); + router.put( '/:user/approve-activation', [ ownerRights, this.approveActivation.bind( this ) ] ); // Register the path - e.use( config.apiPrefix, router ); + e.use( '/auth', router ); } /** diff --git a/src/controllers/error-controller.ts b/src/controllers/error-controller.ts index 21cfb798..2305ae88 100644 --- a/src/controllers/error-controller.ts +++ b/src/controllers/error-controller.ts @@ -13,7 +13,7 @@ export class ErrorController extends Controller { * Creates an instance */ constructor( e: express.Express ) { - super(); + super(null); // Handle all errors the same way e.use( function( err: Error, req: express.Request, res: express.Response ) { diff --git a/src/controllers/user-controller.ts b/src/controllers/user-controller.ts index 203afe8a..a2aa4f1a 100644 --- a/src/controllers/user-controller.ts +++ b/src/controllers/user-controller.ts @@ -15,7 +15,7 @@ import { UsersModel } from '../models/users-model'; * Main class to use for managing users */ export class UserController extends Controller { - private _config: def.IConfig; + private _config: Modepress.IConfig; /** * Creates an instance of the user manager @@ -23,7 +23,7 @@ export class UserController extends Controller { * @param sessionCollection The mongo collection that stores the session data * @param The config options of this manager */ - constructor( e: express.Express, config: def.IConfig ) { + constructor( e: express.Express, config: Modepress.IConfig ) { super([ Model.registerModel( UsersModel ) ]); this._config = config; diff --git a/src/definitions/custom/modepress.d.ts b/src/definitions/custom/modepress.d.ts index 0eb6207a..f6a89122 100644 --- a/src/definitions/custom/modepress.d.ts +++ b/src/definitions/custom/modepress.d.ts @@ -248,10 +248,89 @@ variables: { [ name: string ]: string }; } + export interface IMailOptions { } + + /** + * Options for a gmail mailer + */ + export interface IGMail extends IMailOptions { + /* + * The email account to use the gmail API through. This account must be authorized to + * use this application. See: https://admin.google.com/AdminHome?fral=1#SecuritySettings: + */ + apiEmail: string; + + /* + * Path to the key file + */ + keyFile: string; + } + + /** + * Options for a mailgun mailer + */ + export interface IMailgun extends IMailOptions { + /** + * The domain for associated with the mailgun account + */ + domain: string; + + /** + * The api key for your mailgun account + */ + apiKey: string; + } + + /* + * Users stores data on an external cloud bucket with Google + */ + export interface IGoogleProperties { + /* + * Path to the key file + */ + keyFile: string; + + /* + * Describes the bucket details + */ + bucket: { + + /* + * Project ID + */ + projectId: string; + + /** + * The name of the mongodb collection for storing bucket details + * eg: 'buckets' + */ + bucketsCollection: string; + + /** + * The name of the mongodb collection for storing file details + * eg: 'files' + */ + filesCollection: string; + + /** + * The name of the mongodb collection for storing user stats + * eg: 'storageAPI' + */ + statsCollection: string; + + /** + * The length of time the assets should be cached on a user's browser. + * eg: 2592000000 or 30 days + */ + cacheLifetime: number; + } + } + /** * A server configuration */ export interface IConfig { + /** * The length of time the assets should be cached on a user's browser. The default is 30 days. */ @@ -315,6 +394,51 @@ * eg: 'this-is-my-key' */ usersSocketApiKey: string; + + /** + * If debug is true, certain functions will be emulated and more information logged + */ + debug: boolean; + + /** + * Settings related to sending emails + */ + mail: { + + /** + * The from field sent to recipients + */ + from: string; + + /** + * Specify the type of mailer to use. + * Currently we support either 'gmail' or 'mailgun' + */ + type: 'gmail' | 'mailgun'; + + /** + * Options to be sent to the desired mailer + */ + options: IGMail | IMailgun; + } + + /** + * Information relating to the Google storage platform + * + 'google': { + 'keyFile': '', + 'mail':{ + 'apiEmail': '', + 'from': '' + }, + 'bucket': { + 'projectId': '', + 'bucketsCollection': 'buckets', + 'filesCollection': 'files' + } + } + */ + google: IGoogleProperties; } export interface IAuthReq extends Express.Request { diff --git a/src/dist-src/example-config.json b/src/dist-src/example-config.json index 58ab97c0..497b2199 100644 --- a/src/dist-src/example-config.json +++ b/src/dist-src/example-config.json @@ -9,6 +9,25 @@ "usersSocketURL": "ws://www.webinate.net:8063", "usersSocketOrigin": "webinate.net", "usersSocketApiKey": "my-secret-key", + "debug": true, + "mail": { + "type": "mailgun", + "from": "webinate", + "options": { + "domain": "", + "apiKey": "" + } + }, + "google": { + "keyFile": "", + "bucket": { + "projectId": "", + "bucketsCollection": "buckets", + "filesCollection": "files", + "statsCollection": "storageAPI", + "cacheLifetime": 2592000000 + } + }, "servers": [ { "host": "localhost", diff --git a/src/references.d.ts b/src/references.d.ts index a028e13d..0c3b0ff0 100644 --- a/src/references.d.ts +++ b/src/references.d.ts @@ -13,7 +13,7 @@ /// /// /// -/// +/// /// /// /// diff --git a/src/socket-api/comms-controller.ts b/src/socket-api/comms-controller.ts index 34a62dd0..b2ed305b 100644 --- a/src/socket-api/comms-controller.ts +++ b/src/socket-api/comms-controller.ts @@ -22,12 +22,12 @@ export class CommsController extends events.EventEmitter { private _server: ws.Server; private _connections: ClientConnection[]; private _hashedApiKey: string; - private _cfg: def.IConfig; + private _cfg: Modepress.IConfig; /** * Creates an instance of the Communication server */ - constructor( cfg: def.IConfig ) { + constructor( cfg: Modepress.IConfig ) { super(); CommsController.singleton = this; @@ -121,7 +121,7 @@ export class CommsController extends events.EventEmitter { async onWsConnection( ws: ws ): Promise { let headers = ws.upgradeReq.headers; - if ( this._cfg.debugMode ) + if ( this._cfg.debug ) winston.info( `Websocket client connected: ${headers.origin}`, { process: process.pid } ) let clientApproved = false;