discourse/discourse

View on GitHub
app/controllers/session_controller.rb

Summary

Maintainability
F
4 days
Test Coverage

Method sso_login has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
Open

  def sso_login
    raise Discourse::NotFound.new unless SiteSetting.enable_sso

    params.require(:sso)
    params.require(:sig)
Severity: Minor
Found in app/controllers/session_controller.rb - About 7 hrs 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

File session_controller.rb has 366 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require_dependency 'rate_limiter'
require_dependency 'single_sign_on'
require_dependency 'single_sign_on_provider'
require_dependency 'url_helper'

Severity: Minor
Found in app/controllers/session_controller.rb - About 4 hrs to fix

    Method sso_login has 96 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def sso_login
        raise Discourse::NotFound.new unless SiteSetting.enable_sso
    
        params.require(:sso)
        params.require(:sig)
    Severity: Major
    Found in app/controllers/session_controller.rb - About 3 hrs to fix

      Method sso_provider has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

        def sso_provider(payload = nil)
          payload ||= request.query_string
      
          if SiteSetting.enable_sso_provider
            sso = SingleSignOnProvider.parse(payload)
      Severity: Minor
      Found in app/controllers/session_controller.rb - About 3 hrs 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

      Method create has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          unless params[:second_factor_token].blank?
            RateLimiter.new(nil, "second-factor-min-#{request.remote_ip}", 3, 1.minute).performed!
          end
      
      
      Severity: Minor
      Found in app/controllers/session_controller.rb - About 2 hrs 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

      Class SessionController has 22 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class SessionController < ApplicationController
        class LocalLoginNotAllowed < StandardError; end
        rescue_from LocalLoginNotAllowed do
          render body: nil, status: 500
        end
      Severity: Minor
      Found in app/controllers/session_controller.rb - About 2 hrs to fix

        Method email_login has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

          def email_login
            raise Discourse::NotFound if !SiteSetting.enable_local_logins_via_email
            second_factor_token = params[:second_factor_token]
            second_factor_method = params[:second_factor_method].to_i
            token = params[:token]
        Severity: Minor
        Found in app/controllers/session_controller.rb - 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

        Method sso_provider has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def sso_provider(payload = nil)
            payload ||= request.query_string
        
            if SiteSetting.enable_sso_provider
              sso = SingleSignOnProvider.parse(payload)
        Severity: Minor
        Found in app/controllers/session_controller.rb - About 1 hr to fix

          Method create has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def create
              unless params[:second_factor_token].blank?
                RateLimiter.new(nil, "second-factor-min-#{request.remote_ip}", 3, 1.minute).performed!
              end
          
          
          Severity: Minor
          Found in app/controllers/session_controller.rb - About 1 hr to fix

            Method sso has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              def sso
                destination_url = cookies[:destination_url] || session[:destination_url]
                return_path = params[:return_path] || path('/')
            
                if destination_url && return_path == path('/')
            Severity: Minor
            Found in app/controllers/session_controller.rb - 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

            Method email_login has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def email_login
                raise Discourse::NotFound if !SiteSetting.enable_local_logins_via_email
                second_factor_token = params[:second_factor_token]
                second_factor_method = params[:second_factor_method].to_i
                token = params[:token]
            Severity: Minor
            Found in app/controllers/session_controller.rb - About 1 hr to fix

              Method forgot_password has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def forgot_password
                  params.require(:login)
              
                  RateLimiter.new(nil, "forgot-password-hr-#{request.remote_ip}", 6, 1.hour).performed!
                  RateLimiter.new(nil, "forgot-password-min-#{request.remote_ip}", 3, 1.minute).performed!
              Severity: Minor
              Found in app/controllers/session_controller.rb - 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

              Avoid too many return statements within this method.
              Open

                      return render json: failed_json.merge(
                        error: I18n.t("login.invalid_second_factor_code"),
                        reason: "invalid_second_factor",
                        backup_enabled: user.backup_codes_enabled?
                      )
              Severity: Major
              Found in app/controllers/session_controller.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                          return
                Severity: Major
                Found in app/controllers/session_controller.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                            redirect_to(users_account_created_path) && (return)
                  Severity: Major
                  Found in app/controllers/session_controller.rb - About 30 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status