Skip to content

Commit

Permalink
Merged users definition into Modepress definition
Browse files Browse the repository at this point in the history
  • Loading branch information
MKHenson committed Mar 30, 2017
1 parent 2acf85a commit da92402
Show file tree
Hide file tree
Showing 24 changed files with 578 additions and 761 deletions.
10 changes: 0 additions & 10 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ gulp.task( 'tslint', [ 'ts-code' ], function() {
}) )
});

/**
* Downloads the definition files used in the development of the application and moves them into the definitions folder
*/
gulp.task( 'install-definitions', function() {
return Promise.all( [
setup.getDefinition( "https://raw.githubusercontent.com/MKHenson/users/dev/src/definitions/generated/users.d.ts", "src/definitions/required/", "users.d.ts" )
] );
});

/**
* Copies the distribution files from src to the dist folder
*/
Expand All @@ -66,5 +57,4 @@ gulp.task( 'ts-code-definitions', function() {
gulp.task( 'bump-patch', function() { return setup.bumpVersion( setup.bumpPatchNum, configFiles ) });
gulp.task( 'bump-minor', function() { return setup.bumpVersion( setup.bumpMidNum, configFiles ) });
gulp.task( 'bump-major', function() { return setup.bumpVersion( setup.bumpMajorNum, configFiles ) });
gulp.task( 'install', [ 'install-definitions' ] );
gulp.task( 'build', [ 'tslint', 'dist-files', 'ts-code-definitions' ] );
9 changes: 4 additions & 5 deletions src/bucket-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import * as users from 'webinate-users';
import * as users from 'modepress-api';
import * as fs from 'fs';
import * as gcloud from 'gcloud';
import * as mongodb from 'mongodb';
Expand All @@ -11,7 +11,6 @@ import express = require( 'express' );
import { CommsController } from './socket-api/comms-controller';
import { ClientInstructionType } from './socket-api/socket-event-types';
import { ClientInstruction } from './socket-api/client-instruction';
import * as def from 'webinate-users';
import * as yargs from 'yargs';

const args = yargs.argv;
Expand Down Expand Up @@ -243,7 +242,7 @@ export class BucketManager {
await stats.updateOne( <users.IStorageStats>{ user: user }, { $inc: <users.IStorageStats>{ apiCallsUsed: 1 } } );

// Send bucket added events to sockets
const token: def.SocketTokens.IBucketToken = { type: ClientInstructionType[ ClientInstructionType.BucketUploaded ], bucket: bucketEntry!, username: user };
const token: users.SocketTokens.IBucketToken = { type: ClientInstructionType[ ClientInstructionType.BucketUploaded ], bucket: bucketEntry!, username: user };
await CommsController.singleton.processClientInstruction( new ClientInstruction( token, null, user ) );
return gBucket;
}
Expand Down Expand Up @@ -344,7 +343,7 @@ export class BucketManager {
await stats.updateOne( <users.IStorageStats>{ user: bucketEntry.user }, { $inc: <users.IStorageStats>{ apiCallsUsed: 1 } } );

// Send events to sockets
const token: def.SocketTokens.IBucketToken = { type: ClientInstructionType[ ClientInstructionType.BucketRemoved ], bucket: bucketEntry, username: bucketEntry.user! };
const token: users.SocketTokens.IBucketToken = { type: ClientInstructionType[ ClientInstructionType.BucketRemoved ], bucket: bucketEntry, username: bucketEntry.user! };
await CommsController.singleton.processClientInstruction( new ClientInstruction( token, null, bucketEntry.user ) );

return bucketEntry;
Expand Down Expand Up @@ -395,7 +394,7 @@ export class BucketManager {
await stats.updateOne( <users.IStorageStats>{ user: bucketEntry.user }, { $inc: <users.IStorageStats>{ memoryUsed: -fileEntry.size!, apiCallsUsed: 1 } } );

// Update any listeners on the sockets
const token: def.SocketTokens.IFileToken = { type: ClientInstructionType[ ClientInstructionType.FileRemoved ], file: fileEntry, username: fileEntry.user! };
const token: users.SocketTokens.IFileToken = { type: ClientInstructionType[ ClientInstructionType.FileRemoved ], file: fileEntry, username: fileEntry.user! };
await CommsController.singleton.processClientInstruction( new ClientInstruction( token, null, fileEntry.user ) );

return fileEntry;
Expand Down
3 changes: 1 addition & 2 deletions src/controllers/admin-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import express = require( 'express' );
import bodyParser = require( 'body-parser' );
import * as def from 'webinate-users';
import { UserManager } from '../users';
import { Controller } from './controller'
import { okJson, errJson } from '../serializers';
Expand Down Expand Up @@ -45,7 +44,7 @@ export class AdminController extends Controller {
throw new Error( 'Please specify a message to send' );

await UserManager.get.sendAdminEmail( token.message, token.name, token.from );
okJson<def.IResponse>( { error: false, message: 'Your message has been sent to the support team' }, res );
okJson<Modepress.IResponse>( { error: false, message: 'Your message has been sent to the support team' }, res );

} catch ( err ) {
return errJson( err, res );
Expand Down
25 changes: 12 additions & 13 deletions src/controllers/auth-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import express = require( 'express' );
import bodyParser = require( 'body-parser' );
import * as def from 'webinate-users';
import { UserManager } from '../users';
import { ownerRights } from '../permission-controllers';
import { Controller } from './controller'
Expand Down Expand Up @@ -79,7 +78,7 @@ export class AuthController extends Controller {
const origin = encodeURIComponent( req.headers[ 'origin' ] || req.headers[ 'referer' ] );

await UserManager.get.resendActivation( req.params.user, this._server.accountRedirectURL, origin );
okJson<def.IResponse>( { error: false, message: 'An activation link has been sent, please check your email for further instructions' }, res );
okJson<Modepress.IResponse>( { error: false, message: 'An activation link has been sent, please check your email for further instructions' }, res );

} catch ( err ) {
return errJson( err, res );
Expand All @@ -95,7 +94,7 @@ export class AuthController extends Controller {

await UserManager.get.requestPasswordReset( req.params.user, this._server.passwordResetURL, origin );

okJson<def.IResponse>( { error: false, message: 'Instructions have been sent to your email on how to change your password' }, res );
okJson<Modepress.IResponse>( { error: false, message: 'Instructions have been sent to your email on how to change your password' }, res );

} catch ( err ) {
return errJson( err, res );
Expand All @@ -119,7 +118,7 @@ export class AuthController extends Controller {
// Check the user's activation and forward them onto the admin message page
await UserManager.get.resetPassword( req.body.user, req.body.key, req.body.password );

okJson<def.IResponse>( { error: false, message: 'Your password has been reset' }, res );
okJson<Modepress.IResponse>( { error: false, message: 'Your password has been reset' }, res );

} catch ( err ) {
return errJson( err, res );
Expand All @@ -132,7 +131,7 @@ export class AuthController extends Controller {
private async approveActivation( req: express.Request, res: express.Response ) {
try {
await UserManager.get.approveActivation( req.params.user );
okJson<def.IResponse>( { error: false, message: 'Activation code has been approved' }, res );
okJson<Modepress.IResponse>( { error: false, message: 'Activation code has been approved' }, res );

} catch ( err ) {
return errJson( err, res );
Expand All @@ -144,10 +143,10 @@ export class AuthController extends Controller {
*/
private async login( req: express.Request, res: express.Response ) {
try {
const token: def.ILoginToken = req.body;
const token: Modepress.ILoginToken = req.body;
const user = await UserManager.get.logIn( token.username, token.password, token.rememberMe, req, res );

okJson<def.IAuthenticationResponse>( {
okJson<Modepress.IAuthenticationResponse>( {
message: ( user ? 'User is authenticated' : 'User is not authenticated' ),
authenticated: ( user ? true : false ),
user: ( user ? user.generateCleanedData( Boolean( req.query.verbose ) ) : {} ),
Expand All @@ -156,7 +155,7 @@ export class AuthController extends Controller {

} catch ( err ) {

okJson<def.IAuthenticationResponse>( {
okJson<Modepress.IAuthenticationResponse>( {
message: err.message,
authenticated: false,
error: true
Expand All @@ -170,7 +169,7 @@ export class AuthController extends Controller {
private async logout( req: express.Request, res: express.Response ) {
try {
await UserManager.get.logOut( req, res );
okJson<def.IResponse>( { error: false, message: 'Successfully logged out' }, res );
okJson<Modepress.IResponse>( { error: false, message: 'Successfully logged out' }, res );

} catch ( err ) {
return errJson( err, res );
Expand All @@ -182,10 +181,10 @@ export class AuthController extends Controller {
*/
private async register( req: express.Request, res: express.Response ) {
try {
const token: def.IRegisterToken = req.body;
const token: Modepress.IRegisterToken = req.body;
const user = await UserManager.get.register( token.username!, token.password!, token.email!, this._server.accountRedirectURL, {}, req );

return okJson<def.IAuthenticationResponse>( {
return okJson<Modepress.IAuthenticationResponse>( {
message: ( user ? 'Please activate your account with the link sent to your email address' : 'User is not authenticated' ),
authenticated: ( user ? true : false ),
user: ( user ? user.generateCleanedData( Boolean( req.query.verbose ) ) : {} ),
Expand All @@ -203,15 +202,15 @@ export class AuthController extends Controller {
private async authenticated( req: express.Request, res: express.Response ) {
try {
const user = await UserManager.get.loggedIn( req, res );
return okJson<def.IAuthenticationResponse>( {
return okJson<Modepress.IAuthenticationResponse>( {
message: ( user ? 'User is authenticated' : 'User is not authenticated' ),
authenticated: ( user ? true : false ),
error: false,
user: ( user ? user.generateCleanedData( Boolean( req.query.verbose ) ) : {} )
}, res );

} catch ( error ) {
return okJson<def.IAuthenticationResponse>( {
return okJson<Modepress.IAuthenticationResponse>( {
message: error.message,
authenticated: false,
error: true
Expand Down
7 changes: 3 additions & 4 deletions src/controllers/bucket-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import express = require( 'express' );
import bodyParser = require( 'body-parser' );
import * as users from 'webinate-users';
import * as users from 'modepress-api';
import * as mongodb from 'mongodb';
import { UserManager } from '../users';
import { ownerRights, requireUser } from '../permission-controllers';
Expand All @@ -13,7 +13,6 @@ import * as compression from 'compression';
import { CommsController } from '../socket-api/comms-controller';
import { ClientInstruction } from '../socket-api/client-instruction';
import { ClientInstructionType } from '../socket-api/socket-event-types';
import * as def from 'webinate-users';
import { okJson, errJson } from '../serializers';
import { Model } from '../models/model';
import { BucketModel } from '../models/bucket-model';
Expand Down Expand Up @@ -229,7 +228,7 @@ export class BucketController extends Controller {
const manager = BucketManager.get;
const username = req._user!.username!;
const parentFile = req.params.parentFile;
const filesUploaded: Array<UsersInterface.IFileEntry> = [];
const filesUploaded: Array<users.IFileEntry> = [];
const bucketName = req.params.bucket;
if ( !bucketName || bucketName.trim() === '' )
return okJson<users.IUploadResponse>( { message: `Please specify a bucket`, error: true, tokens: [] }, res );
Expand Down Expand Up @@ -398,7 +397,7 @@ export class BucketController extends Controller {
// Notify the sockets of each file that was uploaded
for ( let i = 0, l = files.length; i < l; i++ ) {
// Send file added events to sockets
const token: def.SocketTokens.IFileToken = { username: user, type: ClientInstructionType[ ClientInstructionType.FileUploaded ], file: files[ i ] };
const token: users.SocketTokens.IFileToken = { username: user, type: ClientInstructionType[ ClientInstructionType.FileUploaded ], file: files[ i ] };
await CommsController.singleton.processClientInstruction( new ClientInstruction( token, null, user ) )
}

Expand Down
3 changes: 1 addition & 2 deletions src/controllers/error-controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

import * as def from 'webinate-users';
import { Controller } from './controller'
import express = require( 'express' );

Expand All @@ -18,7 +17,7 @@ export class ErrorController extends Controller {
// Handle all errors the same way
e.use( function( err: Error, req: express.Request, res: express.Response, next: Function ) {
res.setHeader( 'Content-Type', 'application/json' );
return res.end( JSON.stringify( <def.IResponse>{ message: err.toString(), error: true } ) );
return res.end( JSON.stringify( <Modepress.IResponse>{ message: err.toString(), error: true } ) );
} );
}
}
5 changes: 2 additions & 3 deletions src/controllers/file-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import express = require( 'express' );
import bodyParser = require( 'body-parser' );
import * as users from 'webinate-users';
import * as users from 'modepress-api';
import { ownerRights, requireUser } from '../permission-controllers';
import { Controller } from './controller'
import { BucketManager } from '../bucket-manager';
import * as compression from 'compression';
import { error as logError } from '../logger';
import * as def from 'webinate-users';
import { okJson, errJson } from '../serializers';
import { Model } from '../models/model';
import { BucketModel } from '../models/bucket-model';
Expand Down Expand Up @@ -95,7 +94,7 @@ export class FileController extends Controller {
throw new Error( `Could not find the file '${req.params.file}'` );

await manager.renameFile( fileEntry, req.body.name );
okJson<def.IResponse>( { message: `Renamed file to '${req.body.name}'`, error: false }, res );
okJson<users.IResponse>( { message: `Renamed file to '${req.body.name}'`, error: false }, res );

} catch ( err ) {
return errJson( err, res );
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/posts-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default class PostsController extends Controller {
private async getPost( req: Modepress.IAuthReq, res: express.Response ) {
const posts = this.getModel( 'posts' );
let findToken: Modepress.IPost;
const user: UsersInterface.IUserEntry = req._user!;
const user: Modepress.IUserEntry = req._user!;

try {
if ( req.params.id )
Expand Down
5 changes: 2 additions & 3 deletions src/controllers/session-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import express = require( 'express' );
import bodyParser = require( 'body-parser' );
import * as def from 'webinate-users';
import { UserManager } from '../users';
import { ownerRights } from '../permission-controllers';
import { Controller } from './controller'
Expand Down Expand Up @@ -50,7 +49,7 @@ export class SessionController extends Controller {
const numSessions = await UserManager.get.sessionManager.numActiveSessions();
const sessions = await UserManager.get.sessionManager.getActiveSessions( parseInt( req.query.index ), parseInt( req.query.limit ) )

okJson<def.IGetSessions>( {
okJson<Modepress.IGetSessions>( {
error: false,
message: `Found ${sessions.length} active sessions`,
data: sessions,
Expand All @@ -68,7 +67,7 @@ export class SessionController extends Controller {
private async deleteSession( req: express.Request, res: express.Response ) {
try {
await UserManager.get.sessionManager.clearSession( req.params.id, req, res );
okJson<def.IResponse>( { error: false, message: `Session ${req.params.id} has been removed` }, res );
okJson<Modepress.IResponse>( { error: false, message: `Session ${req.params.id} has been removed` }, res );

} catch ( err ) {
return errJson( err, res );
Expand Down
Loading

0 comments on commit da92402

Please sign in to comment.