Module: UcbRailsUser::ImpersonationsControllerConcerns

Extended by:
ActiveSupport::Concern
Included in:
ImpersonationsController
Defined in:
app/controllers/concerns/ucb_rails_user/impersonations_controller_concerns.rb

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/concerns/ucb_rails_user/impersonations_controller_concerns.rb', line 12

def create
  target = UcbRailsUser.user_class.find_by(id: params[:ucb_rails_user_impersonation][:target_id])
  if logged_in_user.impersonate!(target)
    flash[:info] = "You are now impersonating #{target.full_name}"
    return redirect_to "/"
  else
    if target&.id == logged_in_user.id
      flash[:error] = "Sorry - you can't impersonate yourself."
    else
      flash[:error] = "Unable to start impersonating - please try again"
    end
    return redirect_to action: :index
  end
end

#indexObject



8
9
10
# File 'app/controllers/concerns/ucb_rails_user/impersonations_controller_concerns.rb', line 8

def index

end

#stop_impersonationObject



27
28
29
30
31
# File 'app/controllers/concerns/ucb_rails_user/impersonations_controller_concerns.rb', line 27

def stop_impersonation
  logged_in_user.stop_impersonation!
  flash[:info] = "You are no longer impersonating."
  redirect_to request.referer || "/"
end