Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. // It depends on what your using for backing your sessions. If the session is in the Cookie then there's nothing your Admin can do with it as there's nothing server side to work with. Irregardless, messing with someone else's session may not be possible as you won't know the session ID.
  2.  
  3. // What you want to do is either catch the ActiveRecord::RecordNotFound that is thrown by find or use find_by_id which will return nil. When the user tries to access the site with the session referencing a deleted user, you can then kill the session.
  4.  
  5. def current_user
  6. @current_user ||= Twitteruser.find(session[:twitteruser_id]) if session[:twitteruser_id]
  7. rescue ActiveRecord::RecordNotFound
  8. session[:twitteruser_id] = nil # or reset_session
  9. end
  10. or
  11.  
  12. def current_user
  13. @current_user ||= fetch_user(session[:twitteruser_id])
  14. end
  15.  
  16. def fetch_user(id)
  17. Twitteruser.find_by_id(id) || reset_session unless id.nil?
  18. end
  19.  
  20. // This will work regardless of how a Twitteruser gets deleted. For example, imagine if you deleted the user from the rails console where there is no session.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement