Sha256: e75117cfc63378d4e1b9a0340eae526c03c7b0420a8145eb6e6b5027070b21b7

Contents?: true

Size: 1.86 KB

Versions: 6

Compression:

Stored size: 1.86 KB

Contents

module DeviseSecurityExtension
  module Controllers # :nodoc:
    module Helpers # :nodoc:
      extend ActiveSupport::Concern

      included do
        before_filter :handle_password_change
      end
      
      module ClassMethods
        # helper for captcha
        def init_recover_password_captcha
          p "init"
          p self.inspect
          
          include RecoverPasswordCaptcha
        end        
      end

      module RecoverPasswordCaptcha
        def new
          p "Check here captcha"
          super
        end
      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

6 entries across 6 versions & 1 rubygems

Version Path
devise_security_extension-0.6.0 lib/devise_security_extension/controllers/helpers.rb
devise_security_extension-0.5.1 lib/devise_security_extension/controllers/helpers.rb
devise_security_extension-0.5.0 lib/devise_security_extension/controllers/helpers.rb
devise_security_extension-0.4.2 lib/devise_security_extension/controllers/helpers.rb
devise_security_extension-0.4.1 lib/devise_security_extension/controllers/helpers.rb
devise_security_extension-0.4.0 lib/devise_security_extension/controllers/helpers.rb