docbrown/app/controllers/email_subscriptions_controller.rb
Ben Halpern 6c71369df5
[deploy] Add community_name to site config (#9864)
* Add community_name to site config

* Fix a spec

* Remove SiteConfig from constants

* Change subjects to method

* Fix subjects method

* Fix linting
2020-08-19 14:54:40 -04:00

27 lines
1 KiB
Ruby

class EmailSubscriptionsController < ApplicationController
def unsubscribe
verified_params = Rails.application.message_verifier(:unsubscribe).verify(params[:ut])
if verified_params[:expires_at] > Time.current
user = User.find(verified_params[:user_id])
user.update(verified_params[:email_type] => false)
@email_type = preferred_email_name.fetch(verified_params[:email_type], "this list")
else
render "invalid_token"
end
rescue ActiveSupport::MessageVerifier::InvalidSignature
not_found
end
def preferred_email_name
{
email_digest_periodic: "#{SiteConfig.community_name} digest emails",
email_comment_notifications: "comment notifications",
email_follower_notifications: "follower notifications",
email_mention_notifications: "mention notifications",
email_connect_messages: "#{SiteConfig.community_name} connect messages",
email_unread_notifications: "unread notifications",
email_badge_notifications: "badge notifications"
}.freeze
end
end