class AmfController < ApplicationController
require 'stringio'
+ session :off
before_filter :check_availability
# to log:
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
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