@@ -65,8 +65,9 @@ Accounts._checkPassword = function (user, password) {
65
65
66
66
password = getPasswordString ( password ) ;
67
67
68
- if ( ! bcryptCompare ( password , user . services . password . bcrypt ) )
68
+ if ( ! bcryptCompare ( password , user . services . password . bcrypt ) ) {
69
69
result . error = handleError ( "Incorrect password" , false ) ;
70
+ }
70
71
71
72
return result ;
72
73
} ;
@@ -216,8 +217,9 @@ var checkForCaseInsensitiveDuplicates = function (fieldName, displayName, fieldV
216
217
( ! ownUserId ||
217
218
// Otherwise, check to see if there are multiple matches or a match
218
219
// that is not us
219
- ( matchedUsers . length > 1 || matchedUsers [ 0 ] . _id !== ownUserId ) ) )
220
- handleError ( displayName + " already exists." ) ;
220
+ ( matchedUsers . length > 1 || matchedUsers [ 0 ] . _id !== ownUserId ) ) ) {
221
+ handleError ( displayName + " already exists." ) ;
222
+ }
221
223
}
222
224
} ;
223
225
@@ -268,12 +270,14 @@ Accounts.registerLoginHandler("password", function (options) {
268
270
269
271
270
272
var user = Accounts . _findUserByQuery ( options . user ) ;
271
- if ( ! user )
273
+ if ( ! user ) {
272
274
handleError ( "User not found" ) ;
273
-
275
+ }
276
+
274
277
if ( ! user . services || ! user . services . password ||
275
- ! ( user . services . password . bcrypt || user . services . password . srp ) )
278
+ ! ( user . services . password . bcrypt || user . services . password . srp ) ) {
276
279
handleError ( "User has no password set" ) ;
280
+ }
277
281
278
282
if ( ! user . services . password . bcrypt ) {
279
283
if ( typeof options . password === "string" ) {
@@ -285,11 +289,12 @@ Accounts.registerLoginHandler("password", function (options) {
285
289
var newVerifier = SRP . generateVerifier ( options . password , {
286
290
identity : verifier . identity , salt : verifier . salt } ) ;
287
291
288
- if ( verifier . verifier !== newVerifier . verifier )
292
+ if ( verifier . verifier !== newVerifier . verifier ) {
289
293
return {
290
294
userId : Accounts . _options . ambiguousErrorMessages ? null : user . _id ,
291
295
error : handleError ( "Incorrect password" , false )
292
- }
296
+ } ;
297
+ }
293
298
294
299
return { userId : user . _id } ;
295
300
} else {
@@ -323,8 +328,9 @@ Accounts.registerLoginHandler("password", function (options) {
323
328
//
324
329
// XXX COMPAT WITH 0.8.1.3
325
330
Accounts . registerLoginHandler ( "password" , function ( options ) {
326
- if ( ! options . srp || ! options . password )
331
+ if ( ! options . srp || ! options . password ) {
327
332
return undefined ; // don't handle
333
+ }
328
334
329
335
check ( options , {
330
336
user : userQueryValidator ,
@@ -333,16 +339,19 @@ Accounts.registerLoginHandler("password", function (options) {
333
339
} ) ;
334
340
335
341
var user = Accounts . _findUserByQuery ( options . user ) ;
336
- if ( ! user )
342
+ if ( ! user ) {
337
343
handleError ( "User not found" ) ;
344
+ }
338
345
339
346
// Check to see if another simultaneous login has already upgraded
340
347
// the user record to bcrypt.
341
- if ( user . services && user . services . password && user . services . password . bcrypt )
348
+ if ( user . services && user . services . password && user . services . password . bcrypt ) {
342
349
return checkPassword ( user , options . password ) ;
350
+ }
343
351
344
- if ( ! ( user . services && user . services . password && user . services . password . srp ) )
345
- handleError ( "User has no password set" ) ;
352
+ if ( ! ( user . services && user . services . password && user . services . password . srp ) ) {
353
+ handleError ( "User has no password set" ) ;
354
+ }
346
355
347
356
var v1 = user . services . password . srp . verifier ;
348
357
var v2 = SRP . generateVerifier (
@@ -352,11 +361,12 @@ Accounts.registerLoginHandler("password", function (options) {
352
361
salt : user . services . password . srp . salt
353
362
}
354
363
) . verifier ;
355
- if ( v1 !== v2 )
364
+ if ( v1 !== v2 ) {
356
365
return {
357
366
userId : Accounts . _options . ambiguousErrorMessages ? null : user . _id ,
358
367
error : handleError ( "Incorrect password" , false )
359
- }
368
+ } ;
369
+ }
360
370
361
371
// Upgrade to bcrypt on successful login.
362
372
var salted = hashPassword ( options . password ) ;
@@ -390,8 +400,9 @@ Accounts.setUsername = function (userId, newUsername) {
390
400
check ( newUsername , NonEmptyString ) ;
391
401
392
402
var user = Meteor . users . findOne ( userId ) ;
393
- if ( ! user )
403
+ if ( ! user ) {
394
404
handleError ( "User not found" ) ;
405
+ }
395
406
396
407
var oldUsername = user . username ;
397
408
@@ -430,16 +441,19 @@ Meteor.methods({changePassword: function (oldPassword, newPassword) {
430
441
check ( oldPassword , passwordValidator ) ;
431
442
check ( newPassword , passwordValidator ) ;
432
443
433
- if ( ! this . userId )
444
+ if ( ! this . userId ) {
434
445
throw new Meteor . Error ( 401 , "Must be logged in" ) ;
446
+ }
435
447
436
448
var user = Meteor . users . findOne ( this . userId ) ;
437
- if ( ! user )
438
- handleError ( "User not found" ) ;
449
+ if ( ! user ) {
450
+ handleError ( "User not found" ) ;
451
+ }
439
452
440
453
if ( ! user . services || ! user . services . password ||
441
- ( ! user . services . password . bcrypt && ! user . services . password . srp ) )
454
+ ( ! user . services . password . bcrypt && ! user . services . password . srp ) ) {
442
455
handleError ( "User has no password set" ) ;
456
+ }
443
457
444
458
if ( ! user . services . password . bcrypt ) {
445
459
throw new Meteor . Error ( 400 , "old password format" , EJSON . stringify ( {
@@ -449,8 +463,9 @@ Meteor.methods({changePassword: function (oldPassword, newPassword) {
449
463
}
450
464
451
465
var result = checkPassword ( user , oldPassword ) ;
452
- if ( result . error )
466
+ if ( result . error ) {
453
467
throw result . error ;
468
+ }
454
469
455
470
var hashed = hashPassword ( newPassword ) ;
456
471
@@ -489,8 +504,9 @@ Accounts.setPassword = function (userId, newPlaintextPassword, options) {
489
504
options = _ . extend ( { logout : true } , options ) ;
490
505
491
506
var user = Meteor . users . findOne ( userId ) ;
492
- if ( ! user )
507
+ if ( ! user ) {
493
508
throw new Meteor . Error ( 403 , "User not found" ) ;
509
+ }
494
510
495
511
var update = {
496
512
$unset : {
@@ -518,8 +534,9 @@ Meteor.methods({forgotPassword: function (options) {
518
534
check ( options , { email : String } ) ;
519
535
520
536
var user = Accounts . findUserByEmail ( options . email ) ;
521
- if ( ! user )
537
+ if ( ! user ) {
522
538
handleError ( "User not found" ) ;
539
+ }
523
540
524
541
const emails = _ . pluck ( user . emails || [ ] , 'address' ) ;
525
542
const caseSensitiveEmail = _ . find ( emails , email => {
@@ -542,15 +559,19 @@ Meteor.methods({forgotPassword: function (options) {
542
559
Accounts . sendResetPasswordEmail = function ( userId , email ) {
543
560
// Make sure the user exists, and email is one of their addresses.
544
561
var user = Meteor . users . findOne ( userId ) ;
545
- if ( ! user )
562
+ if ( ! user ) {
546
563
handleError ( "Can't find user" ) ;
564
+ }
547
565
548
566
// pick the first email if we weren't passed an email.
549
- if ( ! email && user . emails && user . emails [ 0 ] )
567
+ if ( ! email && user . emails && user . emails [ 0 ] ) {
550
568
email = user . emails [ 0 ] . address ;
569
+ }
570
+
551
571
// make sure we have a valid email
552
- if ( ! email || ! _ . contains ( _ . pluck ( user . emails || [ ] , 'address' ) , email ) )
572
+ if ( ! email || ! _ . contains ( _ . pluck ( user . emails || [ ] , 'address' ) , email ) ) {
553
573
handleError ( "No such email for user." ) ;
574
+ }
554
575
555
576
var token = Random . secret ( ) ;
556
577
var when = new Date ( ) ;
@@ -581,9 +602,10 @@ Accounts.sendResetPasswordEmail = function (userId, email) {
581
602
Accounts . emailTemplates . resetPassword . text ( user , resetPasswordUrl ) ;
582
603
}
583
604
584
- if ( typeof Accounts . emailTemplates . resetPassword . html === 'function' )
605
+ if ( typeof Accounts . emailTemplates . resetPassword . html === 'function' ) {
585
606
options . html =
586
607
Accounts . emailTemplates . resetPassword . html ( user , resetPasswordUrl ) ;
608
+ }
587
609
588
610
if ( typeof Accounts . emailTemplates . headers === 'object' ) {
589
611
options . headers = Accounts . emailTemplates . headers ;
@@ -612,14 +634,17 @@ Accounts.sendEnrollmentEmail = function (userId, email) {
612
634
613
635
// Make sure the user exists, and email is in their addresses.
614
636
var user = Meteor . users . findOne ( userId ) ;
615
- if ( ! user )
637
+ if ( ! user ) {
616
638
throw new Error ( "Can't find user" ) ;
639
+ }
617
640
// pick the first email if we weren't passed an email.
618
- if ( ! email && user . emails && user . emails [ 0 ] )
641
+ if ( ! email && user . emails && user . emails [ 0 ] ) {
619
642
email = user . emails [ 0 ] . address ;
643
+ }
620
644
// make sure we have a valid email
621
- if ( ! email || ! _ . contains ( _ . pluck ( user . emails || [ ] , 'address' ) , email ) )
645
+ if ( ! email || ! _ . contains ( _ . pluck ( user . emails || [ ] , 'address' ) , email ) ) {
622
646
throw new Error ( "No such email for user." ) ;
647
+ }
623
648
624
649
var token = Random . secret ( ) ;
625
650
var when = new Date ( ) ;
@@ -651,9 +676,10 @@ Accounts.sendEnrollmentEmail = function (userId, email) {
651
676
Accounts . emailTemplates . enrollAccount . text ( user , enrollAccountUrl ) ;
652
677
}
653
678
654
- if ( typeof Accounts . emailTemplates . enrollAccount . html === 'function' )
679
+ if ( typeof Accounts . emailTemplates . enrollAccount . html === 'function' ) {
655
680
options . html =
656
681
Accounts . emailTemplates . enrollAccount . html ( user , enrollAccountUrl ) ;
682
+ }
657
683
658
684
if ( typeof Accounts . emailTemplates . headers === 'object' ) {
659
685
options . headers = Accounts . emailTemplates . headers ;
@@ -678,8 +704,9 @@ Meteor.methods({resetPassword: function (token, newPassword) {
678
704
679
705
var user = Meteor . users . findOne ( {
680
706
"services.password.reset.token" : token } ) ;
681
- if ( ! user )
707
+ if ( ! user ) {
682
708
throw new Meteor . Error ( 403 , "Token expired" ) ;
709
+ }
683
710
var when = user . services . password . reset . when ;
684
711
var reason = user . services . password . reset . reason ;
685
712
var tokenLifetimeMs = Accounts . _getPasswordResetTokenLifetimeMs ( ) ;
0 commit comments