]> git.openstreetmap.org Git - rails.git/commitdiff
Make export action send TOTP cookie
authorTom Hughes <tom@compton.nu>
Mon, 2 Jan 2017 22:51:18 +0000 (22:51 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 2 Jan 2017 22:51:18 +0000 (22:51 +0000)
app/controllers/application_controller.rb
app/controllers/export_controller.rb
app/controllers/site_controller.rb

index 09a35beb351f67ac3e40e4eb7caa9023fd2e2396..354fcc7c0cba1b61e3a3d04f73e0e9ddcf0f3fbf 100644 (file)
@@ -419,6 +419,16 @@ class ApplicationController < ActionController::Base
 
   helper_method :preferred_editor
 
+  def update_totp
+    if defined?(TOTP_KEY)
+      cookies["_osm_totp_token"] = {
+        :value => ROTP::TOTP.new(TOTP_KEY, :interval => 3600).now,
+        :domain => "openstreetmap.org",
+        :expires => 1.hour.from_now
+      }
+    end
+  end
+
   private
 
   # extract authorisation credentials from headers, returns user = nil if none
index fa7944516620e442064b8f8d5adb118d92042761..6e5016ddce4ec7eb6b0fcfaab09fb9634ffe8045 100644 (file)
@@ -1,6 +1,7 @@
 class ExportController < ApplicationController
   before_action :authorize_web
   before_action :set_locale
+  before_action :update_totp, :only => [:finish]
 
   caches_page :embed
 
index 71285356aeb39f4d350ba4d5c0ad5def28161639..5d35b9979f113e4a2074095f73ae831bbcdc2614 100644 (file)
@@ -8,19 +8,12 @@ class SiteController < ApplicationController
   before_action :redirect_map_params, :only => [:index, :edit, :export]
   before_action :require_user, :only => [:welcome]
   before_action :require_oauth, :only => [:index]
+  before_action :update_totp, :only => [:index]
 
   def index
     unless STATUS == :database_readonly || STATUS == :database_offline
       session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"])
     end
-
-    if defined?(TOTP_KEY)
-      cookies["_osm_totp_token"] = {
-        :value => ROTP::TOTP.new(TOTP_KEY, :interval => 3600).now,
-        :domain => "openstreetmap.org",
-        :expires => 1.hour.from_now
-      }
-    end
   end
 
   def permalink