diff --git a/sinatra/server.rb b/sinatra/server.rb index e61570f..3799eee 100755 --- a/sinatra/server.rb +++ b/sinatra/server.rb @@ -21,7 +21,10 @@ end post '/login' do - sessions[Guid.new()] = Session.new(params[:user]) + return '{error: "no username given"}' unless params[:user] + guid = (Guid.new()).to_s() + sessions[guid] = Session.new(params[:user]) + return {'guid' => guid}.to_json() end post '/announce' do @@ -29,7 +32,9 @@ if sessions[session] then room_by_user[session.user] = params[:room] session.reset_timeout() + return true; end + '{error: "invalid session"}' end get '/users' do @@ -50,7 +55,7 @@ #session purge logic: clears the session cache from stale sessions def purge_sessions () - ref = now() + ref = Time.now() sessions.delete_if {|session| if session.timeout()+60*SESSION_TIMEOUT < ref then users_by_room[room_by_user[session.user]].delete(session.user) diff --git a/sinatra/session.rb b/sinatra/session.rb index fd4d68a..4bba4ef 100644 --- a/sinatra/session.rb +++ b/sinatra/session.rb @@ -1,11 +1,11 @@ class Session def initialize (user) @user = user - @timeout = now() + @timeout = Time.now() end def reset_timeout () - @timeout = now() + @timeout = Time.now() end def timeout () diff --git a/sinatra/static/index.html b/sinatra/static/index.html index e84320b..15690d3 100644 --- a/sinatra/static/index.html +++ b/sinatra/static/index.html @@ -12,30 +12,84 @@
-
-
-

Indoor Positioning System Demo Announce Server ©®™

-
-
-

User list

-
-
-

Radar

+
+
+
+

Indoor Positioning System Demo Announce Server ©™®

+
+
+

User list

+
+
+

Radar

+
+
+

Testing

+
+ +
+
+ +
+
+