@@ -10,6 +10,9 @@ import { BasicStrategy } from 'passport-http';
1010
1111import 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+
1316function generateUniqueUsername ( username ) {
1417 const adj =
1518 friendlyWords . predicates [
@@ -38,6 +41,9 @@ passport.use(
3841 if ( ! user ) {
3942 done ( null , false , { msg : `Email ${ email } not found.` } ) ;
4043 return ;
44+ } else if ( user . banned ) {
45+ done ( null , false , { msg : accountSuspensionMessage } ) ;
46+ return ;
4147 }
4248 user . comparePassword ( password , ( innerErr , isMatch ) => {
4349 if ( isMatch ) {
@@ -65,6 +71,10 @@ passport.use(
6571 done ( null , false ) ;
6672 return ;
6773 }
74+ if ( user . banned ) {
75+ done ( null , false , { msg : accountSuspensionMessage } ) ;
76+ return ;
77+ }
6878 user . findMatchingKey ( key , ( innerErr , isMatch , keyDocument ) => {
6979 if ( isMatch ) {
7080 keyDocument . lastUsedAt = Date . now ( ) ;
@@ -117,6 +127,9 @@ passport.use(
117127 new Error ( 'GitHub account is already linked to another account.' )
118128 ) ;
119129 return ;
130+ } else if ( existingUser . banned ) {
131+ done ( new Error ( accountSuspensionMessage ) ) ;
132+ return ;
120133 }
121134 done ( null , existingUser ) ;
122135 return ;
@@ -145,6 +158,10 @@ passport.use(
145158 } else {
146159 [ existingEmailUser ] = existingEmailUsers ;
147160 }
161+ if ( existingEmailUser . banned ) {
162+ done ( new Error ( accountSuspensionMessage ) ) ;
163+ return ;
164+ }
148165 existingEmailUser . email = existingEmailUser . email || primaryEmail ;
149166 existingEmailUser . github = profile . id ;
150167 existingEmailUser . username =
@@ -207,11 +224,13 @@ passport.use(
207224 )
208225 ) ;
209226 return ;
227+ } else if ( existingUser . banned ) {
228+ done ( new Error ( accountSuspensionMessage ) ) ;
229+ return ;
210230 }
211231 done ( null , existingUser ) ;
212232 return ;
213233 }
214-
215234 const primaryEmail = profile . _json . emails [ 0 ] . value ;
216235
217236 if ( req . user ) {
@@ -236,6 +255,10 @@ passport.use(
236255 // what if a username is already taken from the display name too?
237256 // then, append a random friendly word?
238257 if ( existingEmailUser ) {
258+ if ( existingEmailUser . banned ) {
259+ done ( new Error ( accountSuspensionMessage ) ) ;
260+ return ;
261+ }
239262 existingEmailUser . email =
240263 existingEmailUser . email || primaryEmail ;
241264 existingEmailUser . google = profile . _json . emails [ 0 ] . value ;
0 commit comments