Skip to content

Commit 91c5d8c

Browse files
committed
Fix linting warnings; promisify some back-end authentication operations
1 parent 3a61b5a commit 91c5d8c

File tree

7 files changed

+66
-76
lines changed

7 files changed

+66
-76
lines changed

generated/browser/js/fsa/fsa-pre-built.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
var app = angular.module('fsaPreBuilt', []);
99

10-
app.factory('Socket', function ($location) {
10+
app.factory('Socket', function () {
1111
if (!window.io) throw new Error('socket.io not found!');
1212
return window.io(window.location.origin);
1313
});
@@ -34,7 +34,7 @@
3434
return {
3535
responseError: function (response) {
3636
$rootScope.$broadcast(statusDict[response.status], response);
37-
return $q.reject(response);
37+
return $q.reject(response)
3838
}
3939
};
4040
});
@@ -50,6 +50,13 @@
5050

5151
app.service('AuthService', function ($http, Session, $rootScope, AUTH_EVENTS, $q) {
5252

53+
function onSuccessfulLogin(response) {
54+
var data = response.data;
55+
Session.create(data.id, data.user);
56+
$rootScope.$broadcast(AUTH_EVENTS.loginSuccess);
57+
return data.user;
58+
}
59+
5360
// Uses the session factory to see if an
5461
// authenticated user is currently registered.
5562
this.isAuthenticated = function () {
@@ -78,7 +85,7 @@
7885
this.login = function (credentials) {
7986
return $http.post('/login', credentials)
8087
.then(onSuccessfulLogin)
81-
.catch(function (response) {
88+
.catch(function () {
8289
return $q.reject({ message: 'Invalid login credentials.' });
8390
});
8491
};
@@ -90,13 +97,6 @@
9097
});
9198
};
9299

93-
function onSuccessfulLogin(response) {
94-
var data = response.data;
95-
Session.create(data.id, data.user);
96-
$rootScope.$broadcast(AUTH_EVENTS.loginSuccess);
97-
return data.user;
98-
}
99-
100100
});
101101

102102
app.service('Session', function ($rootScope, AUTH_EVENTS) {

generated/server/app/configure/authentication/facebook.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use strict';
2-
var path = require('path');
32
var passport = require('passport');
43
var FacebookStrategy = require('passport-facebook').Strategy;
54
var mongoose = require('mongoose');
@@ -17,26 +16,25 @@ module.exports = function (app) {
1716

1817
var verifyCallback = function (accessToken, refreshToken, profile, done) {
1918

20-
UserModel.findOne({ 'facebook.id': profile.id }, function (err, user) {
21-
22-
if (err) return done(err);
23-
24-
if (user) {
25-
done(null, user);
26-
} else {
27-
UserModel.create({
28-
facebook: {
29-
id: profile.id
30-
}
31-
}).then(function (user) {
32-
done(null, user);
33-
}, function (err) {
34-
console.error('Error creating user from Facebook authentication', err);
35-
done(err);
36-
});
37-
}
38-
39-
});
19+
UserModel.findOne({ 'facebook.id': profile.id }).exec()
20+
.then(function (user) {
21+
22+
if (user) {
23+
return user;
24+
} else {
25+
return UserModel.create({
26+
facebook: {
27+
id: profile.id
28+
}
29+
});
30+
}
31+
32+
}).then(function (userToLogin) {
33+
done(null, userToLogin);
34+
}).catch(function (err) {
35+
console.error('Error creating user from Facebook authentication', err);
36+
done(err);
37+
});
4038

4139
};
4240

generated/server/app/configure/authentication/google.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,25 @@ module.exports = function (app) {
1717

1818
var verifyCallback = function (accessToken, refreshToken, profile, done) {
1919

20-
UserModel.findOne({ 'google.id': profile.id }, function (err, user) {
21-
22-
if (err) return done(err);
23-
24-
if (user) {
25-
done(null, user);
26-
} else {
27-
UserModel.create({
28-
google: {
29-
id: profile.id
30-
}
31-
}).then(function (user) {
32-
done(null, user);
33-
}, function (err) {
34-
console.error('Error creating user from Google authentication', err);
35-
done(err);
36-
});
37-
}
38-
39-
});
20+
UserModel.findOne({ 'google.id': profile.id }).exec()
21+
.then(function (user) {
22+
23+
if (user) {
24+
return user;
25+
} else {
26+
return UserModel.create({
27+
google: {
28+
id: profile.id
29+
}
30+
});
31+
}
32+
33+
}).then(function (userToLogin) {
34+
done(null, userToLogin);
35+
}).catch(function (err) {
36+
console.error('Error creating user from Google authentication', err);
37+
done(err);
38+
});
4039

4140
};
4241

generated/server/app/configure/authentication/local.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ module.exports = function (app) {
3535
}
3636

3737
// req.logIn will establish our session.
38-
req.logIn(user, function (err) {
39-
if (err) return next(err);
40-
// We respond with a reponse object that has user with _id and email.
38+
req.logIn(user, function (loginErr) {
39+
if (loginErr) return next(loginErr);
40+
// We respond with a response object that has user with _id and email.
4141
res.status(200).send({ user: _.omit(user.toJSON(), ['password', 'salt']) });
4242
});
4343

generated/server/app/configure/authentication/twitter.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ module.exports = function (app) {
1717
};
1818

1919
var createNewUser = function (token, tokenSecret, profile) {
20-
2120
return UserModel.create({
2221
twitter: {
2322
id: profile.id,
@@ -26,7 +25,6 @@ module.exports = function (app) {
2625
tokenSecret: tokenSecret
2726
}
2827
});
29-
3028
};
3129

3230
var updateUserCredentials = function (user, token, tokenSecret, profile) {
@@ -45,24 +43,19 @@ module.exports = function (app) {
4543

4644
var verifyCallback = function (token, tokenSecret, profile, done) {
4745

48-
UserModel.findOne({ 'twitter.id': profile.id }, function (err, user) {
49-
50-
if (err) return done(err);
51-
52-
if (user) { // If a user with this twitter id already exists.
53-
updateUserCredentials(user, token, tokenSecret, profile).then(function () {
54-
done(null, user);
55-
});
56-
} else { // If this twitter id has never been seen before and no user is attached.
57-
createNewUser(token, tokenSecret, profile).then(function (createdUser) {
58-
done(null, createdUser);
59-
}, function (err) {
60-
console.error('Error creating user from Twitter authentication', err);
61-
done(err);
62-
});
63-
}
64-
65-
});
46+
UserModel.findOne({ 'twitter.id': profile.id }).exec()
47+
.then(function (user) {
48+
if (user) { // If a user with this twitter id already exists.
49+
return updateUserCredentials(user, token, tokenSecret, profile);
50+
} else { // If this twitter id has never been seen before and no user is attached.
51+
return createNewUser(token, tokenSecret, profile);
52+
}
53+
}).then(function (user) {
54+
done(null, user);
55+
}).catch(function (err) {
56+
console.error('Error creating user from Twitter authentication', err);
57+
done(err);
58+
});
6659

6760
};
6861

generated/server/app/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ app.get('/*', function (req, res) {
3535

3636
// Error catching endware.
3737
app.use(function (err, req, res, next) {
38-
console.error(err);
38+
console.error(err, typeof next);
3939
res.status(err.status || 500).send(err.message || 'Internal server error.');
4040
});

generated/server/io/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function (server) {
88

99
io = socketio(server);
1010

11-
io.on('connection', function (socket) {
11+
io.on('connection', function () {
1212
// Now have access to socket, wowzers!
1313
});
1414

0 commit comments

Comments
 (0)