Sha256: 09ad2fbba2da96ee0518578b8d5be0e316c8d13293536011a61bfd17cac4298d

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

module DevisePasswordExpirable
  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 not request.format.nil? 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
devise_password_expirable-2.0.0 lib/devise_password_expirable/controllers/helpers.rb