Sha256: b4d74049ec4aee4be6712ae64718134cbd7910505ff32e9a321b042aabdc8ff6

Contents?: true

Size: 1011 Bytes

Versions: 4

Compression:

Stored size: 1011 Bytes

Contents

class BrickLayer::BaseController < ApplicationController
  layout 'brick_layer/layouts/brick_layer_layout'
  protect_from_forgery

  helper_method :current_administrator

  before_filter :authenticate

  def authenticate
    request.format.html? ? authenticate_with_session : filter_public_responses
  end

  def current_administrator
    @current_administrator ||= BrickLayer::Administrator.find(session[:administrator_id]) if session[:administrator_id]  
  end 

  private

  def authenticate_with_session
    if !BrickLayer::Administrator.all.blank?
      redirect_to login_path unless current_administrator
    end
  end

  def authenticate_with_token
    if !BrickLayer.token.blank?
      if BrickLayer.token != request.headers["HTTP_X_AUTH_TOKEN"]
        render :nothing => true, :status => 401
      end
    end
  end

  def filter_public_responses
    authenticate_with_token

    unless %w{ index show }.include?(request.params[:action])
      render :nothing => true, :status => 401
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
brick_layer-0.10.6 app/controllers/brick_layer/base_controller.rb
brick_layer-0.10.5 app/controllers/brick_layer/base_controller.rb
brick_layer-0.10.3 app/controllers/brick_layer/base_controller.rb
brick_layer-0.10.2 app/controllers/brick_layer/base_controller.rb