docbrown/app/controllers/email_subscriptions_controller.rb
Mac Siri 84122959bf Update unsubscribed page's copy and css (#199)
* Update unsubscribed page's copy and css

* Create view spec for email_subscriptions/unsubscribe

* Update unsubscribed's page copy

* Prevent search-engine crawlers
2018-04-10 15:02:20 -07:00

26 lines
911 B
Ruby

class EmailSubscriptionsController < ApplicationController
def unsubscribe
verified_params = Rails.application.message_verifier(:unsubscribe).verify(params[:ut])
if verified_params[:expires_at] > Time.now
user = User.find(verified_params[:user_id])
user.update(verified_params[:email_type] => false)
@email_type = preferred_email_name(verified_params[:email_type])
else
not_found
end
rescue ActiveSupport::MessageVerifier::InvalidSignature
not_found
end
def preferred_email_name(given_email_type)
emails_type = {
email_digest_periodic: "DEV digest emails",
email_comment_notifications: "comment notifications",
email_follower_notifications: "follower notifications",
email_mention_notifications: "mention notifications",
email_unread_notifications: "unread notifications",
}
emails_type[given_email_type]
end
end