docbrown/app/controllers/email_subscriptions_controller.rb
Andy Zhao cd9f6d9ada [Done] Add BDEFGI Policies and Specs (#487)
* Add comment for public controllers

* Add block policy and specs

* Add policy for authorizing dashboard

* Add follow policy and specs

* Refactor a tiny bit

* Prevent banned users from following anything

* Add a note for email sub controller about auth

* Add image upload policies

* Add policy for github repos

* Fix typo and use correct github repo variable

* Fix image uploader and use regular params

* Add authenticate_user before action back in

* Rename test

* Update slack bot message formatting and fix reported URL
2018-06-26 09:23:07 -04:00

27 lines
990 B
Ruby

class EmailSubscriptionsController < ApplicationController
# No need to authorize this because its implicit when unsubbing
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
render "invalid_token"
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