Skip to content

Commit b8d4984

Browse files
committed
Add banned attribute to user model
1 parent cad726c commit b8d4984

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

server/config/passport.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ passport.use(
3838
if (!user) {
3939
done(null, false, { msg: `Email ${email} not found.` });
4040
return;
41+
} 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+
return;
4146
}
4247
user.comparePassword(password, (innerErr, isMatch) => {
4348
if (isMatch) {
@@ -65,6 +70,12 @@ passport.use(
6570
done(null, false);
6671
return;
6772
}
73+
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 });
77+
return;
78+
}
6879
user.findMatchingKey(key, (innerErr, isMatch, keyDocument) => {
6980
if (isMatch) {
7081
keyDocument.lastUsedAt = Date.now();
@@ -116,13 +127,19 @@ passport.use(
116127
new Error('GitHub account is already linked to another account.')
117128
);
118129
return;
130+
} else if (existingUser.banned) {
131+
const msg =
132+
'Account has been suspended. Please contact privacy@p5js.org if you believe this is an error.';
133+
done(new Error(msg));
134+
return;
119135
}
120136
done(null, existingUser);
121137
return;
122138
}
123139

124140
const emails = getVerifiedEmails(profile.emails);
125141
const primaryEmail = getPrimaryEmail(profile.emails);
142+
console.log(profile);
126143

127144
if (req.user) {
128145
if (!req.user.github) {
@@ -196,11 +213,15 @@ passport.use(
196213
)
197214
);
198215
return;
216+
} else if (existingUser.banned) {
217+
const msg =
218+
'Account has been suspended. Please contact privacy@p5js.org if you believe this is an error.';
219+
done(new Error(msg));
220+
return;
199221
}
200222
done(null, existingUser);
201223
return;
202224
}
203-
204225
const primaryEmail = profile._json.emails[0].value;
205226

206227
if (req.user) {

server/models/user.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ const userSchema = new Schema(
8181
type: String,
8282
enum: ['none', 'essential', 'all'],
8383
default: 'none'
84-
}
84+
},
85+
banned: { type: Boolean, default: false }
8586
},
8687
{ timestamps: true, usePushEach: true }
8788
);

0 commit comments

Comments
 (0)