Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clever-auth

Package Overview
Dependencies
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clever-auth - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

25

controllers/AccountController.js

@@ -1,2 +0,16 @@

module.exports = function( Controller, AccountService, PermissionController, config, async ) {
var injector = require( 'injector' )
, packageJson = injector.getInstance( 'packageJson' );
module.exports = function( Controller, AccountService, config, async ) {
var autoRouting = [];
if ( packageJson.bundledDependencies.indexOf( 'clever-roles' ) ) {
autoRouting.push(
injector.getInstance( 'PermissionController' ).requiresPermission({
all: 'Account.$action',
postAction: null
})
);
}
var AccountController = Controller.extend(

@@ -15,11 +29,4 @@ /** @Class **/

autoRouting: [
autoRouting: autoRouting,
PermissionController.requiresPermission({
all: 'Account.$action',
postAction: null
})
],
/**

@@ -26,0 +33,0 @@ * Middleware helper function to format data in POST or PUT requests

@@ -415,3 +415,3 @@ var crypto = require( 'crypto' )

password: crypto.createHash( 'sha1' ).update( newPassword ).digest( 'hex' )
} ).success( function ( user ) {
} ).then( function ( user ) {
this.send( {status: 200, results: user} );

@@ -418,0 +418,0 @@ }.bind( this )

@@ -192,3 +192,3 @@ 'use strict';

message: 'Default Username',
default: 'test',
default: 'default',
},

@@ -226,3 +226,3 @@ {

message: 'Default Users Email',
default: 'test@cleverstack.io'
default: 'default@cleverstack.io'
},

@@ -322,2 +322,3 @@ {

if ( foundUser !== false ) {
conf.associations = seed.UserModel[ foundUser ].associations || {};
seed.UserModel.splice( foundUser, 1 );

@@ -324,0 +325,0 @@ }

@@ -71,23 +71,6 @@ var injector = require( 'injector' )

preRoute: function( UserModel, AccountModel, SubscriptionModel, PlanModel, PlanLimitModel ) {
preRoute: function( UserModel, AccountModel ) {
UserModel.on( 'preQuery', function( options ) {
var nestedInclude = {
model : AccountModel._model,
include: [
{
model : SubscriptionModel._model,
as : 'subscription',
include: [
{
model : PlanModel._model,
include: [
{
model : PlanLimitModel._model,
as : 'limits'
}
]
}
]
}
]
model : AccountModel._model
};

@@ -94,0 +77,0 @@

{
"name": "clever-auth",
"description": "CleverStack Authentication Module",
"version": "1.1.0",
"version": "1.1.1",
"main": "module.js",

@@ -35,8 +35,8 @@ "author": {

"passport-google": "~0.3.0",
"passport-local": "~0.1.6",
"passport-local": "~1.0.0",
"connect": "^2.13.0",
"connect-redis": "~1.4.6",
"connect-memcached": "~0.1.0",
"redis": "~0.10.0",
"moment": "~2.5.1"
"redis": "~0.12.1",
"moment": "~2.8.4"
},

@@ -43,0 +43,0 @@ "devDependencies": {

{
"UserModel": []
"UserModel": [
{
"firstname": "Clever",
"lastname": "User",
"email": "default@cleverstack.io",
"username": "default",
"password": "a31a61e94f3799a9385dab9966c4c22c9f5790c4",
"hasAdminRight": true,
"confirmed": true,
"active": true,
"associations": {
"AccountModel": [ { "name": "Default Account" } ]
}
}
],
"AccountModel": [
{
"name": "Default Account",
"email": "default@cleverstack.io",
"subDomain": "default",
"active": true
}
]
}

@@ -1,4 +0,12 @@

var _ = require( 'underscore' );
var injector = require( 'injector' )
, packageJson = injector.getInstance( 'packageJson' )
, PermissionService = null
, RoleService = null;
module.exports = function ( Promise, Service, AccountModel, UserService, PermissionService, RoleService, sequelize, async, config, SiteService ) {
module.exports = function( Promise, Service, AccountModel, UserService, sequelize, async, config, _ ) {
if ( packageJson.bundledDependencies.indexOf( 'clever-roles' ) !== -1 ) {
PermissionService = injector.getInstance( 'PermissionService' );
RoleService = injector.getInstance( 'RoleService' );
}
return Service.extend({

@@ -9,8 +17,8 @@

create: function( data, options ) {
var create = this._super
, service = this
, account = null
var create = this._super
, service = this
, account = null
, permissions = []
, role = null
, user = null;
, role = null
, user = null;

@@ -35,3 +43,3 @@ options = options || {};

email: data.email,
active: !config[ 'clever-roles' ].account.requireConfirmation ? true : false
active: RoleService !== null ? ( !config[ 'clever-roles' ].account.requireConfirmation ? true : false ) : true
};

@@ -55,103 +63,123 @@

function findDefaultPermissions( callback ) {
PermissionService
.findAll({
where: {
AccountId: null,
systemPermission: true
}
}, options)
.then( callback.bind( null, null ) )
.catch( callback );
if ( PermissionService !== null ) {
PermissionService
.findAll({
where: {
AccountId: null,
systemPermission: true
}
}, options)
.then( callback.bind( null, null ) )
.catch( callback );
} else {
callback( null, null );
}
},
function createDefaultPermissions( defaultPermissions, callback ) {
async.forEach(
defaultPermissions,
function createDefaultPermission( defaultPermission, done ) {
PermissionService
.create({
AccountId: account.id,
action: defaultPermission.action,
description: defaultPermission.description,
systemPermission: true
}, options )
.then( function( permission ) {
permissions.push( permission );
done( null );
})
.catch( done );
},
callback
);
if ( PermissionService !== null ) {
async.forEach(
defaultPermissions,
function createDefaultPermission( defaultPermission, done ) {
PermissionService
.create({
AccountId: account.id,
action: defaultPermission.action,
description: defaultPermission.description,
systemPermission: true
}, options )
.then( function( permission ) {
permissions.push( permission );
done( null );
})
.catch( done );
},
callback
);
} else {
callback( null );
}
},
function findDefaultRoles( callback ) {
RoleService
.findAll({
where: {
AccountId: null,
systemRole: true
}
}, options )
.then( callback.bind( null, null ) )
.catch( callback );
if ( RoleService !== null ) {
RoleService
.findAll({
where: {
AccountId: null,
systemRole: true
}
}, options )
.then( callback.bind( null, null ) )
.catch( callback );
} else {
callback( null, null );
}
},
function createDefaultRoles( defaultRoles, callback ) {
async.forEach(
defaultRoles,
function createDefaultRole( defaultRole, done ) {
var rolePermissions = [];
if ( RoleService !== null ) {
async.forEach(
defaultRoles,
function createDefaultRole( defaultRole, done ) {
var rolePermissions = [];
if ( defaultRole.Permissions ) {
defaultRole.Permissions.forEach( function( rolePermission ) {
var defaultPermission = _.findWhere( permissions, { action: rolePermission.action } );
if ( defaultPermission ) {
rolePermissions.push( defaultPermission.id );
}
})
}
if ( defaultRole.Permissions ) {
defaultRole.Permissions.forEach( function( rolePermission ) {
var defaultPermission = _.findWhere( permissions, { action: rolePermission.action } );
if ( defaultPermission ) {
rolePermissions.push( defaultPermission.id );
}
})
}
RoleService
.create({
AccountId: account.id,
systemRole: true,
name: defaultRole.name,
description: defaultRole.description,
Permissions: rolePermissions
}, options )
.then( function( _role ) {
// For now we get the first role and assign the user to that role
if ( role === null ) {
role = _role;
}
done( null );
})
.catch( done );
},
callback
);
RoleService
.create({
AccountId: account.id,
systemRole: true,
name: defaultRole.name,
description: defaultRole.description,
Permissions: rolePermissions
}, options )
.then( function( _role ) {
// For now we get the first role and assign the user to that role
if ( role === null ) {
role = _role;
}
done( null );
})
.catch( done );
},
callback
);
} else {
callback( null );
}
},
function createUser( callback ) {
var userData = {
AccountId: account.id,
title: data.title || null,
firstname: data.firstname,
lastname: data.lastname,
email: data.email,
username: data.username || data.email,
password: data.password,
phone: data.phone || null,
// Implement user options!
active: true,
confirmed: config[ 'clever-auth' ].email_confirmation === true ? false : true,
// Is this actually needed?
hasAdminRight: false
};
if ( RoleService !== null ) {
userData.RoleId = role.id;
}
UserService
.create(
{
AccountId: account.id,
RoleId: role.id,
title: data.title || null,
firstname: data.firstname,
lastname: data.lastname,
email: data.email,
username: data.username || data.email,
password: data.password,
phone: data.phone || null,
// Implement user options!
active: true,
confirmed: false,
// Is this actually needed?
hasAdminRight: false
}, options )
.create( userData, options )
.then( function( _user ) {

@@ -164,73 +192,24 @@ user = _user;

function findDefaultSites( callback ) {
SiteService
.findAll({
where: {
AccountId: null
}
}, options )
.then( callback.bind( null, null ) )
.catch( callback );
},
function createDefaultSites( defaultSites, callback ) {
async.forEach(
defaultSites,
function createDefaultPermission( defaultSite, siteDone ) {
var data = JSON.parse( JSON.stringify( defaultSite ) )
, preference = data.Preferences;
// Cleanup the Site data
delete data.id;
delete data.createdAt;
delete data.updatedAt;
delete data.deletedAt;
delete data.charms;
delete data.Preferences;
data.AccountId = account.id;
data.domainInclusions = account.subDomain + '*';
// Cleanup the Sites Preference data
delete preference.id;
delete preference.SiteId;
delete preference.createdAt;
delete preference.updatedAt;
delete preference.deletedAt;
data.Preferences = preference;
SiteService
.create( data, options )
.then( function() {
siteDone( null );
})
.catch( siteDone );
},
callback
);
}//,
// function authenticateUser( callback ) {
// options.transaction.commit().then( function() {
// UserService
// .authenticate({
// email : user.email,
// password : user.password
// }, options )
// .then( function( _user ) {
// user = _user;
// callback( null );
// })
// .catch( callback );
// });
// }
function authenticateUser( callback ) {
if ( config[ 'clever-auth' ].email_confirmation === true ) {
options.transaction.commit().then( function() {
UserService
.authenticate({
email : user.email,
password : user.password
}, options )
.then( function( _user ) {
user = _user;
callback( null );
})
.catch( callback );
});
} else {
options.transaction.commit().done( callback.bind( null, null ) ).catch( callback );
}
}
],
function createComplete( err ) {
if ( err === null || typeof err === 'undefined' ) {
options
.transaction
.commit()
.done( function() {
resolve( user );
})
.error( reject );
resolve( user );
} else {

@@ -243,3 +222,3 @@ options

})
.error( function( additionalErr ) {
.catch( function( additionalErr ) {
reject( additionalErr + ' was caused by ' + err );

@@ -246,0 +225,0 @@ });

@@ -164,3 +164,3 @@ var crypto = require( 'crypto' )

.find( userId )
.success( function ( user ) {
.then( function ( user ) {

@@ -167,0 +167,0 @@ if ( !user ) {

@@ -15,3 +15,3 @@ var expect = require( 'chai' ).expect

Controller = authModule.controllers.AuthController;
Service = authModule.services.UserService;
Service = injector.getInstance( 'AccountService' );

@@ -23,3 +23,5 @@ Service

email: 'authControllerUser@example.com',
password: 'secret_password'
password: 'secret_password',
confirmed: true,
subDomain: 'authControllerUser'
})

@@ -26,0 +28,0 @@ .then( function( user ) {

@@ -7,2 +7,3 @@ var expect = require( 'chai' ).expect

, Service
, UserService = null
, users = []

@@ -16,3 +17,4 @@ , new_user;

Controller = authModule.controllers.UserController;
Service = Controller.service;
Service = injector.getInstance( 'AccountService' );
UserService = injector.getInstance( 'UserService' );

@@ -24,3 +26,5 @@ Service

email: 'joe@example.com',
password: '7110eda4d09e062aa5e4a390b0a572ac0d2c0220'
password: '7110eda4d09e062aa5e4a390b0a572ac0d2c0220',
confirmed: true,
subDomain: 'joe'
})

@@ -38,3 +42,5 @@ .then( function ( user ) {

email: 'rachel@example.com',
password: '7110eda4d09e062aa5e4a390b0a572ac0d2c0220'
password: '7110eda4d09e062aa5e4a390b0a572ac0d2c0220',
confirmed: true,
subDomain: 'rachel'
});

@@ -201,8 +207,12 @@ })

var data = {
firstName: 'admin',
username: 'admin',
email: 'admin@example.com',
password: 'secret_password'
password: 'secret_password',
confirmed: true,
subDomain: 'admin',
active: true
}
, req = fakeRequest({
url: '/auth/user',
url: '/account',
body: data,

@@ -213,3 +223,3 @@ method: 'POST',

},
user: { hasAdminRights: false, account: {} },
user: { hasAdminRights: false },
login: function( user, fn ) {

@@ -226,5 +236,4 @@ fn( !!user && !!user.id ? null : 'Unknown error' );

Service.findAll( { where: { email: data.email } } )
UserService.findAll( { where: { email: data.email } } )
.then( function ( users ) {
expect( users ).to.be.an( 'array' ).and.have.length( 1 );

@@ -248,3 +257,3 @@

ctrl = Controller.callback( 'newInstance' )( req, res, next );
ctrl = injector.getInstance( 'AccountController' ).callback( 'newInstance' )( req, res, next );
});

@@ -256,6 +265,8 @@

email: users[0].email,
password: 'secret_password'
password: 'secret_password',
confirmed: true,
subDomain: 'userControllerUser'
}
, req = fakeRequest({
url: '/auth/user',
url: '/account',
body: data,

@@ -296,3 +307,3 @@ method: 'POST',

},
user: { hasAdminRights: false, account: { id: 1 } },
user: { hasAdminRights: false, account: { id: 4 } },
login: function( user, fn ) {

@@ -325,3 +336,5 @@ fn( !!user && !!user.id ? null : 'Unknown error' );

password: 'secret_password',
AccountId: 1
AccountId: 1,
confirmed: true,
subDomain: 'cdxsasdf'
})

@@ -353,3 +366,3 @@ .then( function ( user ) {

},
user: { id: new_user.id, hasAdminRights: true, account: { id: 1 } },
user: { id: new_user.id, hasAdminRights: true, account: { id: 4 } },
login: function( user, fn ) {

@@ -388,3 +401,3 @@ fn( !!user && !!user.id ? null : 'Unknown error' );

, next = sinon.spy()
, spy = sinon.spy( Service, 'update' )
, spy = sinon.spy( UserService, 'update' )
, ctrl = null;

@@ -406,3 +419,3 @@

},
user: { hasAdminRights: false, account: { id: 1 } },
user: { hasAdminRights: false, account: { id: 4 } },
login: function( user, fn ) {

@@ -444,3 +457,3 @@ fn( !!user && !!user.id ? null : 'Unknown error' );

},
user: { id: new_user.id, hasAdminRights: true, account: { id: 1 } },
user: { id: new_user.id, hasAdminRights: true, account: { id: 4 } },
login: function( user, fn ) {

@@ -476,3 +489,3 @@ fn( !!user && !!user.id ? null : 'Unknown error' );

, next = sinon.spy()
, spy = sinon.spy( Service, 'update' )
, spy = sinon.spy( UserService, 'update' )
, ctrl = null;

@@ -492,3 +505,4 @@

password: 'secret_password',
AccountId: 1
subDomain: 'listAction',
confirmed: true
})

@@ -507,3 +521,4 @@ .then( function ( user ) {

it( 'Should send all existing users as an array', function( done ) {
var ctrl = null;
var ctrl = null
, lastJson = JSON.parse( JSON.stringify( new_user ) );

@@ -514,3 +529,3 @@ var req = fakeRequest({

params: {},
user: { id: new_user.id, hasAdminRights: true, account: { id: 1 } },
user: { id: new_user.id, hasAdminRights: true, account: { id: 5 } },
login: function( user, fn ) {

@@ -525,4 +540,3 @@ fn( !!user && !!user.id ? null : 'Unknown error' );

var modelJson = JSON.parse( JSON.stringify( result[ result.length - 1 ] ) )
, lastJson = JSON.parse( JSON.stringify( new_user ) );
var modelJson = JSON.parse( JSON.stringify( result[ result.length - 1 ] ) );

@@ -551,3 +565,4 @@ Object.keys( lastJson ).forEach( function( key ) {

password: 'secret_password',
AccountId: 1
subDomain: 'getAction',
confirmed: true
})

@@ -566,5 +581,6 @@ .then( function ( user ) {

it( 'Should be able to get a user by id', function( done ) {
var ctrl = null;
var ctrl = null
, lastJson = JSON.parse( JSON.stringify( new_user ) );
var req = fakeRequest({
var req = fakeRequest({
method: 'GET',

@@ -575,3 +591,3 @@ url: '/auth/user/' + new_user.id,

},
user: { id: new_user.id, hasAdminRights: true, account: { id: 1 } },
user: { id: new_user.id, hasAdminRights: true, account: { id: 6 } },
login: function( user, fn ) {

@@ -586,4 +602,3 @@ fn( !!user && !!user.id ? null : 'Unknown error' );

var modelJson = JSON.parse( JSON.stringify( result ) )
, lastJson = JSON.parse( JSON.stringify( new_user ) );
var modelJson = JSON.parse( JSON.stringify( result ) );

@@ -590,0 +605,0 @@ Object.keys( lastJson ).forEach( function( key ) {

@@ -40,3 +40,4 @@ var expect = require( 'chai' ).expect

email: 'joe@cleverAuth.com',
password: '1234'
password: '1234',
confirmed: true
};

@@ -46,3 +47,4 @@ var rachelsData = {

email: 'rachel@cleverAuth.com',
password: '1234'
password: '1234',
confirmed: true
};

@@ -98,3 +100,4 @@

password: '1234',
active: false
active: false,
confirmed: true
};

@@ -130,3 +133,4 @@

email: 'noduplicates@example.com',
password: '1234'
password: '1234',
confirmed: true
};

@@ -162,3 +166,4 @@

email: 'newUser@cleverAuth.com',
password: '1234'
password: '1234',
confirmed: true
};

@@ -185,3 +190,4 @@

username: 'autoGeneratePassword@cleverAuth.com',
email: 'autoGeneratePassword@cleverAuth.com'
email: 'autoGeneratePassword@cleverAuth.com',
confirmed: true
};

@@ -210,3 +216,4 @@

email: 'rachel21@example.com',
password: '1234'
password: '1234',
confirmed: true
};

@@ -232,3 +239,3 @@

} )
.fail( done );
.catch( done );
});

@@ -243,3 +250,4 @@

email: 'rachel22@example.com',
password: '1234'
password: '1234',
confirmed: true
};

@@ -265,3 +273,3 @@

} )
.fail( done );
.catch( done );
});

@@ -277,3 +285,4 @@ });

email: 'hashPassword@cleverAuth.com',
password: '1234'
password: '1234',
confirmed: true
};

@@ -354,3 +363,3 @@ var originalPassword = null;

} )
.fail( done );
.catch( done );
});

@@ -399,3 +408,3 @@

} )
.fail( done );
.catch( done );
});

@@ -407,3 +416,4 @@

email: 'rachel13@example.com',
password: '1234'
password: '1234',
confirmed: true
};

@@ -421,3 +431,3 @@

} )
.fail( done );
.catch( done );
});

@@ -452,3 +462,3 @@ });

} )
.fail( done );
.catch( done );
});

@@ -472,3 +482,3 @@

})
.fail( done );
.catch( done );
});

@@ -492,3 +502,3 @@

} )
.fail( done );
.catch( done );
});

@@ -537,3 +547,3 @@ });

} )
.fail( done );
.catch( done );
});

@@ -565,3 +575,3 @@

} )
.fail( done );
.catch( done );
});

@@ -602,3 +612,3 @@

} )
.fail( done );
.catch( done );
});

@@ -639,3 +649,3 @@

} )
.fail( done );
.catch( done );
});

@@ -669,5 +679,5 @@

} )
.fail( done );
.catch( done );
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc