Skip to content

Commit

Permalink
Updating/mergin config file
Browse files Browse the repository at this point in the history
  • Loading branch information
MKHenson committed Mar 13, 2017
1 parent e54d2fc commit bff2d9c
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 19 deletions.
24 changes: 12 additions & 12 deletions src/controllers/auth-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ 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
* @param userCollection The mongo collection that stores the users
* @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;
Expand All @@ -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', <any>[ 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', <any>[ ownerRights, this.approveActivation.bind( this ) ] );

// Register the path
e.use( config.apiPrefix, router );
e.use( '/auth', router );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/error-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/user-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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
* @param userCollection The mongo collection that stores the users
* @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;
Expand Down
124 changes: 124 additions & 0 deletions src/definitions/custom/modepress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions src/dist-src/example-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/references.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/// <reference path="./definitions/required/yargs.d.ts" />
/// <reference path="./definitions/required/request.d.ts" />
/// <reference path="./definitions/required/sanitize-html.d.ts" />
/// <reference path="./definitions/required/users.d.ts" />
/// <reference path="./definitions/custom/users.d.ts" />
/// <reference path='./definitions/required/bcrypt.d.ts' />
/// <reference path='./definitions/required/compressible.d.ts' />
/// <reference path='./definitions/required/gcloud.d.ts' />
Expand Down
6 changes: 3 additions & 3 deletions src/socket-api/comms-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,7 +121,7 @@ export class CommsController extends events.EventEmitter {
async onWsConnection( ws: ws ): Promise<void> {
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;
Expand Down

0 comments on commit bff2d9c

Please sign in to comment.