thread reply emails! also a few mail bugfixes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
protect_from_forgery
|
||||
before_filter :update_ip, :update_seen, :check_banned
|
||||
# force_ssl
|
||||
# TODO: force_ssl
|
||||
|
||||
http_basic_authenticate_with name: "redstone", password: "sheep_"
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class ThreadrepliesController < ApplicationController
|
||||
@reply.user_author = current_user
|
||||
@reply.forumthread = thread
|
||||
if @reply.save
|
||||
@reply.send_new_reply_mail
|
||||
redirect_to forumthread_path(@reply.thread) + "#reply-#{@reply.id}", notice: 'Reply created!'
|
||||
else
|
||||
flash[:alert] = "Could not create reply."
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class RedstonerMailer < ActionMailer::Base
|
||||
|
||||
add_template_helper(ApplicationHelper)
|
||||
default from: "info@redstoner.com"
|
||||
default reply_to: "redstonerserver+website@gmail.com"
|
||||
|
||||
@@ -14,4 +15,10 @@ class RedstonerMailer < ActionMailer::Base
|
||||
@mcpw = uses_mc_pass
|
||||
mail(to: "redstonerserver@gmail.com", subject: "#{@user.name} registered on Redstoner.com", from: "info@redstoner.com", reply_to: "redstonerserver+website@gmail.com")
|
||||
end
|
||||
|
||||
def thread_reply_mail(user, reply)
|
||||
@user = user
|
||||
@reply = reply
|
||||
mail(to: @user.email, subject: "#{reply.author.name} replied to '#{reply.thread.title}' on Redstoner", from: "info@redstoner", reply_to: "redstonerserver+website@gmail")
|
||||
end
|
||||
end
|
||||
@@ -28,4 +28,29 @@ class Threadreply < ActiveRecord::Base
|
||||
def edited?
|
||||
!!user_editor_id
|
||||
end
|
||||
|
||||
def send_new_reply_mail
|
||||
userids = []
|
||||
|
||||
# thread + replies
|
||||
(thread.replies.to_a << thread).each do |post|
|
||||
# don't send mail to the user who wrote this
|
||||
if post.author != author # && user.send_threadreply_mail (TODO)
|
||||
userids << post.author.id
|
||||
end
|
||||
end
|
||||
# making sure we don't send multiple mails to the same user
|
||||
userids.uniq!
|
||||
|
||||
userids.each do |uid|
|
||||
begin
|
||||
RedstonerMailer.thread_reply_mail(User.find(uid), self).deliver
|
||||
rescue => e
|
||||
puts "---"
|
||||
puts "WARNING: registration mail failed for user #{@user.name}, #{@user.email}"
|
||||
puts e.message
|
||||
puts "---"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -34,7 +34,7 @@
|
||||
<p><i>If you did not sign up on redstoner.com you can safely ignore this email!</i>
|
||||
</p>
|
||||
<p>You can contact us via:
|
||||
<%= link_to "Website", "root_path", style: "text-decoration: none; color: #4096EE;" %> |
|
||||
<%= link_to "Website", root_path(only_path: false), style: "text-decoration: none; color: #4096EE;" %> |
|
||||
<%= link_to "Twitter", "https://twitter.com/RedstonerServer", style: "text-decoration: none; color: #4096EE;" %> |
|
||||
<%= link_to "Google+", "https://google.com/+Redstoner", style: "text-decoration: none; color: #4096EE;" %> |
|
||||
<%= link_to "Email", "mailto:redstonerserver+website@gmail.com", style: "text-decoration: none; color: #4096EE;" %>
|
||||
|
||||
29
app/views/redstoner_mailer/thread_reply_mail.html.erb
Normal file
29
app/views/redstoner_mailer/thread_reply_mail.html.erb
Normal file
@@ -0,0 +1,29 @@
|
||||
<div style="font-family: 'Oswald','Calibri','Arial','DejaVu Sans','Open Sans','Lucida Sans','Lucida Grande','Lucida Sans Unicode',sans-serif; background: #F2F2F2">
|
||||
<div style="color: #3f3f3f; width: 600px; max-width: 100%; padding: 2em; margin: auto;">
|
||||
Hi <%= @user.name %>!
|
||||
|
||||
<p><%= link_to @reply.author.name, user_path(@reply.author, only_path: false), style: "text-decoration: none; color: #4096EE;" %> has replied to '<%= @reply.thread.title %>' on the Redstoner forums!</p>
|
||||
|
||||
<blockquote>
|
||||
<%# TODO: fix relative links + iframes %>
|
||||
<%= render_md(@reply.content).html_safe %>
|
||||
</blockquote>
|
||||
|
||||
<p><%= link_to "Click here", forumthread_path(@reply, only_path: false) + "##{@reply.id}", style: "text-decoration: none; color: #4096EE;" %> to view the thread.</p>
|
||||
|
||||
<p>If you have any questions or problems, just ask one of our <%= link_to "Staff", users_path(role: "staff", only_path: false), style: "text-decoration: none; color: #4096EE;" %> in-game or on the forums!</p>
|
||||
<p>Your Redstoner team</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div style="background: #444; width: 100%; padding: 2em; color: #fff; margin: auto; text-align: center;">
|
||||
<p><i>You cannot (yet) unsubscribe from these mails, sorry about that. Will add this ASAP!</i>
|
||||
</p>
|
||||
<p>You can contact us via:
|
||||
<%= link_to "Website", root_path(only_path: false), style: "text-decoration: none; color: #4096EE;" %> |
|
||||
<%= link_to "Twitter", "https://twitter.com/RedstonerServer", style: "text-decoration: none; color: #4096EE;" %> |
|
||||
<%= link_to "Google+", "https://google.com/+Redstoner", style: "text-decoration: none; color: #4096EE;" %> |
|
||||
<%= link_to "Email", "mailto:redstonerserver+website@gmail.com", style: "text-decoration: none; color: #4096EE;" %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -16,4 +16,11 @@ class RegistrationPreview < ActionMailer::Preview
|
||||
def register_info_mail_idiot
|
||||
RedstonerMailer.register_info_mail(@@user, true)
|
||||
end
|
||||
|
||||
def thread_reply_mail
|
||||
op = User.new(id: 32, name: "TheOP", email: "theopuser@example.com")
|
||||
thread = Forumthread.new(id: 123, user_author: op, title: "Wow, test thread!", content: "You should not see this...")
|
||||
reply = Threadreply.new(id: 312, user_author: @@user, content: "# Markdown!\n\n`incline code`\n\n<b>html?</b>\n\n[yt:abcd1234]\n\n[link](/forums)", forumthread: thread)
|
||||
RedstonerMailer.thread_reply_mail(@@user, reply)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user