summaryrefslogtreecommitdiff
path: root/app/controllers/application_controller.rb
blob: 16d10594d6cd9869c287227b2b90fb3fb555fced (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
26
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_action :ensure_valid_session

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

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

  def current_session(session_key = cookies.signed[:raphael])
    @current_session ||= Session.authenticate!(session_key)
  end

  private

  def ensure_valid_session
    redirect_to new_session_path unless current_session
  rescue ActiveRecord::RecordNotFound
    redirect_to new_session_path
  end
end