Sha256: 227b6c73fbf21ef313b3c550ec19074737b20ba714b575422e2bcbec4da71733

Contents?: true

Size: 1.72 KB

Versions: 13

Compression:

Stored size: 1.72 KB

Contents

module Caboose
  class MyAccountLineItemsController < Caboose::ApplicationController
            
    # GET /my-account/orders/:order_id/line-items
    def index
      return if !logged_in?      
      @order = Order.find(params[:order_id])
      if @order.customer_id != logged_in_user.id
        @error = "The given order does not belong to you."
        render :file => 'caboose/extras/error'
        return
      end
    end
      
    # GET /my-account/orders/:order_id/line-items/:id
    def edit
      return if !logged_in?
      
      @order = Order.find(params[:order_id])
      @line_item = LineItem.find(params[:id])
      if @order.customer_id != logged_in_user.id
        @error = "The given order does not belong to you."
        render :file => 'caboose/extras/error'
        return
      end      
    end
    
    # GET /my-account/orders/:order_id/line-items/:id/download
    def download
      return if !logged_in?
      
      order = Order.find(params[:order_id])      
      if order.customer_id != logged_in_user.id
        @error = "The given order does not belong to you."
        render :file => 'caboose/extras/error'
        return
      end

      li = LineItem.find(params[:id])
      if !li.variant.downloadable
        render :text => "Not a downloadable file."
        return
      end
      
      # Generate the download URL and redirect to it
      sc = @site.store_config
      config = YAML.load_file("#{::Rails.root}/config/aws.yml")        
      bucket = AWS::S3::Bucket.new(config[Rails.env]['bucket'])
      s3object = AWS::S3::S3Object.new(bucket, li.variant.download_path)
      url = s3object.url_for(:read, :expires => sc.download_url_expires_in.minutes).to_s

      redirect_to url
    end
             
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
caboose-cms-0.5.132 app/controllers/caboose/my_account_line_items_controller.rb
caboose-cms-0.5.131 app/controllers/caboose/my_account_line_items_controller.rb
caboose-cms-0.5.130 app/controllers/caboose/my_account_line_items_controller.rb
caboose-cms-0.5.129 app/controllers/caboose/my_account_line_items_controller.rb
caboose-cms-0.5.128 app/controllers/caboose/my_account_line_items_controller.rb
caboose-cms-0.5.127 app/controllers/caboose/my_account_line_items_controller.rb
caboose-cms-0.5.126 app/controllers/caboose/my_account_line_items_controller.rb
caboose-cms-0.5.125 app/controllers/caboose/my_account_line_items_controller.rb
caboose-cms-0.5.124 app/controllers/caboose/my_account_line_items_controller.rb
caboose-cms-0.5.123 app/controllers/caboose/my_account_line_items_controller.rb
caboose-cms-0.5.122 app/controllers/caboose/my_account_line_items_controller.rb
caboose-cms-0.5.121 app/controllers/caboose/my_account_line_items_controller.rb
caboose-cms-0.5.120 app/controllers/caboose/my_account_line_items_controller.rb