a long variety of improvements and tweaks
[selectricity] / app / controllers / site_controller.rb
index daa74f8cb866feaa7050999a026896d93457b79f..47ae2cbd87af5dbde48f59c1fdbb6feb44c92f4d 100644 (file)
@@ -3,10 +3,20 @@ class SiteController < ApplicationController
   model :user, :election
 
   def index
+    # if the person claims they are logged in
     if session[:user]
-      session[:user] = User.find(session[:user].id)
-      @current_elections = session[:user].elections.sort do |a,b|
-        b.enddate <=> a.enddate
+
+      # check to see that we actually have record of them
+      if User.find_all(["id = ?", session[:user].id]).length == 1
+        # if we have record of them, grab the list of their elections
+        session[:user] = User.find(session[:user].id)
+        @current_elections = session[:user].elections.sort do |a,b|
+          b.enddate <=> a.enddate
+        end
+      else
+        # if we have no record of them, set the session id back to
+       # nothing and start again
+        session[:user] = nil
       end
     end
   end

Benjamin Mako Hill || Want to submit a patch?