Orbit/lib/central_server_exchange_app.rb

49 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2011-08-18 05:43:33 +00:00
class CentralServerExchangeApp < Sinatra::Base
before do
@site = Site.first
end
post "/site/set_registered" do
begin
private_key = OpenSSL::PKey::RSA.new(@site.private_key)
roaming_id = private_key.private_decrypt(request.params['roaming_id'])
@site.update_attributes(:roaming_id => roaming_id)
body 'true'
rescue
body 'false'
end
end
get '/site/public_key' do
begin
if @site.public_key.nil?
@site.generate_keys
@site.save
end
body @site.public_key
rescue
body 'false'
end
end
post '/purchase/:type' do
2011-08-18 05:43:33 +00:00
begin
private_key = OpenSSL::PKey::RSA.new(@site.private_key)
case params[:type]
when 'Design'
purchase = PDesign.new.from_json(private_key.private_decrypt(request.params['purchase']))
2011-11-19 06:33:26 +00:00
when 'ModuleApp'
purchase = PModuleApp.new.from_json(private_key.private_decrypt(request.params['purchase']))
end
purchase.save
2011-08-18 05:43:33 +00:00
body 'true'
rescue
body 'false'
end
end
end