Files
danbooru/app/controllers/emails_controller.rb
evazion b94cb7d824 emails: include logging information in email headers.
Log the following information in email headers:

* X-Danbooru-User: the user's name and ID.
* X-Danbooru-IP: the user's IP.
* X-Danbooru-Session: the users' session ID.
* X-Danbooru-URL: the page that triggered the email.
* X-Danbooru-Job-Id: the ID of the background job that sent the email.
* X-Danbooru-Enqueued-At: when the email was queued as a background job.
* X-Danbooru-Dmail: for Dmail notifications, the link to the Dmail.
* X-Request-Id: the request ID of the HTTP request that triggered the email.

Also make it so we log an event in the APM when we send an email.
2022-09-29 04:36:11 -05:00

67 lines
2.1 KiB
Ruby

# frozen_string_literal: true
class EmailsController < ApplicationController
before_action :requires_reauthentication, only: [:edit, :update]
respond_to :html, :xml, :json
rate_limit :update, rate: 1.0/1.minute, burst: 10
def index
@email_addresses = authorize EmailAddress.visible(CurrentUser.user).paginated_search(params, count_pages: true)
@email_addresses = @email_addresses.includes(:user)
respond_with(@email_addresses, model: "EmailAddress")
end
def show
if params[:user_id]
@email_address = authorize EmailAddress.find_by_user_id!(params[:user_id])
else
@email_address = authorize EmailAddress.find(params[:id])
end
respond_with(@email_address)
end
def edit
@user = authorize User.find(params[:user_id]), policy_class: EmailAddressPolicy
respond_with(@user)
end
def update
@user = authorize User.find(params[:user_id]), policy_class: EmailAddressPolicy
@user.change_email(params[:user][:email], request)
if @user.errors.none?
flash[:notice] = "Email updated. Check your email to confirm your new address"
respond_with(@user, location: settings_url)
else
flash[:notice] = @user.errors.full_messages.join("; ")
respond_with(@user)
end
end
def verify
@user = User.find(params[:user_id])
@email_address = @user.email_address
if @email_address.blank?
redirect_to edit_user_email_path(@user)
elsif params[:email_verification_key].present? && @email_address == EmailAddress.find_signed!(params[:email_verification_key], purpose: "verify")
@email_address.verify!
flash[:notice] = "Email address verified"
redirect_to @email_address.user
else
authorize @email_address
respond_with(@user)
end
end
def send_confirmation
@user = authorize User.find(params[:user_id]), policy_class: EmailAddressPolicy
UserMailer.with_request(request).welcome_user(@user).deliver_later
flash[:notice] = "Confirmation email sent to #{@user.email_address.address}. Check your email to confirm your address"
redirect_to @user
end
end