2011-10-18 14:47:17 +01:00
|
|
|
class PrivatesController < ApplicationController
|
|
|
|
require 'digest/sha2'
|
|
|
|
|
2011-10-24 14:01:15 +01:00
|
|
|
before_filter :authenticate_user!
|
2011-10-18 14:47:17 +01:00
|
|
|
before_filter :find_platform
|
2011-10-24 14:01:15 +01:00
|
|
|
|
2011-10-18 14:47:17 +01:00
|
|
|
before_filter :authenticate
|
|
|
|
|
|
|
|
def show
|
2011-10-27 14:04:03 +01:00
|
|
|
file_name = "#{APP_CONFIG['root_path']}/platforms/#{params[:platform_name]}/repository/#{params[:file_path]}"
|
2011-10-18 14:47:17 +01:00
|
|
|
|
|
|
|
if File.directory?(file_name) || !File.exists?(file_name)
|
|
|
|
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
|
|
|
|
else
|
|
|
|
send_file file_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def authenticate
|
|
|
|
authenticate_or_request_with_http_basic do |username, password|
|
|
|
|
PrivateUser.exists?(
|
|
|
|
:login => username,
|
|
|
|
:password => Digest::SHA2.new.hexdigest(password),
|
|
|
|
:platform_id => @platform.try(:id)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_platform
|
|
|
|
@platform = Platform.find_by_name(params[:platform_name])
|
|
|
|
end
|
|
|
|
end
|