engine/lib/locomotive/routing/site_dispatcher.rb
Jacques Crocker 9097200339 Adding specific admin templates for the "no site" and "no page" errors.
Goal should be to use these to allow someone to create a new site right here
2010-09-21 04:45:34 -07:00

46 lines
1016 B
Ruby

module Locomotive
module Routing
module SiteDispatcher
extend ActiveSupport::Concern
included do
if self.respond_to?(:before_filter)
before_filter :fetch_site
helper_method :current_site
end
end
module InstanceMethods
protected
def fetch_site
Locomotive.logger "[fetch site] host = #{request.host} / #{request.env['HTTP_HOST']}"
@current_site ||= Site.match_domain(request.host).first
end
def current_site
@current_site || fetch_site
end
def require_site
render_no_site_error and return false if current_site.nil?
end
def render_no_site_error
render :template => "/admin/errors/no_site", :layout => false
end
def validate_site_membership
return if current_site && current_site.accounts.include?(current_admin)
sign_out_and_redirect(current_admin)
end
end
end
end
end