<commit_before>module DeviseSecurityExtension
  module Controllers # :nodoc:
    module Helpers # :nodoc:
      extend ActiveSupport::Concern

      included do
        before_filter :handle_password_change
      end


      # controller instance methods
      module InstanceMethods
        private

        # lookup if an password change needed
        def handle_password_change
          Devise.mappings.keys.flatten.any? do |scope|
            if signed_in? scope
              if warden.session(scope)[:password_expired]
                session["#{scope}_return_to"] = request.path if request.get?
                redirect_for_password_change scope
                break
              end
            end
          end
        end

        # redirect for password update with alert message
        def redirect_for_password_change(scope)
          redirect_to change_password_required_path_for(scope), :alert => I18n.t('change_required', {:scope => 'devise.password_expired'})
        end

        # path for change password
        def change_password_required_path_for(resource_or_scope = nil)
          scope       = Devise::Mapping.find_scope!(resource_or_scope)
          change_path = "#{scope}_password_expired_path"
          send(change_path)
        end

      end
    end
  end

end<commit_msg>fix: on password expired - now possible to logout<commit_after>module DeviseSecurityExtension
  module Controllers # :nodoc:
    module Helpers # :nodoc:
      extend ActiveSupport::Concern

      included do
        before_filter :handle_password_change
      end


      # controller instance methods
      module InstanceMethods
        private

        # lookup if an password change needed
        def handle_password_change
          if not devise_controller? and not ignore_password_expire? and request.format.html?
            Devise.mappings.keys.flatten.any? do |scope|
              if signed_in?(scope) and warden.session(scope)[:password_expired]
                session["#{scope}_return_to"] = request.path if request.get?
                redirect_for_password_change scope
                return
              end
            end
          end
        end

        # redirect for password update with alert message
        def redirect_for_password_change(scope)
          redirect_to change_password_required_path_for(scope), :alert => I18n.t('change_required', {:scope => 'devise.password_expired'})
        end

        # path for change password
        def change_password_required_path_for(resource_or_scope = nil)
          scope       = Devise::Mapping.find_scope!(resource_or_scope)
          change_path = "#{scope}_password_expired_path"
          send(change_path)
        end
        
        protected
        
        # allow to overwrite for some special handlings
        def ignore_password_expire?
          false
        end

      end
    end
  end

end
{'fraction_non_alphanumeric': 0.0596551724137931, 'fraction_numerical': 0.001379310344827586, 'mean_word_length': 2.1670305676855897, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3516519', 'n_tokens_mistral': 767, 'n_tokens_neox': 744, 'n_words': 187}