Sha256: cc57f8343f3878aa7fe79e032959f2f2540fc79684b4f1788182eb4d587579c4

Contents?: true

Size: 1.09 KB

Versions: 21

Compression:

Stored size: 1.09 KB

Contents

class Headstart::ImpersonationsController < ApplicationController
  before_filter :authenticate
  before_filter :check_role, :except => :destroy
  
  
  def index
    @users = User.all
    render :template => 'impersonations/index'
  end
  
  def create
    user = User.find(params[:user_id])
    if user == current_user
      flash[:failure] = "Cannot impersonate yourself"
      redirect_to root_url
    else
      session[:admin_user_id]       = current_user.id
      session[:impersonation_hash]  = Impersonation.hash_for(current_user.id)
      sign_in(user)
      redirect_to root_url
    end
  end
  
  def destroy
    if Impersonation.valid_hash?(session[:admin_user_id], session[:impersonation_hash])
      old_user    = current_user
      admin_user  = User.find(session[:admin_user_id])
      session[:admin_user_id]       = nil
      session[:impersonation_hash]  = nil
      sign_in(admin_user)
      redirect_to impersonations_url
    else
      deny_access
    end
  end
  
  
  private
  
  
  def check_role
    raise ActionController::Forbidden, "disallowed" unless current_user.admin?
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
headstart-0.11.2 app/controllers/headstart/impersonations_controller.rb
headstart-0.11.1 app/controllers/headstart/impersonations_controller.rb
headstart-0.9.2 app/controllers/headstart/impersonations_controller.rb
headstart-0.9.1 app/controllers/headstart/impersonations_controller.rb
headstart-0.9.0 app/controllers/headstart/impersonations_controller.rb
headstart-0.8.0 app/controllers/headstart/impersonations_controller.rb
headstart-0.7.0 app/controllers/headstart/impersonations_controller.rb
headstart-0.6.2 app/controllers/headstart/impersonations_controller.rb
headstart-0.6.1 app/controllers/headstart/impersonations_controller.rb
headstart-0.6.0 app/controllers/headstart/impersonations_controller.rb
headstart-0.5.5 app/controllers/headstart/impersonations_controller.rb
headstart-0.5.4 app/controllers/headstart/impersonations_controller.rb
headstart-0.5.3 app/controllers/headstart/impersonations_controller.rb
headstart-0.5.2 app/controllers/headstart/impersonations_controller.rb
headstart-0.5.1 app/controllers/headstart/impersonations_controller.rb
headstart-0.5.0 app/controllers/headstart/impersonations_controller.rb
headstart-0.4.2 app/controllers/headstart/impersonations_controller.rb
headstart-0.4.1 app/controllers/headstart/impersonations_controller.rb
headstart-0.4.0 app/controllers/headstart/impersonations_controller.rb
headstart-0.3.0 app/controllers/headstart/impersonations_controller.rb