diff --git a/app/controllers/admin/purchases_controller.rb b/app/controllers/admin/purchases_controller.rb index d8ffa0e2..e5357fbe 100644 --- a/app/controllers/admin/purchases_controller.rb +++ b/app/controllers/admin/purchases_controller.rb @@ -20,12 +20,13 @@ class Admin::PurchasesController < ApplicationController protected def download_purchase(purchase, url) - uri = URI.parse("http://#{APP_CONFIG['store_ip']}/download/design") + uri = URI.parse("http://#{APP_CONFIG['store_ip']}/download/purchase") http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri) public_key = OpenSSL::PKey::RSA.new(File.read(APP_CONFIG['main_public_key'])) encrypted_data = public_key.public_encrypt({:purchase_id => purchase.purchase_id, + :purchase_type => purchase._type, :roaming_id => Site.find(session[:site]).roaming_id, :url => url}.to_json) diff --git a/app/models/purchase/purchase.rb b/app/models/purchase/purchase.rb index cc52c2d5..a8a9bcfd 100644 --- a/app/models/purchase/purchase.rb +++ b/app/models/purchase/purchase.rb @@ -7,5 +7,6 @@ class Purchase field :author field :intro field :downloaded, :type => Boolean + field :download_date, :type => Date end diff --git a/config/routes.rb b/config/routes.rb index 0bb23607..2118919c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,7 +6,7 @@ PrototypeR4::Application.routes.draw do match '/site/set_registered', :to => CentralServerExchangeApp match '/site/public_key', :to => CentralServerExchangeApp match '/site/update', :to => GithubApp - match '/purchase/design', :to => CentralServerExchangeApp + match '/purchase/:type', :to => CentralServerExchangeApp match "/panel/:app_name/frontend/:action" => redirect {|params| "/panel/#{params[:app_name]}/#{params[:action]}" } diff --git a/lib/central_server_exchange_app.rb b/lib/central_server_exchange_app.rb index 6cb84b4d..536cd21f 100644 --- a/lib/central_server_exchange_app.rb +++ b/lib/central_server_exchange_app.rb @@ -28,11 +28,16 @@ class CentralServerExchangeApp < Sinatra::Base end end - post '/purchase/design' do + post '/purchase/:type' do begin private_key = OpenSSL::PKey::RSA.new(@site.private_key) - p_design = PDesign.new.from_json(private_key.private_decrypt(request.params['purchase'])) - p_design.save + + case params[:type] + when 'Design' + purchase = PDesign.new.from_json(private_key.private_decrypt(request.params['purchase'])) + end + + purchase.save body 'true' rescue body 'false'