meteor/meteor

View on GitHub
packages/accounts-password/password_server.js

Summary

Maintainability
F
6 days
Test Coverage

File password_server.js has 595 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { hash as bcryptHash, compare as bcryptCompare } from 'bcrypt';
import { Accounts } from "meteor/accounts-base";

// Utility for grabbing user
const getUserById = (id, options) => Meteor.users.findOne(id, Accounts._addDefaultFieldSelector(options));
Severity: Major
Found in packages/accounts-password/password_server.js - About 1 day to fix

    Function resetPassword has 101 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    Meteor.methods({resetPassword: async function (...args) {
      const token = args[0];
      const newPassword = args[1];
      return await Accounts._loginMethod(
        this,
    Severity: Major
    Found in packages/accounts-password/password_server.js - About 4 hrs to fix

      Function verifyEmail has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Meteor.methods({verifyEmail: async function (...args) {
        const token = args[0];
        return await Accounts._loginMethod(
          this,
          "verifyEmail",
      Severity: Major
      Found in packages/accounts-password/password_server.js - About 2 hrs to fix

        Function addEmail has 51 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        Accounts.addEmail = (userId, newEmail, verified) => {
          check(userId, NonEmptyString);
          check(newEmail, NonEmptyString);
          check(verified, Match.Optional(Boolean));
        
        
        Severity: Major
        Found in packages/accounts-password/password_server.js - About 2 hrs to fix

          Function generateResetToken has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          Accounts.generateResetToken = (userId, email, reason, extraTokenData) => {
            // Make sure the user exists, and email is one of their addresses.
            // Don't limit the fields in the user object since the user is returned
            // by the function and some other fields might be used elsewhere.
            const user = getUserById(userId);
          Severity: Minor
          Found in packages/accounts-password/password_server.js - About 1 hr to fix

            Function generateVerificationToken has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            Accounts.generateVerificationToken = (userId, email, extraTokenData) => {
              // Make sure the user exists, and email is one of their addresses.
              // Don't limit the fields in the user object since the user is returned
              // by the function and some other fields might be used elsewhere.
              const user = getUserById(userId);
            Severity: Minor
            Found in packages/accounts-password/password_server.js - About 1 hr to fix

              Function changePassword has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              Meteor.methods({changePassword: async function (oldPassword, newPassword) {
                check(oldPassword, passwordValidator);
                check(newPassword, passwordValidator);
              
                if (!this.userId) {
              Severity: Minor
              Found in packages/accounts-password/password_server.js - About 1 hr to fix

                Function generateResetToken has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                Accounts.generateResetToken = (userId, email, reason, extraTokenData) => {
                  // Make sure the user exists, and email is one of their addresses.
                  // Don't limit the fields in the user object since the user is returned
                  // by the function and some other fields might be used elsewhere.
                  const user = getUserById(userId);
                Severity: Minor
                Found in packages/accounts-password/password_server.js - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function generateVerificationToken has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                Accounts.generateVerificationToken = (userId, email, extraTokenData) => {
                  // Make sure the user exists, and email is one of their addresses.
                  // Don't limit the fields in the user object since the user is returned
                  // by the function and some other fields might be used elsewhere.
                  const user = getUserById(userId);
                Severity: Minor
                Found in packages/accounts-password/password_server.js - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function addEmail has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                Accounts.addEmail = (userId, newEmail, verified) => {
                  check(userId, NonEmptyString);
                  check(newEmail, NonEmptyString);
                  check(verified, Match.Optional(Boolean));
                
                
                Severity: Minor
                Found in packages/accounts-password/password_server.js - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                Accounts.sendResetPasswordEmail = (userId, email, extraTokenData, extraParams) => {
                  const {email: realEmail, user, token} =
                    Accounts.generateResetToken(userId, email, 'resetPassword', extraTokenData);
                  const url = Accounts.urls.resetPassword(token, extraParams);
                  const options = Accounts.generateOptionsForEmail(realEmail, user, url, 'resetPassword');
                Severity: Major
                Found in packages/accounts-password/password_server.js and 1 other location - About 6 hrs to fix
                packages/accounts-password/password_server.js on lines 565..575

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 162.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                Accounts.sendEnrollmentEmail = (userId, email, extraTokenData, extraParams) => {
                  const {email: realEmail, user, token} =
                    Accounts.generateResetToken(userId, email, 'enrollAccount', extraTokenData);
                  const url = Accounts.urls.enrollAccount(token, extraParams);
                  const options = Accounts.generateOptionsForEmail(realEmail, user, url, 'enrollAccount');
                Severity: Major
                Found in packages/accounts-password/password_server.js and 1 other location - About 6 hrs to fix
                packages/accounts-password/password_server.js on lines 535..545

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 162.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                        } else {
                          affectedRecords = Meteor.users.update(
                            {
                              _id: user._id,
                              'emails.address': email,
                Severity: Major
                Found in packages/accounts-password/password_server.js and 1 other location - About 1 hr to fix
                packages/accounts-password/password_server.js on lines 655..665

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 71.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                        if(isEnroll) {
                          affectedRecords = Meteor.users.update(
                            {
                              _id: user._id,
                              'emails.address': email,
                Severity: Major
                Found in packages/accounts-password/password_server.js and 1 other location - About 1 hr to fix
                packages/accounts-password/password_server.js on lines 665..675

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 71.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                  } else {
                    Meteor.users.update({_id: user._id}, {
                      $set : {
                        'services.password.reset': tokenRecord
                      }
                Severity: Major
                Found in packages/accounts-password/password_server.js and 1 other location - About 1 hr to fix
                packages/accounts-password/password_server.js on lines 440..448

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 66.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                  if(reason === 'enrollAccount') {
                    Meteor.users.update({_id: user._id}, {
                      $set : {
                        'services.password.enroll': tokenRecord
                      }
                Severity: Major
                Found in packages/accounts-password/password_server.js and 1 other location - About 1 hr to fix
                packages/accounts-password/password_server.js on lines 448..456

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 66.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                  if (!user.services || !user.services.password ||
                      !user.services.password.bcrypt) {
                    Accounts._handleError("User has no password set");
                  }
                Severity: Major
                Found in packages/accounts-password/password_server.js and 1 other location - About 1 hr to fix
                packages/accounts-password/password_server.js on lines 281..283

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 56.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                  if (!user.services || !user.services.password || !user.services.password.bcrypt) {
                    Accounts._handleError("User has no password set");
                  }
                Severity: Major
                Found in packages/accounts-password/password_server.js and 1 other location - About 1 hr to fix
                packages/accounts-password/password_server.js on lines 190..193

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 56.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                  Match.Where(str => Match.test(str, String) && str.length <= Meteor.settings?.packages?.accounts?.passwordMaxLength || 256), {
                Severity: Minor
                Found in packages/accounts-password/password_server.js and 1 other location - About 55 mins to fix
                packages/accounts-password/password_server.js on lines 325..325

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 54.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                  check(newPlaintextPassword, Match.Where(str => Match.test(str, String) && str.length <= Meteor.settings?.packages?.accounts?.passwordMaxLength || 256));
                Severity: Minor
                Found in packages/accounts-password/password_server.js and 1 other location - About 55 mins to fix
                packages/accounts-password/password_server.js on lines 150..150

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 54.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                There are no issues that match your filters.

                Category
                Status