]> projects.mako.cc - selectricity/blobdiff - lib/authenticated_system.rb
fixed some typos caught in the first usage
[selectricity] / lib / authenticated_system.rb
index 840d89aac08c489ed964271dd262f20cf9318876..370a3e961ed74dac41cff7b8ec1c2e26326dd592 100644 (file)
@@ -3,17 +3,18 @@ module AuthenticatedSystem
     # Returns true or false if the user is logged in.
     # Preloads @current_user with the user model if they're logged in.
     def logged_in?
-      current_user != :false
+      (@current_user ||= session[:user_id] ? User.find_by_id(session[:user_id]) : :false).is_a?(User)
     end
     
     # Accesses the current user from the session.
     def current_user
-      @current_user ||= (session[:user] && User.find_by_id(session[:user])) || :false
+      @current_user if logged_in?
     end
     
     # Store the given user in the session.
     def current_user=(new_user)
-      session[:user] = (new_user.nil? || new_user.is_a?(Symbol)) ? nil : new_user.id
+      session[:user] = new_user
+      session[:user_id] = new_user.nil? ? nil : new_user.id
       @current_user = new_user
     end
     

Benjamin Mako Hill || Want to submit a patch?