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 452 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class SessionController < ApplicationController
  before_action :check_local_login_allowed, only: %i(create forgot_password)
  before_action :rate_limit_login, only: %i(create email_login)
  before_action :rate_limit_second_factor_totp, only: %i(create email_login)
  skip_before_action :redirect_to_login_if_required
Severity: Minor
Found in app/controllers/session_controller.rb - About 6 hrs to fix

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

      def sso_provider(payload = nil)
        if SiteSetting.enable_sso_provider
          begin
            if !payload
              params.require(:sso)
    Severity: Minor
    Found in app/controllers/session_controller.rb - About 5 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 sso_login has 98 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

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

      class SessionController < ApplicationController
        before_action :check_local_login_allowed, only: %i(create forgot_password)
        before_action :rate_limit_login, only: %i(create email_login)
        before_action :rate_limit_second_factor_totp, only: %i(create email_login)
        skip_before_action :redirect_to_login_if_required
      Severity: Minor
      Found in app/controllers/session_controller.rb - About 3 hrs to fix

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

          def sso_provider(payload = nil)
            if SiteSetting.enable_sso_provider
              begin
                if !payload
                  params.require(:sso)
        Severity: Major
        Found in app/controllers/session_controller.rb - About 2 hrs to fix

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

            def create
              params.require(:login)
              params.require(:password)
          
              return invalid_credentials if params[:password].length > User.max_password_length
          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 forgot_password has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            def forgot_password
              params.require(:login)
          
              if ScreenedIpAddress.should_block?(request.remote_ip)
                return render_json_error(I18n.t("login.reset_not_allowed_from_ip_address"))
          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 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_info has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def email_login_info
              token = params[:token]
              matched_token = EmailToken.confirmable(token)
              user = matched_token&.user
          
          
          Severity: Minor
          Found in app/controllers/session_controller.rb - About 1 hr to fix

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

              def create
                params.require(:login)
                params.require(:password)
            
                return invalid_credentials if params[:password].length > User.max_password_length
            Severity: Minor
            Found in app/controllers/session_controller.rb - About 1 hr to fix

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

                def email_login
                  token = params[:token]
                  matched_token = EmailToken.confirmable(token)
                  user = matched_token&.user
              
              
              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: @second_factor_failure_payload)
              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

                  Avoid too many return statements within this method.
                  Open

                        return render json: payload
                  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

                      Method one_time_password has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def one_time_password
                          @otp_username = otp_username = Discourse.redis.get "otp_#{params[:token]}"
                      
                          if otp_username && user = User.find_by_username(otp_username)
                            if current_user&.username == otp_username
                      Severity: Minor
                      Found in app/controllers/session_controller.rb - About 25 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

                      Method email_login_info has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def email_login_info
                          token = params[:token]
                          matched_token = EmailToken.confirmable(token)
                          user = matched_token&.user
                      
                      
                      Severity: Minor
                      Found in app/controllers/session_controller.rb - About 25 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

                      Method become has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                          def become
                      
                            raise Discourse::InvalidAccess if Rails.env.production?
                      
                            if ENV['DISCOURSE_DEV_ALLOW_ANON_TO_IMPERSONATE'] != "1"
                      Severity: Minor
                      Found in app/controllers/session_controller.rb - About 25 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

                      There are no issues that match your filters.

                      Category
                      Status