2010-04-11 23:59:18 +00:00
|
|
|
module Locomotive
|
2010-07-22 22:10:40 +00:00
|
|
|
module Routing
|
2010-04-11 23:59:18 +00:00
|
|
|
module SiteDispatcher
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
extend ActiveSupport::Concern
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
included do
|
2010-07-22 22:10:40 +00:00
|
|
|
if self.respond_to?(:before_filter)
|
|
|
|
before_filter :fetch_site
|
|
|
|
|
|
|
|
helper_method :current_site
|
|
|
|
end
|
2010-04-11 23:59:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
module InstanceMethods
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2010-04-11 23:59:18 +00:00
|
|
|
protected
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2010-04-11 23:59:18 +00:00
|
|
|
def fetch_site
|
2010-06-14 13:04:01 +00:00
|
|
|
Locomotive.logger "[fetch site] host = #{request.host} / #{request.env['HTTP_HOST']}"
|
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
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2010-04-11 23:59:18 +00:00
|
|
|
def current_site
|
2010-05-10 22:39:52 +00:00
|
|
|
@current_site || fetch_site
|
2010-04-11 23:59:18 +00:00
|
|
|
end
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2010-04-11 23:59:18 +00:00
|
|
|
def require_site
|
|
|
|
redirect_to application_root_url and return false if current_site.nil?
|
|
|
|
end
|
2010-07-22 22:10:40 +00:00
|
|
|
|
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-07-28 00:42:33 +00:00
|
|
|
sign_out_and_redirect(current_admin)
|
2010-05-10 22:39:52 +00:00
|
|
|
end
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2010-04-11 23:59:18 +00:00
|
|
|
def application_root_url
|
|
|
|
root_url(:host => Locomotive.config.default_domain, :port => request.port)
|
|
|
|
end
|
2010-07-22 22:10:40 +00:00
|
|
|
|
2010-04-11 23:59:18 +00:00
|
|
|
end
|
2010-07-22 22:10:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
end
|