Store the username in a cookie and use it to validate the session
[rails.git] / app / controllers / application_controller.rb
index d58bc8922146b32e48144e18a274ab038a6b37be..c2f1e644c5f928fd8da86415f5cf0bb6361816c7 100644 (file)
@@ -18,7 +18,10 @@ class ApplicationController < ActionController::Base
     if session[:user]
       @user = User.where(:id => session[:user]).where("status IN ('active', 'confirmed', 'suspended')").first
 
-      if @user.status == "suspended"
+      if @user.display_name != cookies["_osm_username"]
+        reset_session
+        @user = nil
+      elsif @user.status == "suspended"
         session.delete(:user)
         session_expires_automatically
 
@@ -37,10 +40,13 @@ class ApplicationController < ActionController::Base
     elsif session[:token]
       if @user = User.authenticate(:token => session[:token])
         session[:user] = @user.id
+      else
+        reset_session
       end
     end
   rescue Exception => ex
     logger.info("Exception authorizing user: #{ex.to_s}")
+    reset_session
     @user = nil
   end