docbrown/app/controllers/email_subscriptions_controller.rb
Anna Buianova 983c3d28dd
Replaced remaining hardcoded DEV with the configurable community name (#7435)
* Replaced hardcoded DEV and dev.to remainders with the configurable name
* Removed hardcoded dev.to from the rss feed
2020-04-22 17:16:21 +03:00

25 lines
1 KiB
Ruby

class EmailSubscriptionsController < ApplicationController
PREFERRED_EMAIL_NAME = {
email_digest_periodic: "#{ApplicationConfig['COMMUNITY_NAME']} digest emails",
email_comment_notifications: "comment notifications",
email_follower_notifications: "follower notifications",
email_mention_notifications: "mention notifications",
email_connect_messages: "#{ApplicationConfig['COMMUNITY_NAME']} connect messages",
email_unread_notifications: "unread notifications",
email_badge_notifications: "badge notifications"
}.freeze
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
end