Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Filters added to this controller apply to all controllers in the application.
- # Likewise, all the methods added will be available for all controllers.
- class ApplicationController < ActionController::Base
- helper :all # include all helpers, all the time
- protect_from_forgery # See ActionController::RequestForgeryProtection for details
- # Scrub sensitive parameters from your log
- # filter_parameter_logging :password
- if RAILS_ENV == 'production'
- has_mobile_fu()
- else
- has_mobile_fu()
- end
- include Geokit::Geocoders
- helper_method :current_advertiser, :current_advertiser_session, :radius
- before_filter :meta_defaults
- before_filter :has_mobile_location, :except => [:get_location]
- # before_filter :lock_down
- def radius;
- session[:radius] || 5;
- end
- def distance
- advertiser_location = deal.advertiser
- user_location = session[:user_lat],session[:user_lng]
- distance = advertiser_location.distance_to(user_location)
- distance = distance * 1000
- distance.to_i
- end
- protected
- def admin_required
- authenticate_or_request_with_http_basic do |user_name, password|
- user_name == 'peter.nicholls' && password == 'NIch01@$'
- end if RAILS_ENV == 'production' || params[:admin_http]
- end
- def log_mobile_out
- if is_mobile_device? && !current_advertiser.nil?
- current_advertiser_session.destroy
- end
- end
- private
- def has_mobile_location
- if is_mobile_device? && session[:user_lat].nil? && session[:all_deals].nil?
- redirect_to :controller => 'home', :action => 'get_location'
- else
- return true
- end
- end
- def meta_defaults
- @meta_title = "Welcome to"
- @meta_keywords = "my keywords"
- @meta_description = "my meta description"
- end
- def current_advertiser_session
- return @current_advertiser_session if defined?(@current_advertiser_session)
- @current_advertiser_session = AdvertiserSession.find
- end
- def current_advertiser
- return @current_advertiser if defined?(@current_advertiser)
- @current_advertiser = current_advertiser_session && current_advertiser_session.record
- end
- def require_advertiser
- unless current_advertiser
- store_location
- flash[:notice] = "You must be logged in to access this page"
- redirect_to new_advertiser_session_url
- return false
- end
- end
- def require_no_advertiser
- if current_advertiser
- store_location
- flash[:notice] = "You must be logged out to access this page"
- redirect_to root_url
- return false
- end
- end
- def store_location
- session[:return_to] = request.request_uri
- end
- def redirect_back_or_default(default)
- redirect_to(session[:return_to] || default)
- session[:return_to] = nil
- end
- before_filter :set_time_zone
- def set_time_zone
- Time.zone = @current_advertiser.time_zone if @current_advertiser
- end
- end
Add Comment
Please, Sign In to add comment