<commit_before>module Puffer
  module Controller
    # Module provides authentification methods and helpers for puffer
    # controllers. Puffer's authentification system is simple. In general, you
    # should use different kinds of routing and controllers namespaces for
    # partial access of different user types.
    # 
    # Method +has_puffer_access?+ with current namespace name as a parameter.
    # If you want to use appication's own auth system - just redefine this
    # method in your ApplicationController.
    #
    # Also see Puffer::SessionsBase.
    module Auth
      extend ActiveSupport::Concern

      included do
        helper_method :current_puffer_user
      end

      module InstanceMethods

        # Return current user instance, used for authorization. This method can
        # be redefined in ApplicationController if you want to use application's
        # auth system. 
        # 
        # ex:
        #
        #   class ApplicationController < ActionController::Base
        #     def current_puffer_user
        #       current_user
        #     end
        #   end
        # 
        # In this case returner user model instance should respond to has_role?
        # method, or you should properly redefine +has_puffer_access?+ See
        # +has_puffer_access?+ source and docs.
        def current_puffer_user
          @current_puffer_user ||= super rescue (PufferUser.find(session[:puffer_user_id]) if session[:puffer_user_id])
        end

        # Used in before_filter to prevent unauthorized access
        def require_puffer_user
          unless has_puffer_access?(puffer_namespace)
            redirect_to new_admin_session_url(:return_to => request.fullpath)
            return false
          end
        end

        # This method is also part of auth system and it can be redefined at the
        # ApplicationController.
        #<commit_msg>solves problem with executing find method against module instead class<commit_after>module Puffer
  module Controller
    # Module provides authentification methods and helpers for puffer
    # controllers. Puffer's authentification system is simple. In general, you
    # should use different kinds of routing and controllers namespaces for
    # partial access of different user types.
    # 
    # Method +has_puffer_access?+ with current namespace name as a parameter.
    # If you want to use appication's own auth system - just redefine this
    # method in your ApplicationController.
    #
    # Also see Puffer::SessionsBase.
    module Auth
      extend ActiveSupport::Concern

      included do
        helper_method :current_puffer_user
      end

      module InstanceMethods

        # Return current user instance, used for authorization. This method can
        # be redefined in ApplicationController if you want to use application's
        # auth system. 
        # 
        # ex:
        #
        #   class ApplicationController < ActionController::Base
        #     def current_puffer_user
        #       current_user
        #     end
        #   end
        # 
        # In this case returner user model instance should respond to has_role?
        # method, or you should properly redefine +has_puffer_access?+ See
        # +has_puffer_access?+ source and docs.
        def current_puffer_user
          @current_puffer_user ||= super rescue (::PufferUser.find(session[:puffer_user_id]) if session[:puffer_user_id])
        end

        # Used in before_filter to prevent unauthorized access
        def require_puffer_user
          unless has_puffer_access?(puffer_namespace)
            redirect_to new_admin_session_url(:return_to => request.fullpath)
            return false
          end
        end

        # This method is also part of auth system and it can be redefined at the
        # ApplicationController.
        #
{'fraction_non_alphanumeric': 0.04819901528893496, 'fraction_numerical': 0.0, 'mean_word_length': 2.409893992932862, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3924987', 'n_tokens_mistral': 989, 'n_tokens_neox': 957, 'n_words': 355}