]> git.openstreetmap.org Git - rails.git/commitdiff
Store the username in a cookie and use it to validate the session
authorTom Hughes <tom@compton.nu>
Mon, 7 Nov 2011 17:46:15 +0000 (17:46 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 14 Nov 2011 09:42:59 +0000 (09:42 +0000)
app/controllers/application_controller.rb
app/controllers/user_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
 
index 3622b037d683abac9ce4f44c1cc7b243f98ca439..5104715552b1bd77d5be860b0e0a18d9c852de58 100644 (file)
@@ -336,6 +336,7 @@ class UserController < ApplicationController
             token.destroy
 
             session[:user] = user.id
+            cookies["_osm_username"] = user.display_name
 
             if referer.nil?
               flash[:notice] = t('user.confirm.success') + "<br /><br />" + t('user.confirm.before you start')
@@ -388,6 +389,7 @@ class UserController < ApplicationController
         end
         token.destroy
         session[:user] = @user.id
+        cookies["_osm_username"] = @user.display_name
         redirect_to :action => 'account', :display_name => @user.display_name
       else
         flash[:error] = t 'user.confirm_email.failure'
@@ -615,6 +617,8 @@ private
   ##
   # process a successful login
   def successful_login(user)
+    cookies["_osm_username"] = user.display_name
+
     session[:user] = user.id
     session_expires_after 1.month if session[:remember_me]