LucasAntoniassi/meteor-accounts-lockout

View on GitHub
src/unknownUser.js

Summary

Maintainability
F
3 days
Test Coverage

File unknownUser.js has 300 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import _AccountsLockoutCollection from './accountsLockoutCollection';

class UnknownUser {
Severity: Minor
Found in src/unknownUser.js - About 3 hrs to fix

    UnknownUser has 21 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class UnknownUser {
      constructor(
        settings,
        {
          AccountsLockoutCollection = _AccountsLockoutCollection,
    Severity: Minor
    Found in src/unknownUser.js - About 2 hrs to fix

      Function validateLoginAttempt has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        validateLoginAttempt(loginInfo) {
          // don't interrupt non-password logins
          if (
            loginInfo.type !== 'password' ||
            loginInfo.user !== undefined ||
      Severity: Minor
      Found in src/unknownUser.js - About 1 hr to fix

        Function validateLoginAttempt has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

          validateLoginAttempt(loginInfo) {
            // don't interrupt non-password logins
            if (
              loginInfo.type !== 'password' ||
              loginInfo.user !== undefined ||
        Severity: Minor
        Found in src/unknownUser.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 scheduleUnlocksForLockedAccounts has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          scheduleUnlocksForLockedAccounts() {
            const lockedAccountsCursor = this.AccountsLockoutCollection.find(
              {
                'services.accounts-lockout.unlockTime': {
                  $gt: Number(new Date()),
        Severity: Minor
        Found in src/unknownUser.js - About 1 hr to fix

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

            validateSettings() {
              if (
                !this.settings.failuresBeforeLockout ||
                this.settings.failuresBeforeLockout < 0
              ) {
          Severity: Major
          Found in src/unknownUser.js and 1 other location - About 4 hrs to fix
          src/knownUser.js on lines 31..50

          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 128.

          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

            updateSettings() {
              const settings = UnknownUser.unknownUsers();
              if (settings) {
                settings.forEach(function updateSetting({ key, value }) {
                  this.settings[key] = value;
          Severity: Major
          Found in src/unknownUser.js and 1 other location - About 2 hrs to fix
          src/knownUser.js on lines 21..29

          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 84.

          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 (failedAttempts === maxAttemptsAllowed) {
                this.setNewUnlockTime(failedAttempts, clientAddress);
          
                let duration = this.settings.lockoutPeriod;
                duration = Math.ceil(duration);
          Severity: Major
          Found in src/unknownUser.js and 1 other location - About 2 hrs to fix
          src/knownUser.js on lines 149..156

          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 81.

          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 4 locations. Consider refactoring.
          Open

            lastFailedAttempt(connection) {
              connection = this.findOneByConnection(connection);
              let lastFailedAttempt;
              try {
                lastFailedAttempt = connection.services['accounts-lockout'].lastFailedAttempt;
          Severity: Major
          Found in src/unknownUser.js and 3 other locations - About 2 hrs to fix
          src/unknownUser.js on lines 273..282
          src/unknownUser.js on lines 284..293
          src/unknownUser.js on lines 306..315

          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 76.

          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 4 locations. Consider refactoring.
          Open

            unlockTime(connection) {
              connection = this.findOneByConnection(connection);
              let unlockTime;
              try {
                unlockTime = connection.services['accounts-lockout'].unlockTime;
          Severity: Major
          Found in src/unknownUser.js and 3 other locations - About 2 hrs to fix
          src/unknownUser.js on lines 284..293
          src/unknownUser.js on lines 295..304
          src/unknownUser.js on lines 306..315

          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 76.

          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 4 locations. Consider refactoring.
          Open

            failedAttempts(connection) {
              connection = this.findOneByConnection(connection);
              let failedAttempts;
              try {
                failedAttempts = connection.services['accounts-lockout'].failedAttempts;
          Severity: Major
          Found in src/unknownUser.js and 3 other locations - About 2 hrs to fix
          src/unknownUser.js on lines 273..282
          src/unknownUser.js on lines 295..304
          src/unknownUser.js on lines 306..315

          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 76.

          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 4 locations. Consider refactoring.
          Open

            firstFailedAttempt(connection) {
              connection = this.findOneByConnection(connection);
              let firstFailedAttempt;
              try {
                firstFailedAttempt = connection.services['accounts-lockout'].firstFailedAttempt;
          Severity: Major
          Found in src/unknownUser.js and 3 other locations - About 2 hrs to fix
          src/unknownUser.js on lines 273..282
          src/unknownUser.js on lines 284..293
          src/unknownUser.js on lines 295..304

          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 76.

          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 (unlockTime > currentTime) {
                let duration = unlockTime - currentTime;
                duration = Math.ceil(duration / 1000);
                duration = duration > 1 ? duration : 1;
                UnknownUser.tooManyAttempts(duration);
          Severity: Major
          Found in src/unknownUser.js and 1 other location - About 1 hr to fix
          src/knownUser.js on lines 143..148

          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 69.

          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

            static unknownUsers() {
              let unknownUsers;
              try {
                unknownUsers = Meteor.settings['accounts-lockout'].unknownUsers;
              } catch (e) {
          Severity: Major
          Found in src/unknownUser.js and 1 other location - About 1 hr to fix
          src/knownUser.js on lines 259..267

          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 60.

          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

            static userNotFound(
              failedAttempts,
              maxAttemptsAllowed,
              attemptsRemaining,
            ) {
          Severity: Minor
          Found in src/unknownUser.js and 1 other location - About 55 mins to fix
          src/knownUser.js on lines 231..246

          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 53.

          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 (this.settings instanceof Function) {
                this.settings = this.settings(loginInfo.connection);
                this.validateSettings();
              }
          Severity: Minor
          Found in src/unknownUser.js and 1 other location - About 40 mins to fix
          src/knownUser.js on lines 120..123

          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 48.

          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