Class: Headstart::ImpersonationsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/headstart/impersonations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/headstart/impersonations_controller.rb', line 11

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)
    (user)
    redirect_to root_url
  end
end

#destroyObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/headstart/impersonations_controller.rb', line 24

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
    (admin_user)
    redirect_to impersonations_url
  else
    deny_access
  end
end

#indexObject



6
7
8
9
# File 'app/controllers/headstart/impersonations_controller.rb', line 6

def index
  @users = User.all
  render :template => 'impersonations/index'
end