Skip to content

Commit d2aecac

Browse files
author
Martii
committed
Some missed "hungarian apps" notation.
PLEASE TEST THOROUGHLY! Applies to OpenUserJS#264
1 parent c8fbdee commit d2aecac

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

controllers/auth.js

+51-51
Original file line numberDiff line numberDiff line change
@@ -12,153 +12,153 @@ var cleanFilename = require('../libs/helpers').cleanFilename;
1212
var addSession = require('../libs/modifySessions').add;
1313

1414
// Unused but removing it breaks passport
15-
passport.serializeUser(function (user, done) {
16-
done(null, user._id);
15+
passport.serializeUser(function (aUser, aDone) {
16+
aDone(null, aUser._id);
1717
});
1818

1919
// Setup all our auth strategies
2020
var openIdStrategies = {};
21-
Strategy.find({}, function (err, strategies) {
21+
Strategy.find({}, function (aErr, aStrategies) {
2222

2323
// Get OpenId strategies
2424
for (var name in allStrategies) {
2525
if (!allStrategies[name].oauth) {
2626
openIdStrategies[name] = true;
27-
strategies.push({ 'name': name, 'openid': true });
27+
aStrategies.push({ 'name': name, 'openid': true });
2828
}
2929
}
3030

3131
// Load the passport module for each strategy
32-
strategies.forEach(function (strategy) {
33-
loadPassport(strategy);
32+
aStrategies.forEach(function (aStrategy) {
33+
loadPassport(aStrategy);
3434
});
3535
});
3636

37-
exports.auth = function (req, res, next) {
38-
var user = req.session.user;
39-
var strategy = req.body.auth || req.route.params.strategy;
40-
var username = req.body.username || req.session.username;
37+
exports.auth = function (aReq, aRes, aNext) {
38+
var user = aReq.session.user;
39+
var strategy = aReq.body.auth || aReq.route.params.strategy;
40+
var username = aReq.body.username || aReq.session.username;
4141

4242
function auth() {
4343
var authenticate = passport.authenticate(strategy);
4444

4545
// Just in case some dumbass tries a bad /auth/* url
46-
if (!strategyInstances[strategy]) { return next(); }
46+
if (!strategyInstances[strategy]) { return aNext(); }
4747

48-
authenticate(req, res);
48+
authenticate(aReq, aRes);
4949
}
5050

5151
// Allow a logged in user to add a new strategy
5252
if (strategy && user) {
53-
req.session.username = user.name;
53+
aReq.session.username = user.name;
5454
return auth();
5555
} else if (user) {
56-
return next();
56+
return aNext();
5757
}
5858

59-
if (!username) { return res.redirect('/register?noname'); }
59+
if (!username) { return aRes.redirect('/register?noname'); }
6060
// Clean the username of leading and trailing whitespace,
6161
// and other stuff that is unsafe in a url
6262
username = cleanFilename(username.replace(/^\s+|\s+$/g, ''));
6363

6464
// The username could be empty after the replacements
65-
if (!username) { return res.redirect('/register?noname'); }
65+
if (!username) { return aRes.redirect('/register?noname'); }
6666

6767
// Store the username in the session so we still have it when they
6868
// get back from authentication
69-
if (!req.session.username) {
70-
req.session.username = username;
69+
if (!aReq.session.username) {
70+
aReq.session.username = username;
7171
}
7272

7373
User.findOne({ name: { $regex: new RegExp('^' + username + '$', 'i') } },
74-
function (err, user) {
74+
function (aErr, aUser) {
7575
var strategies = null;
7676
var strat = null;
7777

78-
if (user) {
79-
strategies = user.strategies;
78+
if (aUser) {
79+
strategies = aUser.strategies;
8080
strat = strategies.pop();
8181

82-
if (req.session.newstrategy) { // authenticate with a new strategy
83-
delete req.session.newstrategy;
82+
if (aReq.session.newstrategy) { // authenticate with a new strategy
83+
delete aReq.session.newstrategy;
8484
} else if (!strategy) { // use an existing strategy
8585
strategy = strat;
8686
} else if (strategies.indexOf(strategy) === -1) {
8787
// add a new strategy but first authenticate with existing strategy
88-
req.session.newstrategy = strategy;
88+
aReq.session.newstrategy = strategy;
8989
strategy = strat;
9090
} // else use the strategy that was given in the POST
9191
}
9292

9393
if (!strategy) {
94-
return res.redirect('/register');
94+
return aRes.redirect('/register');
9595
} else {
9696
return auth();
9797
}
9898
});
9999
};
100100

101-
exports.callback = function (req, res, next) {
102-
var strategy = req.route.params.strategy;
103-
var username = req.session.username;
104-
var newstrategy = req.session.newstrategy;
101+
exports.callback = function (aReq, aRes, aNext) {
102+
var strategy = aReq.route.params.strategy;
103+
var username = aReq.session.username;
104+
var newstrategy = aReq.session.newstrategy;
105105
var strategyInstance = null;
106-
var doneUrl = req.session.user ? '/user/edit' : '/';
106+
var doneUrl = aReq.session.user ? '/user/edit' : '/';
107107

108108
// The callback was called improperly
109-
if (!strategy || !username) { return next(); }
109+
if (!strategy || !username) { return aNext(); }
110110

111111
// Get the passport strategy instance so we can alter the _verfiy method
112112
strategyInstance = strategyInstances[strategy];
113113

114114
// Hijak the private verify method so we can fuck shit up freely
115115
// We use this library for things it was never intended to do
116116
if (openIdStrategies[strategy]) {
117-
strategyInstance._verify = function (id, done) {
118-
verifyPassport(id, strategy, username, req.session.user, done);
117+
strategyInstance._verify = function (aId, aDone) {
118+
verifyPassport(aId, strategy, username, aReq.session.user, aDone);
119119
}
120120
} else {
121121
strategyInstance._verify =
122-
function (token, refreshOrSecretToken, profile, done) {
123-
req.session.profile = profile;
124-
verifyPassport(profile.id, strategy, username, req.session.user, done);
122+
function (aToken, aRefreshOrSecretToken, aProfile, aDone) {
123+
aReq.session.profile = aProfile;
124+
verifyPassport(aProfile.id, strategy, username, aReq.session.user, aDone);
125125
}
126126
}
127127

128128
// This callback will happen after the verify routine
129-
var authenticate = passport.authenticate(strategy, function (err, user, info) {
130-
if (err) { return next(err); }
131-
if (!user) {
132-
return res.redirect(doneUrl + (doneUrl === '/' ? 'register' : '')
129+
var authenticate = passport.authenticate(strategy, function (aErr, aUser, aInfo) {
130+
if (aErr) { return aNext(aErr); }
131+
if (!aUser) {
132+
return aRes.redirect(doneUrl + (doneUrl === '/' ? 'register' : '')
133133
+ '?authfail');
134134
}
135135

136-
req.logIn(user, function (err) {
137-
if (err) { return next(err); }
136+
aReq.logIn(aUser, function (aErr) {
137+
if (aErr) { return aNext(aErr); }
138138

139139
// Store the user info in the session
140-
req.session.user = user;
140+
aReq.session.user = aUser;
141141

142142
// Save the session id on the user model
143-
user.sessionId = req.sessionID;
143+
aUser.sessionId = aReq.sessionID;
144144

145145
// Save GitHub username.
146-
if (req.session.profile && req.session.profile.provider === 'github') {
147-
user.ghUsername = req.session.profile.username;
146+
if (aReq.session.profile && aReq.session.profile.provider === 'github') {
147+
aUser.ghUsername = aReq.session.profile.username;
148148
}
149149

150-
addSession(req, user, function () {
150+
addSession(aReq, aUser, function () {
151151
if (newstrategy) {
152152
// Allow a user to link to another acount
153-
return res.redirect('/auth/' + newstrategy);
153+
return aRes.redirect('/auth/' + newstrategy);
154154
} else {
155155
// Delete the username that was temporarily stored
156-
delete req.session.username;
157-
return res.redirect(doneUrl);
156+
delete aReq.session.username;
157+
return aRes.redirect(doneUrl);
158158
}
159159
});
160160
});
161161
});
162162

163-
authenticate(req, res, next);
163+
authenticate(aReq, aRes, aNext);
164164
}

0 commit comments

Comments
 (0)