I have been using Rick Olson’s restful_authentication plugin for quite some time now.
Recently I came across a requirement where the Site Admin was required to be able, to impersonate any user on the site.
Here’s how I achieved this:
When “Site Admin” logs-in on the site, I create two sessions namely:
If the Site Admin impersonates an user on the site,
replace the “session[:user_id]” with the id of the user we wish to impersonate.
So the Site Admin becomes the intended user.
Whenever Site Admin wants to stop impersonating,
replace “session[:user_id]” data with “session[:original_user_id]”
Site Admin regains original admin profile.
lib/authenticated_system.rb (Generated by restful_authentication plugin)
# Store the given user id in the session.
session[:user_id] = new_user ? new_user.id : nil
@current_user = new_user || false
I overloaded this method in my Application Controller:
if new_user &&…
View original post 207 more words