2010-04-11 23:59:18 +00:00
|
|
|
module Locomotive
|
|
|
|
|
|
|
|
module Routing
|
|
|
|
|
|
|
|
module SiteDispatcher
|
|
|
|
|
|
|
|
def self.included(base)
|
|
|
|
base.class_eval do
|
|
|
|
include Locomotive::Routing::SiteDispatcher::InstanceMethods
|
|
|
|
|
|
|
|
before_filter :fetch_site
|
|
|
|
|
|
|
|
helper_method :current_site
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module InstanceMethods
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def fetch_site
|
2010-06-11 09:29:51 +00:00
|
|
|
logger.info "[fetch site] host = #{request.host} / #{request.env['HTTP_HOST']}" if Locomotive.config.enable_logs
|
2010-05-10 22:39:52 +00:00
|
|
|
@current_site ||= Site.match_domain(request.host).first
|
2010-04-11 23:59:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def current_site
|
2010-05-10 22:39:52 +00:00
|
|
|
@current_site || fetch_site
|
2010-04-11 23:59:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def require_site
|
|
|
|
redirect_to application_root_url and return false if current_site.nil?
|
|
|
|
end
|
|
|
|
|
2010-05-10 22:39:52 +00:00
|
|
|
def validate_site_membership
|
2010-06-10 22:07:59 +00:00
|
|
|
return if current_site && current_site.accounts.include?(current_admin)
|
2010-05-10 22:39:52 +00:00
|
|
|
redirect_to application_root_url
|
|
|
|
end
|
|
|
|
|
2010-04-11 23:59:18 +00:00
|
|
|
def application_root_url
|
|
|
|
root_url(:host => Locomotive.config.default_domain, :port => request.port)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|