# 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

  # See ActionController::RequestForgeryProtection for details
  # Uncomment the :secret if you're not using the cookie session store
  protect_from_forgery  :secret => 'a0eb34fe2f95d34c9b4035eb8c3cabde'
  
  # See ActionController::Base for details 
  # Uncomment this to filter the contents of submitted sensitive data parameters
  # from your application log (in this case, all fields with names like "password"). 
  # filter_parameter_logging :password
 
 # Wybierz unikatow nazw pliku cookie, aby odrni dane naszej sesji spord innych
  session :session_key => '_rails_space_session_id'
  
  # Sprawd, czy istnieje poprawny plik cookie, ewentualnie zaloguj uytkownika
  def check_authorization
    if cookies[:authorization_token] and not session[:user_id]
      user = User.find_by_authorization_token (cookies[:authorization_token])
      if user
        session[:user_id] = user.id
      end
    end
  end
end

