Skip to content

Instantly share code, notes, and snippets.

@MichaelTorfs
Created May 28, 2011 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MichaelTorfs/996887 to your computer and use it in GitHub Desktop.
Save MichaelTorfs/996887 to your computer and use it in GitHub Desktop.
non guessable url with md5 generator
def md5hash
md5 = Digest::MD5.hexdigest(self.id.to_s + self.initial_sender_email + MD5_SECRET)
logger.info "DEBUG: md5 = " + md5
return self.id.to_s + "-" + md5
end
def check_md5(md5_to_check)
md5 = Digest::MD5.hexdigest(self.id.to_s + self.initial_sender_email + MD5_SECRET)
if md5 == md5_to_check
return true
else
return false
end
end
def show
if params[:md5].nil?
message_not_found
return
end
message_thread_array = params[:md5].split('-')
if message_thread_array.size != 2
message_not_found
return
end
@message_thread = MessageThread.with_data.find(message_thread_array[0],
:conditions => ['message_threads.type_id <> ?', MessageThread::CONTACT_TYPE],
:include => :messages) rescue nil
if @message_thread.nil?
message_not_found
return
end
unless @message_thread.check_md5(message_thread_array[1])
message_not_found
return
end
@message_thread.messages.each_with_index do |msg, index|
msg.opened_by_sender! if msg.opened_by_sender == nil
@message_thread.opened_by_sender!(msg.id) if index == (@message_thread.messages.size - 1)
end
@message = Message.new(:view_opened_time => DateTime.now.strftime("%Y-%m-%d %H:%M:%S %z"))
@onload = "$('#message_body').focus();"
end
message.reply_url = messages_url(message_thread.md5hash)
map.messages "messages/:md5", :controller => "messages", :action => "show",
:conditions => { :method => :get }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment