]> git.openstreetmap.org Git - rails.git/commitdiff
various fixes
authorSteve Coast <steve@asklater.com>
Fri, 18 Aug 2006 17:54:41 +0000 (17:54 +0000)
committerSteve Coast <steve@asklater.com>
Fri, 18 Aug 2006 17:54:41 +0000 (17:54 +0000)
app/controllers/application.rb
app/controllers/node_controller.rb
app/controllers/user_controller.rb
app/models/user.rb
config/routes.rb
db/migrate.sql [new file with mode: 0644]

index 6cd6dac06b5703ab0e78ba2037c9af435719bc46..82ef80920237cffbf8e1bf07b4a188c4cc2b5295 100644 (file)
@@ -10,20 +10,20 @@ class ApplicationController < ActionController::Base
     username, passwd = get_auth_data 
     # check if authorized 
     # try to get user 
-    if user = User.authenticate(username, passwd) 
+    if @user = User.authenticate(username, passwd) 
       # user exists and password is correct ... horray! 
-      if user.methods.include? 'lastlogin' 
+      if @user.methods.include? 'lastlogin' 
         # note last login 
         @session['lastlogin'] = user.lastlogin 
-        user.last.login = Time.now 
-        user.save() 
-        @session["User.id"] = user.id 
+        @user.last.login = Time.now 
+        @user.save() 
+        @session["User.id"] = @user.id 
       end             
     else 
       # the user does not exist or the password was wrong 
       @response.headers["Status"] = "Unauthorized" 
       @response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\"" 
-      render_text(errormessage, 401)       
+      render_text(errormessage, 401)
     end 
   end 
 
index a783ea9e6989c7a4429d5195e715d2a268e26802..c27081650a692375575940c9ea90804ae1b40fcd 100644 (file)
@@ -4,16 +4,141 @@ class NodeController < ApplicationController
   before_filter :authorize
 
   def create
-#    @node = Node.new
-#    @node.id = 1
-#    @node.latitude = 1
-#    @node.save
+    if request.put?
+      doc = XML::Document.new(request.raw_post) #THIS IS BROKEN, libxml docus dont talk about creating a doc from a string
+      doc.find('//osm/node').each do |pt|
+        render :text => 'arghsd.rkugt;dsrt'
+        return
+        lat = pt.attributes['lat'].to_f
+        lon = pt.attributes['lon'].to_f
+        node_id = pt.attributes['id'].to_i
 
-    if request.putt?
-      @txt = resp.body
+        if lat > 90 or lat < -90 or lon > 180 or lon < -180  or node_id != 0
+          render :nothing => true, :status => 400 # BAD REQUEST
+          return
+        end
+
+        tags = []
+
+        pt.elements.each('tag') do |tag|
+          tags << [tag.attributes['k'],tag.attributes['v']]
+        end
+        tags = tags.collect { |k,v| "#{k}=#{v}" }.join(';')
+        tags = '' if tags.nil?
+
+        now = Time.now
+
+        node = Node.new
+        node.latitude = lat
+        node.longitude = lon
+        node.visible = 1
+        node.tags = tags
+        node.timestamp = now
+        node.user_id = @user.id
+
+        #FIXME add a node to the old nodes table too
+
+        if node.save
+          render :text => node.id
+        else
+          render :nothing => true, :status => 500
+        end
+      end
     end
+
+        render :text => 'WRONG!           '
+        return
+
   end
 
+  def rest
+    unless Node.exists?(params[:id])
+      render :nothing => true, :status => 400
+      return
+    end
+
+    node = Node.find(params[:id])
+
+
+    case request.method
+    when :get
+      doc = XML::Document.new
+
+      # this needs a new libxml:
+      # doc.encoding = "UTF-8"  
+
+      root = XML::Node.new 'osm'
+      root['version'] = '0.4'
+      root['generator'] = 'OpenStreetMap server'
+      doc.root = root
+      el1 = XML::Node.new 'node'
+      el1['id'] = node.id.to_s
+      el1['lat'] = node.latitude.to_s
+      el1['lon'] = node.longitude.to_s
+      split_tags(el1, node.tags)
+      el1['visible'] = node.visible.to_s
+      el1['timestamp'] = node.timestamp.xmlschema
+      root << el1
+
+      render :text => doc.to_s
+
+      #
+      # DELETE
+      #
+    when :delete
+
+      if node.visible
+        node.visible = 0
+        node.save
+      else
+        render :nothing => true, :status => 410
+      end
+
+      #
+      # PUT
+      #
+    when :put
+
+      doc = XML::Document.new(request.raw_post)
+      doc.elements.each('osm/node') do |pt|
+        lat = pt.attributes['lat'].to_f
+        lon = pt.attributes['lon'].to_f
+        node_id = pt.attributes['id'].to_i
+
+        if lat > 90 or lat < -90 or lon > 180 or lon < -180  or node_id != params[:id]
+          render :nothing => true, :status => 400 # BAD REQUEST
+          return
+        end
+
+        tags = []
+
+        pt.elements.each('tag') do |tag|
+          tags << [tag.attributes['k'],tag.attributes['v']]
+        end
+        tags = tags.collect { |k,v| "#{k}=#{v}" }.join(';')
+        tags = '' if tags.nil?
+
+        now = Time.now
+
+        node.latitude = lat
+        node.longitude = lon
+        node.visible = 1
+        node.tags = tags
+        node.timestamp = now
+        node.user_id = @user.id
+
+        #FIXME add a node to the old nodes table too
+
+        if node.save
+          render :text => node.id
+        else
+          render :nothing => true, :status => 500
+        end
+      end
+    end
+  end
+
+
   def dummy
     if request.post?
       userid = dao.useridfromcreds(r.user, r.get_basic_auth_pw)
@@ -66,7 +191,7 @@ class NodeController < ApplicationController
   end
 
 
-  def rest
+  def dummydummy
 
     #
     # POST ???
@@ -127,13 +252,13 @@ class NodeController < ApplicationController
 
     if request.get?
       node = node.find(params[:id])
-      doc = Document.new
-      doc.encoding = "UTF-8"
-      root = Node.new 'osm'
+      doc = document.new
+      doc.encoding = "utf-8"
+      root = node.new 'osm'
       root['version'] = '0.4'
-      root['generator'] = 'OpenStreetMap server'
+      root['generator'] = 'openstreetmap server'
       doc.root = root
-      el1 = Node.new 'node'
+      el1 = node.new 'node'
       el1['id'] = node.id.to_s
       el1['lat'] = node.latitude.to_s
       el1['lon'] = node.longitude.to_s
index b982a93c9863f094185983e067a9abd8b22d70c2..3012765d2a24732b85b4d01c5e379f49b3f3fb1d 100644 (file)
@@ -11,7 +11,6 @@ class UserController < ApplicationController
     else
       render :action => 'new'
     end
-
   end
 
   def new
index 1a12790420a899473de6c4c56fc890a0874e0fd5..589546e2d6c97c05e11a366ec0621e2aa50fcf68 100644 (file)
@@ -25,9 +25,7 @@ class User < ActiveRecord::Base
   end 
 
   def self.authenticate(email, passwd) 
-    find_first([ "email = ? AND pass_crypt =?", 
-               email, 
-               Digest::MD5.hexdigest(passwd) ]) 
+    find_first([ "email = ? AND pass_crypt =?", email, Digest::MD5.hexdigest(passwd) ])
   end 
   
   private
index 828e0f40d368a19c4cac6129cf7eba458a904a4d..4b87400b44c69ffbac2d2fad6eb20d1c455c4695 100644 (file)
@@ -1,15 +1,15 @@
 ActionController::Routing::Routes.draw do |map|
-  map.connect ':controller/service.wsdl', :action => 'wsdl'
+#  map.connect ':controller/service.wsdl', :action => 'wsdl'
 
+  map.connect 'api/0.4/node/create', :controller => 'node', :action => 'create'
+  map.connect 'api/0.4/node/:id', :controller => 'node', :action => 'rest', :id => nil
 
-  map.connect '/api/0.4/node/:id', :controller => 'node', :action => 'rest'
-  map.connect '/api/0.4/node/create', :controller => 'node', :action => 'create'
  
-  map.connect '/api/0.4/segment/:id', :controller => 'segment', :action => 'rest'
-  map.connect '/api/0.4/segment/create', :controller => 'segment', :action => 'create'
+#  map.connect 'api/0.4/segment/:id', :controller => 'segment', :action => 'rest'
+#  map.connect 'api/0.4/segment/create', :controller => 'segment', :action => 'create'
 
-  map.connect '/api/0.4/way/:id', :controller => 'way', :action => 'rest'
-  map.connect '/api/0.4/way/create', :controller => 'way', :action => 'create'
+#  map.connect 'api/0.4/way/:id', :controller => 'way', :action => 'rest'
+#  map.connect 'api/0.4/way/create', :controller => 'way', :action => 'create'
  
   map.connect ':controller/:action/:id'
 end
diff --git a/db/migrate.sql b/db/migrate.sql
new file mode 100644 (file)
index 0000000..83840d5
--- /dev/null
@@ -0,0 +1,7 @@
+drop table meta_nodes;
+alter table current_nodes modify tags text not null;
+alter table current_nodes modify id bigint(64) not null auto_increment;
+
+
+alter table nodes modify tags text not null;
+