Module: Effective::ImpersonationController::Impersonate

Defined in:
app/controllers/concerns/effective/impersonation_controller/impersonate.rb

Instance Method Summary collapse

Instance Method Details

#after_impersonate_path_for(user) ⇒ Object



23
24
25
# File 'app/controllers/concerns/effective/impersonation_controller/impersonate.rb', line 23

def after_impersonate_path_for(user)
  try(:dashboard_path) || try(:root_path) || '/'
end

#impersonateObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/concerns/effective/impersonation_controller/impersonate.rb', line 5

def impersonate
  @user = current_user.class.find(params[:id])
  redirect_path = after_impersonate_path_for(@user)

  authorize! :impersonate, @user

  # Impersonate
  session[:impersonation_user_id] = current_user.id
  session[:impersonation_original_path] = request.referer.presence || '/admin/users'

  expire_data_after_sign_in!
  warden.session_serializer.store(@user, Devise::Mapping.find_scope!(@user))

  @user.touch

  redirect_to(redirect_path)
end