+ def preferred_editor
+ editor = if params[:editor]
+ params[:editor]
+ elsif current_user && current_user.preferred_editor
+ current_user.preferred_editor
+ else
+ DEFAULT_EDITOR
+ end
+
+ editor
+ end
+
+ 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
+ def get_auth_data
+ if request.env.key? "X-HTTP_AUTHORIZATION" # where mod_rewrite might have put it
+ authdata = request.env["X-HTTP_AUTHORIZATION"].to_s.split
+ elsif request.env.key? "REDIRECT_X_HTTP_AUTHORIZATION" # mod_fcgi
+ authdata = request.env["REDIRECT_X_HTTP_AUTHORIZATION"].to_s.split
+ elsif request.env.key? "HTTP_AUTHORIZATION" # regular location
+ authdata = request.env["HTTP_AUTHORIZATION"].to_s.split
+ end
+ # only basic authentication supported
+ user, pass = Base64.decode64(authdata[1]).split(":", 2) if authdata && authdata[0] == "Basic"
+ [user, pass]