Guest User

Untitled

a guest
Jul 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. # Filters added to this controller apply to all controllers in the application.
  2. # Likewise, all the methods added will be available for all controllers.
  3.  
  4. class ApplicationController < ActionController::Base
  5. helper :all # include all helpers, all the time
  6. protect_from_forgery # See ActionController::RequestForgeryProtection for details
  7.  
  8. # Scrub sensitive parameters from your log
  9. # filter_parameter_logging :password
  10.  
  11.  
  12.  
  13.  
  14.  
  15. if RAILS_ENV == 'production'
  16. has_mobile_fu()
  17. else
  18. has_mobile_fu()
  19. end
  20.  
  21. include Geokit::Geocoders
  22.  
  23.  
  24. helper_method :current_advertiser, :current_advertiser_session, :radius
  25.  
  26. before_filter :meta_defaults
  27.  
  28. before_filter :has_mobile_location, :except => [:get_location]
  29.  
  30. # before_filter :lock_down
  31.  
  32.  
  33.  
  34. def radius;
  35. session[:radius] || 5;
  36. end
  37.  
  38. def distance
  39. advertiser_location = deal.advertiser
  40. user_location = session[:user_lat],session[:user_lng]
  41. distance = advertiser_location.distance_to(user_location)
  42. distance = distance * 1000
  43. distance.to_i
  44. end
  45.  
  46. protected
  47. def admin_required
  48. authenticate_or_request_with_http_basic do |user_name, password|
  49. user_name == 'peter.nicholls' && password == 'NIch01@$'
  50. end if RAILS_ENV == 'production' || params[:admin_http]
  51. end
  52.  
  53.  
  54. def log_mobile_out
  55. if is_mobile_device? && !current_advertiser.nil?
  56. current_advertiser_session.destroy
  57. end
  58. end
  59.  
  60. private
  61.  
  62. def has_mobile_location
  63. if is_mobile_device? && session[:user_lat].nil? && session[:all_deals].nil?
  64. redirect_to :controller => 'home', :action => 'get_location'
  65. else
  66. return true
  67. end
  68. end
  69.  
  70. def meta_defaults
  71. @meta_title = "Welcome to"
  72. @meta_keywords = "my keywords"
  73. @meta_description = "my meta description"
  74. end
  75.  
  76. def current_advertiser_session
  77. return @current_advertiser_session if defined?(@current_advertiser_session)
  78. @current_advertiser_session = AdvertiserSession.find
  79. end
  80.  
  81. def current_advertiser
  82. return @current_advertiser if defined?(@current_advertiser)
  83. @current_advertiser = current_advertiser_session && current_advertiser_session.record
  84. end
  85.  
  86. def require_advertiser
  87. unless current_advertiser
  88. store_location
  89. flash[:notice] = "You must be logged in to access this page"
  90. redirect_to new_advertiser_session_url
  91. return false
  92. end
  93. end
  94.  
  95. def require_no_advertiser
  96. if current_advertiser
  97. store_location
  98. flash[:notice] = "You must be logged out to access this page"
  99. redirect_to root_url
  100. return false
  101. end
  102. end
  103.  
  104. def store_location
  105. session[:return_to] = request.request_uri
  106. end
  107.  
  108. def redirect_back_or_default(default)
  109. redirect_to(session[:return_to] || default)
  110. session[:return_to] = nil
  111. end
  112.  
  113. before_filter :set_time_zone
  114.  
  115. def set_time_zone
  116. Time.zone = @current_advertiser.time_zone if @current_advertiser
  117. end
  118.  
  119. end
Add Comment
Please, Sign In to add comment