Changes for purchases - handle different type of purchases
This commit is contained in:
		
							parent
							
								
									d9d7099da6
								
							
						
					
					
						commit
						c1d77fa6d6
					
				| 
						 | 
					@ -20,12 +20,13 @@ class Admin::PurchasesController < ApplicationController
 | 
				
			||||||
  protected
 | 
					  protected
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  def download_purchase(purchase, url)
 | 
					  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)
 | 
					    http = Net::HTTP.new(uri.host, uri.port)
 | 
				
			||||||
    request = Net::HTTP::Post.new(uri.request_uri)
 | 
					    request = Net::HTTP::Post.new(uri.request_uri)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    public_key = OpenSSL::PKey::RSA.new(File.read(APP_CONFIG['main_public_key']))
 | 
					    public_key = OpenSSL::PKey::RSA.new(File.read(APP_CONFIG['main_public_key']))
 | 
				
			||||||
    encrypted_data = public_key.public_encrypt({:purchase_id => purchase.purchase_id,
 | 
					    encrypted_data = public_key.public_encrypt({:purchase_id => purchase.purchase_id,
 | 
				
			||||||
 | 
					                                                :purchase_type => purchase._type,
 | 
				
			||||||
                                                :roaming_id => Site.find(session[:site]).roaming_id,
 | 
					                                                :roaming_id => Site.find(session[:site]).roaming_id,
 | 
				
			||||||
                                                :url => url}.to_json)
 | 
					                                                :url => url}.to_json)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,5 +7,6 @@ class Purchase
 | 
				
			||||||
  field :author
 | 
					  field :author
 | 
				
			||||||
  field :intro
 | 
					  field :intro
 | 
				
			||||||
  field :downloaded, :type => Boolean
 | 
					  field :downloaded, :type => Boolean
 | 
				
			||||||
 | 
					  field :download_date, :type => Date
 | 
				
			||||||
 | 
					
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ PrototypeR4::Application.routes.draw do
 | 
				
			||||||
  match '/site/set_registered', :to => CentralServerExchangeApp  
 | 
					  match '/site/set_registered', :to => CentralServerExchangeApp  
 | 
				
			||||||
  match '/site/public_key', :to => CentralServerExchangeApp 
 | 
					  match '/site/public_key', :to => CentralServerExchangeApp 
 | 
				
			||||||
  match '/site/update', :to => GithubApp
 | 
					  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]}" }
 | 
					  match "/panel/:app_name/frontend/:action" => redirect {|params| "/panel/#{params[:app_name]}/#{params[:action]}" }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,11 +28,16 @@ class CentralServerExchangeApp < Sinatra::Base
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  post '/purchase/design' do
 | 
					  post '/purchase/:type' do
 | 
				
			||||||
    begin
 | 
					    begin
 | 
				
			||||||
      private_key = OpenSSL::PKey::RSA.new(@site.private_key)
 | 
					      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'
 | 
					      body 'true'
 | 
				
			||||||
    rescue
 | 
					    rescue
 | 
				
			||||||
      body 'false'
 | 
					      body 'false'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in New Issue