mail_subscriptions_controller.rb 848 B

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