Merge branch 'master' of github.com:r888888888/danbooru
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
module Maintenance
|
||||||
|
module User
|
||||||
|
class EmailNotificationsController < ApplicationController
|
||||||
|
class VerificationError < Exception ; end
|
||||||
|
|
||||||
|
before_filter :validate_sig, :only => [:destroy]
|
||||||
|
rescue_from VerificationError, :with => :render_403
|
||||||
|
|
||||||
|
def show
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@user = User.find(params[:user_id])
|
||||||
|
@user.receive_email_notifications = false
|
||||||
|
@user.save
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def render_403
|
||||||
|
render :nothing => true, :status => 403
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_sig
|
||||||
|
digest = OpenSSL::Digest.new("sha256")
|
||||||
|
calc_sig = OpenSSL::HMAC.hexdigest(digest, Danbooru.config.email_key, params[:user_id].to_s)
|
||||||
|
if calc_sig != params[:sig]
|
||||||
|
raise VerificationError.new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,2 +1,6 @@
|
|||||||
module UsersHelper
|
module UsersHelper
|
||||||
|
def email_sig(user)
|
||||||
|
digest = OpenSSL::Digest.new("sha256")
|
||||||
|
OpenSSL::HMAC.hexdigest(digest, Danbooru.config.email_key, user.id.to_s)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class UserMailer < ActionMailer::Base
|
class UserMailer < ActionMailer::Base
|
||||||
add_template_helper ApplicationHelper
|
add_template_helper ApplicationHelper
|
||||||
|
add_template_helper UsersHelper
|
||||||
default :from => Danbooru.config.contact_email, :content_type => "text/html"
|
default :from => Danbooru.config.contact_email, :content_type => "text/html"
|
||||||
|
|
||||||
def dmail_notice(dmail)
|
def dmail_notice(dmail)
|
||||||
@@ -16,6 +17,7 @@ class UserMailer < ActionMailer::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def forum_notice(user, forum_topic, forum_posts)
|
def forum_notice(user, forum_topic, forum_posts)
|
||||||
|
@user = user
|
||||||
@forum_topic = forum_topic
|
@forum_topic = forum_topic
|
||||||
@forum_posts = forum_posts
|
@forum_posts = forum_posts
|
||||||
mail(:to => "#{user.name} <#{user.email}>", :subject => "#{Danbooru.config.app_name} forum topic #{forum_topic.title} updated")
|
mail(:to => "#{user.name} <#{user.email}>", :subject => "#{Danbooru.config.app_name} forum topic #{forum_topic.title} updated")
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
<p>You have been unsubscribed from all email notifications.</p>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<h1>Unsubscribe</h1>
|
||||||
|
|
||||||
|
<p>Do you wish to stop receiving all email notifications?</p>
|
||||||
|
|
||||||
|
<%= form_tag(maintenance_user_email_notification_path, :method => "delete") do %>
|
||||||
|
<%= hidden_field_tag "sig", params[:sig] %>
|
||||||
|
<%= hidden_field_tag "user_id", params[:user_id] %>
|
||||||
|
<%= submit_tag "Yes" %>
|
||||||
|
<% end %>
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
|
||||||
<%= stylesheet_link_tag "application", :media => "screen" %>
|
|
||||||
</head>
|
|
||||||
<body>
|
<body>
|
||||||
<p><%= h @dmail.from.name %> said:</p>
|
<p><%= h @dmail.from.name %> said:</p>
|
||||||
|
|
||||||
@@ -10,6 +7,6 @@
|
|||||||
<%= DText.parse(@dmail.body) %>
|
<%= DText.parse(@dmail.body) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p><%= link_to "View message", dmail_url(@dmail, :host => Danbooru.config.hostname, :only_path => false) %></p>
|
<p><%= link_to "View message", dmail_url(@dmail, :host => Danbooru.config.hostname, :only_path => false) %> | <%= link_to "Unsubscribe", maintenance_user_email_notification_url(:user_id => @dmail.owner.id, :sig => email_sig(@dmail.owner), :host => Danbooru.config.hostname, :only_path => false) %></p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -10,4 +10,4 @@
|
|||||||
<br>
|
<br>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<p><%= link_to "View topic", forum_topic_path(@forum_topic, :page => @forum_topic.last_page, :host => Danbooru.config.hostname, :only_path => false) %></p>
|
<p><%= link_to "View topic", forum_topic_path(@forum_topic, :page => @forum_topic.last_page, :host => Danbooru.config.hostname, :only_path => false) %> | <%= link_to "Unsubscribe", maintenance_user_email_notification_url(:user_id => @user.id, :sig => email_sig(@user), :host => Danbooru.config.hostname, :only_path => false) %></p>
|
||||||
|
|||||||
@@ -360,6 +360,10 @@ module Danbooru
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def email_key
|
||||||
|
"zDMSATq0W3hmA5p3rKTgD"
|
||||||
|
end
|
||||||
|
|
||||||
# For downloads, if the host matches any of these IPs, block it
|
# For downloads, if the host matches any of these IPs, block it
|
||||||
def banned_ip_for_download?(ip_addr)
|
def banned_ip_for_download?(ip_addr)
|
||||||
raise ArgumentError unless ip_addr.is_a?(IPAddr)
|
raise ArgumentError unless ip_addr.is_a?(IPAddr)
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
namespace :maintenance do
|
namespace :maintenance do
|
||||||
namespace :user do
|
namespace :user do
|
||||||
|
resource :email_notification, :only => [:show, :destroy]
|
||||||
resource :password_reset, :only => [:new, :create, :edit, :update]
|
resource :password_reset, :only => [:new, :create, :edit, :update]
|
||||||
resource :login_reminder, :only => [:new, :create]
|
resource :login_reminder, :only => [:new, :create]
|
||||||
resource :deletion, :only => [:show, :destroy]
|
resource :deletion, :only => [:show, :destroy]
|
||||||
|
|||||||
Reference in New Issue
Block a user