1
0

mail_subscriptions_controller.rb 754 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # frozen_string_literal: true
  2. class MailSubscriptionsController < ApplicationController
  3. layout 'auth'
  4. skip_before_action :require_functional!
  5. before_action :set_user
  6. before_action :set_type
  7. protect_from_forgery with: :null_session
  8. def show; end
  9. def create
  10. @user.settings[email_type_from_param] = false
  11. @user.save!
  12. end
  13. private
  14. def set_user
  15. @user = GlobalID::Locator.locate_signed(params[:token], for: 'unsubscribe')
  16. not_found unless @user
  17. end
  18. def set_type
  19. @type = email_type_from_param
  20. end
  21. def email_type_from_param
  22. case params[:type]
  23. when 'follow', 'reblog', 'favourite', 'mention', 'follow_request'
  24. "notification_emails.#{params[:type]}"
  25. else
  26. not_found
  27. end
  28. end
  29. end