Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac4decb

Browse files
committed
Maintain braces on if conditionals + other style changes.
This file leaves a lot to be desired, but strong preference to not remove existing curly-braces on if-statements. Also removed trailing whitespaces and slight indentation changes following the changes in meteor#8520.
1 parent 9c688d1 commit ac4decb

File tree

1 file changed

+59
-32
lines changed

1 file changed

+59
-32
lines changed

packages/accounts-password/password_server.js

+59-32
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ Accounts._checkPassword = function (user, password) {
6565

6666
password = getPasswordString(password);
6767

68-
if (! bcryptCompare(password, user.services.password.bcrypt))
68+
if (! bcryptCompare(password, user.services.password.bcrypt)) {
6969
result.error = handleError("Incorrect password", false);
70+
}
7071

7172
return result;
7273
};
@@ -216,8 +217,9 @@ var checkForCaseInsensitiveDuplicates = function (fieldName, displayName, fieldV
216217
(!ownUserId ||
217218
// Otherwise, check to see if there are multiple matches or a match
218219
// 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+
}
221223
}
222224
};
223225

@@ -268,12 +270,14 @@ Accounts.registerLoginHandler("password", function (options) {
268270

269271

270272
var user = Accounts._findUserByQuery(options.user);
271-
if (!user)
273+
if (!user) {
272274
handleError("User not found");
273-
275+
}
276+
274277
if (!user.services || !user.services.password ||
275-
!(user.services.password.bcrypt || user.services.password.srp))
278+
!(user.services.password.bcrypt || user.services.password.srp)) {
276279
handleError("User has no password set");
280+
}
277281

278282
if (!user.services.password.bcrypt) {
279283
if (typeof options.password === "string") {
@@ -285,11 +289,12 @@ Accounts.registerLoginHandler("password", function (options) {
285289
var newVerifier = SRP.generateVerifier(options.password, {
286290
identity: verifier.identity, salt: verifier.salt});
287291

288-
if (verifier.verifier !== newVerifier.verifier)
292+
if (verifier.verifier !== newVerifier.verifier) {
289293
return {
290294
userId: Accounts._options.ambiguousErrorMessages ? null : user._id,
291295
error: handleError("Incorrect password", false)
292-
}
296+
};
297+
}
293298

294299
return {userId: user._id};
295300
} else {
@@ -323,8 +328,9 @@ Accounts.registerLoginHandler("password", function (options) {
323328
//
324329
// XXX COMPAT WITH 0.8.1.3
325330
Accounts.registerLoginHandler("password", function (options) {
326-
if (!options.srp || !options.password)
331+
if (!options.srp || !options.password) {
327332
return undefined; // don't handle
333+
}
328334

329335
check(options, {
330336
user: userQueryValidator,
@@ -333,16 +339,19 @@ Accounts.registerLoginHandler("password", function (options) {
333339
});
334340

335341
var user = Accounts._findUserByQuery(options.user);
336-
if (!user)
342+
if (!user) {
337343
handleError("User not found");
344+
}
338345

339346
// Check to see if another simultaneous login has already upgraded
340347
// 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) {
342349
return checkPassword(user, options.password);
350+
}
343351

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+
}
346355

347356
var v1 = user.services.password.srp.verifier;
348357
var v2 = SRP.generateVerifier(
@@ -352,11 +361,12 @@ Accounts.registerLoginHandler("password", function (options) {
352361
salt: user.services.password.srp.salt
353362
}
354363
).verifier;
355-
if (v1 !== v2)
364+
if (v1 !== v2) {
356365
return {
357366
userId: Accounts._options.ambiguousErrorMessages ? null : user._id,
358367
error: handleError("Incorrect password", false)
359-
}
368+
};
369+
}
360370

361371
// Upgrade to bcrypt on successful login.
362372
var salted = hashPassword(options.password);
@@ -390,8 +400,9 @@ Accounts.setUsername = function (userId, newUsername) {
390400
check(newUsername, NonEmptyString);
391401

392402
var user = Meteor.users.findOne(userId);
393-
if (!user)
403+
if (!user) {
394404
handleError("User not found");
405+
}
395406

396407
var oldUsername = user.username;
397408

@@ -430,16 +441,19 @@ Meteor.methods({changePassword: function (oldPassword, newPassword) {
430441
check(oldPassword, passwordValidator);
431442
check(newPassword, passwordValidator);
432443

433-
if (!this.userId)
444+
if (!this.userId) {
434445
throw new Meteor.Error(401, "Must be logged in");
446+
}
435447

436448
var user = Meteor.users.findOne(this.userId);
437-
if (!user)
438-
handleError("User not found");
449+
if (!user) {
450+
handleError("User not found");
451+
}
439452

440453
if (!user.services || !user.services.password ||
441-
(!user.services.password.bcrypt && !user.services.password.srp))
454+
(!user.services.password.bcrypt && !user.services.password.srp)) {
442455
handleError("User has no password set");
456+
}
443457

444458
if (! user.services.password.bcrypt) {
445459
throw new Meteor.Error(400, "old password format", EJSON.stringify({
@@ -449,8 +463,9 @@ Meteor.methods({changePassword: function (oldPassword, newPassword) {
449463
}
450464

451465
var result = checkPassword(user, oldPassword);
452-
if (result.error)
466+
if (result.error) {
453467
throw result.error;
468+
}
454469

455470
var hashed = hashPassword(newPassword);
456471

@@ -489,8 +504,9 @@ Accounts.setPassword = function (userId, newPlaintextPassword, options) {
489504
options = _.extend({logout: true}, options);
490505

491506
var user = Meteor.users.findOne(userId);
492-
if (!user)
507+
if (!user) {
493508
throw new Meteor.Error(403, "User not found");
509+
}
494510

495511
var update = {
496512
$unset: {
@@ -518,8 +534,9 @@ Meteor.methods({forgotPassword: function (options) {
518534
check(options, {email: String});
519535

520536
var user = Accounts.findUserByEmail(options.email);
521-
if (!user)
537+
if (!user) {
522538
handleError("User not found");
539+
}
523540

524541
const emails = _.pluck(user.emails || [], 'address');
525542
const caseSensitiveEmail = _.find(emails, email => {
@@ -542,15 +559,19 @@ Meteor.methods({forgotPassword: function (options) {
542559
Accounts.sendResetPasswordEmail = function (userId, email) {
543560
// Make sure the user exists, and email is one of their addresses.
544561
var user = Meteor.users.findOne(userId);
545-
if (!user)
562+
if (!user) {
546563
handleError("Can't find user");
564+
}
547565

548566
// 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]) {
550568
email = user.emails[0].address;
569+
}
570+
551571
// 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)) {
553573
handleError("No such email for user.");
574+
}
554575

555576
var token = Random.secret();
556577
var when = new Date();
@@ -581,9 +602,10 @@ Accounts.sendResetPasswordEmail = function (userId, email) {
581602
Accounts.emailTemplates.resetPassword.text(user, resetPasswordUrl);
582603
}
583604

584-
if (typeof Accounts.emailTemplates.resetPassword.html === 'function')
605+
if (typeof Accounts.emailTemplates.resetPassword.html === 'function') {
585606
options.html =
586607
Accounts.emailTemplates.resetPassword.html(user, resetPasswordUrl);
608+
}
587609

588610
if (typeof Accounts.emailTemplates.headers === 'object') {
589611
options.headers = Accounts.emailTemplates.headers;
@@ -612,14 +634,17 @@ Accounts.sendEnrollmentEmail = function (userId, email) {
612634

613635
// Make sure the user exists, and email is in their addresses.
614636
var user = Meteor.users.findOne(userId);
615-
if (!user)
637+
if (!user) {
616638
throw new Error("Can't find user");
639+
}
617640
// 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]) {
619642
email = user.emails[0].address;
643+
}
620644
// 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)) {
622646
throw new Error("No such email for user.");
647+
}
623648

624649
var token = Random.secret();
625650
var when = new Date();
@@ -651,9 +676,10 @@ Accounts.sendEnrollmentEmail = function (userId, email) {
651676
Accounts.emailTemplates.enrollAccount.text(user, enrollAccountUrl);
652677
}
653678

654-
if (typeof Accounts.emailTemplates.enrollAccount.html === 'function')
679+
if (typeof Accounts.emailTemplates.enrollAccount.html === 'function') {
655680
options.html =
656681
Accounts.emailTemplates.enrollAccount.html(user, enrollAccountUrl);
682+
}
657683

658684
if (typeof Accounts.emailTemplates.headers === 'object') {
659685
options.headers = Accounts.emailTemplates.headers;
@@ -678,8 +704,9 @@ Meteor.methods({resetPassword: function (token, newPassword) {
678704

679705
var user = Meteor.users.findOne({
680706
"services.password.reset.token": token});
681-
if (!user)
707+
if (!user) {
682708
throw new Meteor.Error(403, "Token expired");
709+
}
683710
var when = user.services.password.reset.when;
684711
var reason = user.services.password.reset.reason;
685712
var tokenLifetimeMs = Accounts._getPasswordResetTokenLifetimeMs();

0 commit comments

Comments
 (0)