diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cd18e4c..239942a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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_" diff --git a/app/controllers/threadreplies_controller.rb b/app/controllers/threadreplies_controller.rb index 8b08bf3..1709d0c 100644 --- a/app/controllers/threadreplies_controller.rb +++ b/app/controllers/threadreplies_controller.rb @@ -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." diff --git a/app/mailers/redstoner_mailer.rb b/app/mailers/redstoner_mailer.rb index c92fec3..e945a4d 100644 --- a/app/mailers/redstoner_mailer.rb +++ b/app/mailers/redstoner_mailer.rb @@ -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 \ No newline at end of file diff --git a/app/models/threadreply.rb b/app/models/threadreply.rb index ea874f1..a6b4633 100644 --- a/app/models/threadreply.rb +++ b/app/models/threadreply.rb @@ -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 \ No newline at end of file diff --git a/app/views/redstoner_mailer/register_mail.html.erb b/app/views/redstoner_mailer/register_mail.html.erb index 2f0438b..ba5c2ca 100644 --- a/app/views/redstoner_mailer/register_mail.html.erb +++ b/app/views/redstoner_mailer/register_mail.html.erb @@ -34,7 +34,7 @@
If you did not sign up on redstoner.com you can safely ignore this email!
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;" %> diff --git a/app/views/redstoner_mailer/thread_reply_mail.html.erb b/app/views/redstoner_mailer/thread_reply_mail.html.erb new file mode 100644 index 0000000..7d77707 --- /dev/null +++ b/app/views/redstoner_mailer/thread_reply_mail.html.erb @@ -0,0 +1,29 @@ +
<%= 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!
+ ++ <%# TODO: fix relative links + iframes %> + <%= render_md(@reply.content).html_safe %> ++ +
<%= link_to "Click here", forumthread_path(@reply, only_path: false) + "##{@reply.id}", style: "text-decoration: none; color: #4096EE;" %> to view the thread.
+ +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!
+Your Redstoner team
+ +You cannot (yet) unsubscribe from these mails, sorry about that. Will add this ASAP! +
+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;" %> +
+