Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Format code according to ESLint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ilanbiala committed Oct 17, 2015
1 parent e30c3d1 commit 0323696
Show file tree
Hide file tree
Showing 15 changed files with 243 additions and 244 deletions.
28 changes: 14 additions & 14 deletions config/lib/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ var seedOptions = {};
function removeUser (user) {
return new Promise(function (resolve, reject) {
var User = mongoose.model('User');
User.find({username: user.username}).remove(function (err) {
if (err) {
reject(new Error('Failed to remove local ' + user.username));
}
resolve();
User.find({ username: user.username }).remove(function (err) {
if (err) {
reject(new Error('Failed to remove local ' + user.username));
}
resolve();
});
});
}
Expand All @@ -39,16 +39,16 @@ function saveUser (user) {
function checkUserNotExists (user) {
return new Promise(function (resolve, reject) {
var User = mongoose.model('User');
User.find({username: user.username}, function (err, users) {
if (err) {
reject(new Error('Failed to find local account ' + user.username));
}
User.find({ username: user.username }, function (err, users) {
if (err) {
reject(new Error('Failed to find local account ' + user.username));
}

if (users.length === 0) {
resolve();
} else {
reject(new Error('Failed due to local account already exists: ' + user.username));
}
if (users.length === 0) {
resolve();
} else {
reject(new Error('Failed due to local account already exists: ' + user.username));
}
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ angular.module('core')
return linkFn;
}
};
}]);
}]);
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
describe('authInterceptor', function() {
//Initialize global variables
var authInterceptor,
$q,
$state,
httpProvider;
$q,
$state,
httpProvider;

// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
Expand All @@ -25,11 +25,11 @@
}));

it('Auth Interceptor should be object', function() {
expect( typeof authInterceptor).toEqual('object');
expect(typeof authInterceptor).toEqual('object');
});

it('Auth Interceptor should contain responseError function', function() {
expect( typeof authInterceptor.responseError).toEqual('function');
expect(typeof authInterceptor.responseError).toEqual('function');
});

it('httpProvider Interceptor should have authInterceptor', function() {
Expand All @@ -38,19 +38,25 @@

describe('Forbidden Interceptor', function() {
it('should redirect to forbidden route', function () {
var response = {status:403,config:{}};
var promise = authInterceptor.responseError(response);
expect($q.reject).toHaveBeenCalled();
expect($state.transitionTo).toHaveBeenCalledWith('forbidden');
var response = {
status: 403,
config: {}
};
var promise = authInterceptor.responseError(response);
expect($q.reject).toHaveBeenCalled();
expect($state.transitionTo).toHaveBeenCalledWith('forbidden');
});
});

describe('Authorization Interceptor', function() {
it('should redirect to signIn page for unauthorized access', function () {
var response = {status:401,config:{}};
var promise = authInterceptor.responseError(response);
expect($q.reject).toHaveBeenCalled();
expect($state.transitionTo).toHaveBeenCalledWith('authentication.signin');
var response = {
status: 401,
config: {}
};
var promise = authInterceptor.responseError(response);
expect($q.reject).toHaveBeenCalled();
expect($state.transitionTo).toHaveBeenCalledWith('authentication.signin');
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion modules/core/tests/client/menus.client.service.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@
Menus.addMenu(menuId);
Menus.addMenuItem(menuId, menuItem1Options);
Menus.addMenuItem(menuId, menuItem2Options);
Menus.addMenuItem(menuId, {state:'something.else'});
Menus.addMenuItem(menuId, { state: 'something.else' });
Menus.addSubMenuItem(menuId, menuItem1Options.state, subItemOptions);
menu = Menus.addSubMenuItem(menuId, menuItem1Options.state);
menuItem1 = menu.items[0];
Expand Down
24 changes: 12 additions & 12 deletions modules/core/tests/server/core.server.config.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ describe('Configuration Tests:', function () {
});

it('should not be an admin user to begin with', function(done) {
User.find({username: 'admin'}, function(err, users) {
User.find({ username: 'admin' }, function(err, users) {
should.not.exist(err);
users.should.be.instanceof(Array).and.have.lengthOf(0);
return done();
});
});

it('should not be a "regular" user to begin with', function(done) {
User.find({username: 'user'}, function(err, users) {
User.find({ username: 'user' }, function(err, users) {
should.not.exist(err);
users.should.be.instanceof(Array).and.have.lengthOf(0);
return done();
Expand All @@ -92,7 +92,7 @@ describe('Configuration Tests:', function () {
// Set node env ro production environment
process.env.NODE_ENV = 'production';

User.find({username: adminFromSeedConfig.username}, function(err, users) {
User.find({ username: adminFromSeedConfig.username }, function(err, users) {

// There shouldn't be any errors
should.not.exist(err);
Expand All @@ -101,7 +101,7 @@ describe('Configuration Tests:', function () {
seed
.start({ logResults: false })
.then(function() {
User.find({username: adminFromSeedConfig.username}, function(err, users) {
User.find({ username: adminFromSeedConfig.username }, function(err, users) {
should.not.exist(err);
users.should.be.instanceof(Array).and.have.lengthOf(1);

Expand All @@ -127,7 +127,7 @@ describe('Configuration Tests:', function () {
// Set node env ro production environment
process.env.NODE_ENV = 'test';

User.find({username: adminFromSeedConfig.username}, function(err, users) {
User.find({ username: adminFromSeedConfig.username }, function(err, users) {

// There shouldn't be any errors
should.not.exist(err);
Expand All @@ -136,14 +136,14 @@ describe('Configuration Tests:', function () {
seed
.start({ logResults: false })
.then(function() {
User.find({username: adminFromSeedConfig.username}, function(err, users) {
User.find({ username: adminFromSeedConfig.username }, function(err, users) {
should.not.exist(err);
users.should.be.instanceof(Array).and.have.lengthOf(1);

var _admin = users.pop();
_admin.username.should.equal(adminFromSeedConfig.username);

User.find({username: userFromSeedConfig.username}, function(err, users) {
User.find({ username: userFromSeedConfig.username }, function(err, users) {

should.not.exist(err);
users.should.be.instanceof(Array).and.have.lengthOf(1);
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('Configuration Tests:', function () {
// Set node env ro production environment
process.env.NODE_ENV = 'production';

User.find({username: admin1.username}, function(err, users) {
User.find({ username: admin1.username }, function(err, users) {

// There shouldn't be any errors
should.not.exist(err);
Expand All @@ -224,7 +224,7 @@ describe('Configuration Tests:', function () {
seed
.start({ logResults: false, seedAdmin: admin1 })
.then(function() {
User.find({username: admin1.username}, function(err, users) {
User.find({ username: admin1.username }, function(err, users) {
should.not.exist(err);
users.should.be.instanceof(Array).and.have.lengthOf(1);

Expand All @@ -250,7 +250,7 @@ describe('Configuration Tests:', function () {
// Set node env ro production environment
process.env.NODE_ENV = 'test';

User.find({username: admin1.username}, function(err, users) {
User.find({ username: admin1.username }, function(err, users) {

// There shouldn't be any errors
should.not.exist(err);
Expand All @@ -259,14 +259,14 @@ describe('Configuration Tests:', function () {
seed
.start({ logResults: false, seedAdmin: admin1, seedUser: user1 })
.then(function() {
User.find({username: admin1.username}, function(err, users) {
User.find({ username: admin1.username }, function(err, users) {
should.not.exist(err);
users.should.be.instanceof(Array).and.have.lengthOf(1);

var _admin = users.pop();
_admin.username.should.equal(admin1.username);

User.find({username: user1.username}, function(err, users) {
User.find({ username: user1.username }, function(err, users) {

should.not.exist(err);
users.should.be.instanceof(Array).and.have.lengthOf(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ angular.module('users')
});
}
};
}]);
}]);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('users')
.directive('passwordVerify', function() {
.directive('passwordVerify', [function() {
return {
require: 'ngModel',
scope: {
Expand All @@ -28,6 +28,6 @@ angular.module('users')
});
}
});
}
}
};
});
}]);
69 changes: 34 additions & 35 deletions modules/users/server/config/strategies/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,44 @@ var passport = require('passport'),
module.exports = function (config) {
// Use facebook strategy
passport.use(new FacebookStrategy({
clientID: config.facebook.clientID,
clientSecret: config.facebook.clientSecret,
callbackURL: config.facebook.callbackURL,
profileFields: ['id', 'name', 'displayName', 'emails', 'photos'],
passReqToCallback: true
},
function (req, accessToken, refreshToken, profile, done) {
// Set the provider data and include tokens
var providerData = profile._json;
providerData.accessToken = accessToken;
providerData.refreshToken = refreshToken;
clientID: config.facebook.clientID,
clientSecret: config.facebook.clientSecret,
callbackURL: config.facebook.callbackURL,
profileFields: ['id', 'name', 'displayName', 'emails', 'photos'],
passReqToCallback: true
},
function (req, accessToken, refreshToken, profile, done) {
// Set the provider data and include tokens
var providerData = profile._json;
providerData.accessToken = accessToken;
providerData.refreshToken = refreshToken;

// Create the user OAuth profile
var providerUserProfile = {
firstName: profile.name.givenName,
lastName: profile.name.familyName,
displayName: profile.displayName,
email: profile.emails ? profile.emails[0].value : undefined,
username: profile.username || generateUsername(profile),
profileImageURL: (profile.id) ? '//graph.facebook.com/' + profile.id + '/picture?type=large' : undefined,
provider: 'facebook',
providerIdentifierField: 'id',
providerData: providerData
};
// Create the user OAuth profile
var providerUserProfile = {
firstName: profile.name.givenName,
lastName: profile.name.familyName,
displayName: profile.displayName,
email: profile.emails ? profile.emails[0].value : undefined,
username: profile.username || generateUsername(profile),
profileImageURL: (profile.id) ? '//graph.facebook.com/' + profile.id + '/picture?type=large' : undefined,
provider: 'facebook',
providerIdentifierField: 'id',
providerData: providerData
};

// Save the user OAuth profile
users.saveOAuthUserProfile(req, providerUserProfile, done);
// Save the user OAuth profile
users.saveOAuthUserProfile(req, providerUserProfile, done);

function generateUsername(profile) {
var username = '';
function generateUsername(profile) {
var username = '';

if (profile.emails) {
username = profile.emails[0].value.split('@')[0];
} else if (profile.name) {
username = profile.name.givenName[0] + profile.name.familyName;
}

return username.toLowerCase() || undefined;
if (profile.emails) {
username = profile.emails[0].value.split('@')[0];
} else if (profile.name) {
username = profile.name.givenName[0] + profile.name.familyName;
}

return username.toLowerCase() || undefined;
}
));
}));
};
63 changes: 31 additions & 32 deletions modules/users/server/config/strategies/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,38 @@ var passport = require('passport'),
module.exports = function (config) {
// Use github strategy
passport.use(new GithubStrategy({
clientID: config.github.clientID,
clientSecret: config.github.clientSecret,
callbackURL: config.github.callbackURL,
passReqToCallback: true
},
function (req, accessToken, refreshToken, profile, done) {
// Set the provider data and include tokens
var providerData = profile._json;
providerData.accessToken = accessToken;
providerData.refreshToken = refreshToken;
clientID: config.github.clientID,
clientSecret: config.github.clientSecret,
callbackURL: config.github.callbackURL,
passReqToCallback: true
},
function (req, accessToken, refreshToken, profile, done) {
// Set the provider data and include tokens
var providerData = profile._json;
providerData.accessToken = accessToken;
providerData.refreshToken = refreshToken;

// Create the user OAuth profile
var displayName = profile.displayName ? profile.displayName.trim() : profile.username.trim();
var iSpace = displayName.indexOf(' '); // index of the whitespace following the firstName
var firstName = iSpace !== -1 ? displayName.substring(0, iSpace) : displayName;
var lastName = iSpace !== -1 ? displayName.substring(iSpace + 1) : '';
// Create the user OAuth profile
var displayName = profile.displayName ? profile.displayName.trim() : profile.username.trim();
var iSpace = displayName.indexOf(' '); // index of the whitespace following the firstName
var firstName = iSpace !== -1 ? displayName.substring(0, iSpace) : displayName;
var lastName = iSpace !== -1 ? displayName.substring(iSpace + 1) : '';

var providerUserProfile = {
firstName: firstName,
lastName: lastName,
displayName: displayName,
email: profile.emails[0].value,
username: profile.username,
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
profileImageURL: (providerData.avatar_url) ? providerData.avatar_url : undefined,
// jscs:enable
provider: 'github',
providerIdentifierField: 'id',
providerData: providerData
};
var providerUserProfile = {
firstName: firstName,
lastName: lastName,
displayName: displayName,
email: profile.emails[0].value,
username: profile.username,
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
profileImageURL: (providerData.avatar_url) ? providerData.avatar_url : undefined,
// jscs:enable
provider: 'github',
providerIdentifierField: 'id',
providerData: providerData
};

// Save the user OAuth profile
users.saveOAuthUserProfile(req, providerUserProfile, done);
}
));
// Save the user OAuth profile
users.saveOAuthUserProfile(req, providerUserProfile, done);
}));
};
Loading

0 comments on commit 0323696

Please sign in to comment.