module Fortress::Controller

The Controller module embbed all the code to “hook” Fortress to your Rails application.

@author zedtux

Public Instance Methods

access_deny() click to toggle source

Default access_deny method used when not re-defined in the Rails application.

You can re-define it within the ApplicationController of you rails application.

# File lib/fortress/controller.rb, line 31
def access_deny
  respond_to do |format|
    format.html { redirect_to_root_url_with_flash_message }
    format.json { unauthorized_with_error_message(:json) }
    format.xml { unauthorized_with_error_message(:xml) }
  end
end
prevent_access!() click to toggle source
# File lib/fortress/controller.rb, line 20
def prevent_access!
  controller = Fortress::ControllerInterface.new(self)
  Mechanism.authorised?(controller, action_name) ? true : access_deny
end

Private Instance Methods

error_message() click to toggle source
# File lib/fortress/controller.rb, line 55
def error_message
  'You are not authorised to access this page.'
end
redirect_to_root_url_with_flash_message() click to toggle source
# File lib/fortress/controller.rb, line 59
def redirect_to_root_url_with_flash_message
  flash[:error] = error_message
  redirect_to root_url
end
response_for_format(format) click to toggle source
# File lib/fortress/controller.rb, line 69
def response_for_format(format)
  response = { error: error_message }
  case
  when format == :json then response.to_json
  when format == :xml then response.to_xml
  end
end
unauthorized_with_error_message(format) click to toggle source
# File lib/fortress/controller.rb, line 64
def unauthorized_with_error_message(format)
  self.status = :unauthorized
  self.response_body = response_for_format(format)
end