module DeviseExtension::Controllers::Helpers

Protected Instance Methods

ignore_password_expire?() click to toggle source

allow to overwrite for some special handlings

# File lib/devise/controllers/extension_helpers.rb, line 47
def ignore_password_expire?
  false
end

Private Instance Methods

change_password_required_path_for(resource_or_scope = nil) click to toggle source

path for change password

# File lib/devise/controllers/extension_helpers.rb, line 38
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
handle_password_change() click to toggle source

lookup if an password change needed

# File lib/devise/controllers/extension_helpers.rb, line 14
def handle_password_change
  return if warden.nil?
  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']
        # re-check to avoid infinite loop if date changed after login attempt
        if send(:"current_#{scope}").try(:need_change_password?)
          session["#{scope}_return_to"] = request.original_fullpath if request.get?
          redirect_for_password_change scope
          return
        else
          warden.session(scope)[:password_expired] = false
        end
      end
    end
  end
end
redirect_for_password_change(scope) click to toggle source

redirect for password update with alert message

# File lib/devise/controllers/extension_helpers.rb, line 33
def redirect_for_password_change(scope)
  redirect_to change_password_required_path_for(scope), alert: 'Your password has expired. Please renew your password.'
end