@@ -10,6 +10,9 @@ import { BasicStrategy } from 'passport-http';
10
10
11
11
import User from '../models/user' ;
12
12
13
+ const accountSuspensionMessage =
14
+ 'Account has been suspended. Please contact [email protected] if you believe this is an error.' ;
15
+
13
16
function generateUniqueUsername ( username ) {
14
17
const adj =
15
18
friendlyWords . predicates [
@@ -38,6 +41,9 @@ passport.use(
38
41
if ( ! user ) {
39
42
done ( null , false , { msg : `Email ${ email } not found.` } ) ;
40
43
return ;
44
+ } else if ( user . banned ) {
45
+ done ( null , false , { msg : accountSuspensionMessage } ) ;
46
+ return ;
41
47
}
42
48
user . comparePassword ( password , ( innerErr , isMatch ) => {
43
49
if ( isMatch ) {
@@ -65,6 +71,10 @@ passport.use(
65
71
done ( null , false ) ;
66
72
return ;
67
73
}
74
+ if ( user . banned ) {
75
+ done ( null , false , { msg : accountSuspensionMessage } ) ;
76
+ return ;
77
+ }
68
78
user . findMatchingKey ( key , ( innerErr , isMatch , keyDocument ) => {
69
79
if ( isMatch ) {
70
80
keyDocument . lastUsedAt = Date . now ( ) ;
@@ -117,6 +127,9 @@ passport.use(
117
127
new Error ( 'GitHub account is already linked to another account.' )
118
128
) ;
119
129
return ;
130
+ } else if ( existingUser . banned ) {
131
+ done ( new Error ( accountSuspensionMessage ) ) ;
132
+ return ;
120
133
}
121
134
done ( null , existingUser ) ;
122
135
return ;
@@ -145,6 +158,10 @@ passport.use(
145
158
} else {
146
159
[ existingEmailUser ] = existingEmailUsers ;
147
160
}
161
+ if ( existingEmailUser . banned ) {
162
+ done ( new Error ( accountSuspensionMessage ) ) ;
163
+ return ;
164
+ }
148
165
existingEmailUser . email = existingEmailUser . email || primaryEmail ;
149
166
existingEmailUser . github = profile . id ;
150
167
existingEmailUser . username =
@@ -207,11 +224,13 @@ passport.use(
207
224
)
208
225
) ;
209
226
return ;
227
+ } else if ( existingUser . banned ) {
228
+ done ( new Error ( accountSuspensionMessage ) ) ;
229
+ return ;
210
230
}
211
231
done ( null , existingUser ) ;
212
232
return ;
213
233
}
214
-
215
234
const primaryEmail = profile . _json . emails [ 0 ] . value ;
216
235
217
236
if ( req . user ) {
@@ -236,6 +255,10 @@ passport.use(
236
255
// what if a username is already taken from the display name too?
237
256
// then, append a random friendly word?
238
257
if ( existingEmailUser ) {
258
+ if ( existingEmailUser . banned ) {
259
+ done ( new Error ( accountSuspensionMessage ) ) ;
260
+ return ;
261
+ }
239
262
existingEmailUser . email =
240
263
existingEmailUser . email || primaryEmail ;
241
264
existingEmailUser . google = profile . _json . emails [ 0 ] . value ;
0 commit comments