summaryrefslogtreecommitdiff
path: root/app/controllers/application_controller.rb
blob: f94dcfaed83fab8aee0a6849155dab146fdc7585 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  before_filter :ensure_valid_session

  def resolve(key)
    Spank::IOC.resolve(key)
  end

  def current_user
    @current_user ||= @current_session.user
  end

  private

  def ensure_valid_session
    #::TODO look up session by unique session key not id.
    unless session[:user_session_id] && @current_session = Session.find(session[:user_session_id])
      redirect_to new_session_path
    end
  rescue ActiveRecord::RecordNotFound
    redirect_to new_session_path
  end
end