]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/application_controller.rb
Make OAuth work again
[rails.git] / app / controllers / application_controller.rb
index ec2f381fc8b971448853385692c1b339c3ff3b04..44307d482e90e7afaca8e01c15be347f8208b7b7 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
 
@@ -35,11 +38,13 @@ class ApplicationController < ActionController::Base
         end
       end
     elsif session[:token]
-      @user = User.authenticate(:token => session[:token])
-      session[:user] = @user.id
+      if @user = User.authenticate(:token => session[:token])
+        session[:user] = @user.id
+      end
     end
   rescue Exception => ex
     logger.info("Exception authorizing user: #{ex.to_s}")
+    reset_session
     @user = nil
   end
 
@@ -242,7 +247,7 @@ class ApplicationController < ActionController::Base
       end
     end
 
-    I18n.locale = request.compatible_language_from(I18n.available_locales)
+    I18n.locale = request.compatible_language_from(I18n.available_locales) || I18n.default_locale
 
     response.headers['Content-Language'] = I18n.locale.to_s
   end
@@ -361,6 +366,11 @@ private
     return [user, pass] 
   end 
 
+  # used by oauth plugin to get the current user
+  def current_user
+    @user
+  end
+
   # used by oauth plugin to set the current user
   def current_user=(user)
     @user=user