1 class SiteController < ApplicationController
3 layout :map_layout, :only => [:index, :export]
5 before_action :authorize_web
6 before_action :set_locale
7 before_action :redirect_browse_params, :only => :index
8 before_action :redirect_map_params, :only => [:index, :edit, :export]
9 before_action :require_user, :only => [:welcome]
10 before_action :require_oauth, :only => [:index]
13 unless STATUS == :database_readonly || STATUS == :database_offline
14 session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"])
18 cookies["_osm_totp_token"] = {
19 :value => ROTP::TOTP.new(TOTP_KEY, :interval => 3600).now,
20 :domain => ".openstreetmap.org",
21 :expires => 1.day.from_now
27 lon, lat, zoom = ShortLink.decode(params[:code])
28 new_params = params.except(:code, :lon, :lat, :zoom, :layers, :node, :way, :relation, :changeset)
32 new_params[:mlat] = lat
33 new_params[:mlon] = lon
37 new_params[:controller] = "browse"
38 new_params[:action] = "node"
39 new_params[:id] = params[:node]
40 elsif params.key? :way
41 new_params[:controller] = "browse"
42 new_params[:action] = "way"
43 new_params[:id] = params[:way]
44 elsif params.key? :relation
45 new_params[:controller] = "browse"
46 new_params[:action] = "relation"
47 new_params[:id] = params[:relation]
48 elsif params.key? :changeset
49 new_params[:controller] = "browse"
50 new_params[:action] = "changeset"
51 new_params[:id] = params[:changeset]
53 new_params[:controller] = "site"
54 new_params[:action] = "index"
57 new_params[:anchor] = "map=#{zoom}/#{lat}/#{lon}"
58 new_params[:anchor] += "&layers=#{params[:layers]}" if params.key? :layers
60 redirect_to Hash[new_params]
64 expires_in 7.days, :public => true
65 render :layout => false
69 editor = preferred_editor
73 render :action => :index, :layout => map_layout
80 bbox = Node.find(params[:node]).bbox.to_unscaled
81 @lat = bbox.centre_lat
82 @lon = bbox.centre_lon
85 bbox = Way.find(params[:way]).bbox.to_unscaled
86 @lat = bbox.centre_lat
87 @lon = bbox.centre_lon
90 note = Note.find(params[:note])
95 trace = Trace.visible_to(@user).find(params[:gpx])
97 @lon = trace.longitude
103 @locale = params[:copyright_locale] || I18n.locale
117 render :text => RichText.new(params[:format], params[:text]).to_html
121 render "id", :layout => false
126 def redirect_browse_params
128 redirect_to node_path(params[:node])
130 redirect_to way_path(params[:way])
131 elsif params[:relation]
132 redirect_to relation_path(params[:relation])
134 redirect_to browse_note_path(params[:note])
136 redirect_to search_path(:query => params[:query])
140 def redirect_map_params
143 if params[:lat] && params[:lon]
144 anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}"
148 anchor << "layers=#{params.delete(:layers)}"
149 elsif params.delete(:notes) == "yes"
154 redirect_to Hash[params].merge(:anchor => anchor.join("&"))