Skip to content

Commit d58ca8f

Browse files
committed
Update account ban code to work with OAuth logins
1 parent e18bf8e commit d58ca8f

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

server/config/passport.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { BasicStrategy } from 'passport-http';
1010

1111
import User from '../models/user';
1212

13+
const accountSuspensionMessage =
14+
'Account has been suspended. Please contact privacy@p5js.org if you believe this is an error.';
15+
1316
function generateUniqueUsername(username) {
1417
const adj =
1518
friendlyWords.predicates[
@@ -39,9 +42,7 @@ passport.use(
3942
done(null, false, { msg: `Email ${email} not found.` });
4043
return;
4144
} else if (user.banned) {
42-
const msg =
43-
'Account has been suspended. Please contact privacy@p5js.org if you believe this is an error.';
44-
done(null, false, { msg });
45+
done(null, false, { msg: accountSuspensionMessage });
4546
return;
4647
}
4748
user.comparePassword(password, (innerErr, isMatch) => {
@@ -71,9 +72,7 @@ passport.use(
7172
return;
7273
}
7374
if (user.banned) {
74-
const msg =
75-
'Account has been suspended. Please contact privacy@p5js.org if you believe this is an error.';
76-
done(null, false, { msg });
75+
done(null, false, { msg: accountSuspensionMessage });
7776
return;
7877
}
7978
user.findMatchingKey(key, (innerErr, isMatch, keyDocument) => {
@@ -129,9 +128,7 @@ passport.use(
129128
);
130129
return;
131130
} else if (existingUser.banned) {
132-
const msg =
133-
'Account has been suspended. Please contact privacy@p5js.org if you believe this is an error.';
134-
done(new Error(msg));
131+
done(new Error(accountSuspensionMessage));
135132
return;
136133
}
137134
done(null, existingUser);
@@ -140,7 +137,6 @@ passport.use(
140137

141138
const emails = getVerifiedEmails(profile.emails);
142139
const primaryEmail = getPrimaryEmail(profile.emails);
143-
console.log(profile);
144140

145141
if (req.user) {
146142
if (!req.user.github) {
@@ -162,6 +158,10 @@ passport.use(
162158
} else {
163159
[existingEmailUser] = existingEmailUsers;
164160
}
161+
if (existingEmailUser.banned) {
162+
done(new Error(accountSuspensionMessage));
163+
return;
164+
}
165165
existingEmailUser.email = existingEmailUser.email || primaryEmail;
166166
existingEmailUser.github = profile.id;
167167
existingEmailUser.username =
@@ -225,9 +225,7 @@ passport.use(
225225
);
226226
return;
227227
} else if (existingUser.banned) {
228-
const msg =
229-
'Account has been suspended. Please contact privacy@p5js.org if you believe this is an error.';
230-
done(new Error(msg));
228+
done(new Error(accountSuspensionMessage));
231229
return;
232230
}
233231
done(null, existingUser);
@@ -257,6 +255,10 @@ passport.use(
257255
// what if a username is already taken from the display name too?
258256
// then, append a random friendly word?
259257
if (existingEmailUser) {
258+
if (existingEmailUser.banned) {
259+
done(new Error(accountSuspensionMessage));
260+
return;
261+
}
260262
existingEmailUser.email =
261263
existingEmailUser.email || primaryEmail;
262264
existingEmailUser.google = profile._json.emails[0].value;

0 commit comments

Comments
 (0)