X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/57aeccccc8d23adceac028616b7877ae6c4e0c87..18453600aa5c208276c7d2f329952642924f4a75:/app/controllers/amf_controller.rb diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 47f8f2458..5771f4e3d 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -1,6 +1,7 @@ class AmfController < ApplicationController require 'stringio' + session :off before_filter :check_availability # to log: @@ -690,18 +691,33 @@ end def createuniquenodes(uqs_name,uqn_name) # Finds nodes which appear in uniquesegments but no other segments sql=<<-EOF - CREATE TEMPORARY TABLE #{uqn_name} - SELECT DISTINCT node_id - FROM (SELECT cn.id AS node_id - FROM current_nodes AS cn, - current_segments AS cs, - #{uqs_name} AS us - WHERE cs.id=us.segment_id - AND (cn.id=cs.node_a OR cn.id=cs.node_b)) AS n - LEFT JOIN current_segments AS cs2 ON node_id=cs2.node_a AND cs2.visible=1 - LEFT JOIN current_segments AS cs3 ON node_id=cs3.node_b AND cs3.visible=1 - WHERE cs2.node_a IS NULL - AND cs3.node_b IS NULL + CREATE TEMPORARY TABLE #{uqn_name} + SELECT DISTINCT node_id + FROM (SELECT cn.id AS node_id + FROM current_nodes AS cn, + current_segments AS cs, + #{uqs_name} AS us + WHERE cs.id=us.segment_id + AND cn.id=cs.node_a) AS n + LEFT JOIN current_segments AS cs2 ON node_id=cs2.node_a AND cs2.visible=1 + LEFT JOIN current_segments AS cs3 ON node_id=cs3.node_b AND cs3.visible=1 + WHERE cs2.node_a IS NULL + AND cs3.node_b IS NULL + EOF + ActiveRecord::Base.connection.execute(sql) + sql=<<-EOF + INSERT INTO #{uqn_name} + SELECT DISTINCT node_id + FROM (SELECT cn.id AS node_id + FROM current_nodes AS cn, + current_segments AS cs, + #{uqs_name} AS us + WHERE cs.id=us.segment_id + AND cn.id=cs.node_b) AS n + LEFT JOIN current_segments AS cs2 ON node_id=cs2.node_a AND cs2.visible=1 + LEFT JOIN current_segments AS cs3 ON node_id=cs3.node_b AND cs3.visible=1 + WHERE cs2.node_a IS NULL + AND cs3.node_b IS NULL EOF ActiveRecord::Base.connection.execute(sql) end @@ -735,12 +751,13 @@ def array2tag(a) end def getuserid(token) - token=sqlescape(token) - if (token=~/^(.+)\+(.+)$/) then - return ActiveRecord::Base.connection.select_value("SELECT id FROM users WHERE active=1 AND email='#{$1}' AND pass_crypt=MD5('#{$2}')") + if (token =~ /^(.+)\+(.+)$/) then + user = User.authenticate(:username => $1, :password => $2) else - return ActiveRecord::Base.connection.select_value("SELECT id FROM users WHERE active=1 AND token='#{token}'") + user = User.authenticate(:token => token) end + + return user ? user.id : nil; end