-
-
Save mankind/997044 to your computer and use it in GitHub Desktop.
non guessable url with md5 generator
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
message.reply_url = messages_url(message_thread.md5hash) |
This file contains hidden or 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
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