Created
June 20, 2011 18:33
-
-
Save revis0r/1036233 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DecryptJob < Struct.new(:bundle_id, :password) | |
def perform | |
bundle = Bundle.find(bundle_id) | |
begin | |
bundle.start_process! | |
bundle.decrypt_slots(password) | |
bundle.finish_process | |
bundle.remove_slot_afted_download = true | |
bundle.save | |
rescue OpenSSL::Cipher::CipherError | |
bundle.finish_process! | |
end | |
end | |
end | |
class EncryptJob < Struct.new(:bundle_id, :password) | |
def perform | |
bundle = Bundle.find(bundle_id) | |
begin | |
bundle.start_process! | |
bundle.crypt_slots(password) | |
bundle.finish_process! | |
rescue OpenSSL::Cipher::CipherError | |
bundle.finish_process! | |
end | |
end | |
end | |
# Bundles controller (create action) | |
# POST /bundles | |
# POST /bundles.xml | |
def create | |
@bundle = Bundle.new(params[:bundle]) | |
if not params[:bundle]['slots_attributes'].nil? | |
params[:bundle]['slots_attributes'].each do |k, v| | |
#logger.error "Slots #{v.join(', ')}" | |
@bundle.slots.new(v) | |
end | |
@password = params[:bundle][:password] | |
if @password.empty? | |
@bundle.finish_process | |
end | |
else | |
@bundle.slots.new | |
end | |
respond_to do |format| | |
if @bundle.save | |
if @password.present? | |
Delayed::Job.enqueue EncryptJob.new(@bundle.id.to_s, @password) | |
end | |
format.html { redirect_to(@bundle, :notice => 'Bundle was successfully created.') } | |
format.xml { render :xml => @bundle, :status => :created, :location => @bundle } | |
else | |
format.html { render :action => "new" } | |
format.xml { render :xml => @bundle.errors, :status => :unprocessable_entity } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment