# 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 LDAP_HOST = 'dc1.lemanscorp.com' LDAP_PORT = 389 LDAP_BASE = 'dc=lemanscorp,dc=com' # See ActionController::RequestForgeryProtection for details # Uncomment the :secret if you're not using the cookie session store protect_from_forgery :secret => 'fcbe1c9f74bf1a95e75cb6f9b9a69246' def load_event_registration user = session[:participant] session[:registration] = RegistrationFinder.new(user.event.label, user.event.year.to_s) end def load_event_participant(credentials, options={}) user = Participant.find_by_credentials(credentials, options) if user != nil then if user.event != nil and user.event.allow_user_login != nil and user.event.allow_user_login == true if (user.agreement_response_date < Time.now and user.event_accepted_date == nil) or (user.event_accepted == false and user.event_accepted_date != nil) then return else session[:participant] = user session[:event] = user.event end else flash[:error] = "Invalid Credentials, Please use the Credentials given in your email. If you still face issues, Please contact events@parts-unltd.com." end end end def load_event_session(credentials, *forced_creds) forced_creds.each {|cred| credentials.merge!(cred => '') unless credentials.include?(cred) } event_participant_and_associations(credentials) and load_event_registration end def event_participant_and_associations(credentials) load_event_participant(credentials, {:include => [{:session_offers => :session}, {:registration_requirements => :registration_step}]}) end def find_view(name, loc=nil) loc ||= params[:controller] registration.find_file("#{name}.html.erb", {:in => "#{RAILS_ROOT}/app/views/#{loc}"}) end def event_view(name) File.join("events", find_view(name, "registrations/events")) end def use_layout(name) layout(find_view(name, "layouts")) end def registration; session[:registration] end def participant; session[:participant] end def registration_step_url(step) #puts registration.name + ', ' + registration.year + ', ' + step.place_in_order.to_s + ', ' + step.label File.join("", registration.name, registration.year, "registrations", "show", step.place_in_order.to_s, step.label) end def build_admin_sidebar @meet_and_greet_sessions = SessionOffer.find(:all, :include=>[:session, :attendees], :conditions=>"event_sessions.[label]='meet_and_greet' and event_sessions.[event_id] = #{session[:event].id}").collect{|o| o.attendees}.flatten.length @briefing_sessions = SessionOffer.find(:all, :include=>[:session, :attendees], :conditions=>"event_sessions.[label]='briefing_session' and event_sessions.[event_id] = #{session[:event].id}").collect{|o| o.attendees}.flatten.length end def admin_authenticate unless session[:admin] and session[:admin][:permissions] and session[:admin][:permissions].length > 0 authenticate_or_request_with_http_basic do |username, password| ldap = Net::LDAP.new(:host => LDAP_HOST, :port => LDAP_PORT, :base => LDAP_BASE) ldap.auth('LEMANSCORP\\' + username, password) if ldap.bind filter = Net::LDAP::Filter.eq('uid', username) ldap.search(:filter => filter) {|entry| username = entry.dn} ldap.search( :base => LDAP_BASE, :attributes => [], :filter => filter, :return_result => true ) do |entry| session[:admin]={ :name => entry[:uid].to_s, :email => entry[:mail].to_s, :full_name => entry[:name].to_s, :permissions => '' } for group in entry[:memberof] if group.to_s.match('CN=VER.*,OU=VendorEventRegistration,OU=Intranet,DC=lemanscorp,DC=com') session[:admin][:permissions] += group.to_s + ';' end end if session[:admin][:permissions].length == 0 session.close redirect_to(:controller=>'gateway', :action=>'logout') end return true end end session.close redirect_to(:controller=>'gateway', :action=>'logout') end end end def time_range(start, stop) return "(TBA)" unless start and stop format_time(start) + ' - ' + format_time(stop) end def format_time(time) time.strftime("%I:%M %p") if time != nil end def format_date(date) date.strftime("%m/%d/%Y") if date != nil end def formal_date(date) date.strftime("%A, %B %d, %Y") if date != nil end def sql_date(date) date.strftime("%Y-%m-%d %H:%M:%S") end end