Class: Decidim::NewslettersController
- Inherits:
-
ApplicationController
- Object
- DecidimController
- ApplicationController
- Decidim::NewslettersController
- Includes:
- NewslettersHelper
- Defined in:
- decidim-core/app/controllers/decidim/newsletters_controller.rb
Overview
The controller to show the newsletter on the website.
Instance Method Summary collapse
Methods included from NewslettersHelper
#custom_url_for_mail_root, #parse_interpolations
Methods inherited from ApplicationController
Methods included from UserBlockedChecker
#check_user_block_status, #check_user_not_blocked
Methods included from NeedsSnippets
Methods included from Headers::HttpCachingDisabler
Methods included from HasStoredPath
#skip_store_location?, #store_current_location
Methods included from TranslatableAttributes
Methods included from RegistersPermissions
Methods included from NeedsOrganization
enhance_controller, extended, included
Instance Method Details
#newsletter ⇒ Object
46 47 48 |
# File 'decidim-core/app/controllers/decidim/newsletters_controller.rb', line 46 def @newsletter ||= collection.find(params[:id]) end |
#show ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'decidim-core/app/controllers/decidim/newsletters_controller.rb', line 13 def show @user = current_user @organization = current_organization raise ActionController::RoutingError, "Not Found" unless .sent? @encrypted_token = Decidim::NewsletterEncryptor.sent_at_encrypted(@user.id, .sent_at) if @user.present? end |
#unsubscribe ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'decidim-core/app/controllers/decidim/newsletters_controller.rb', line 22 def unsubscribe encryptor = Decidim::NewsletterEncryptor decrypted_string = encryptor.sent_at_decrypted(params[:u]) user = User.find_by(decidim_organization_id: current_organization.id, id: decrypted_string.split("-").first) sent_at_time = Time.zone.at(decrypted_string.split("-").second.to_i) if sent_at_time > (15.days.ago) UnsubscribeSettings.call(user) do on(:ok) do flash.now[:notice] = t("newsletters.unsubscribe.success", scope: "decidim") end on(:invalid) do flash.now[:alert] = t("newsletters.unsubscribe.error", scope: "decidim") render action: :unsubscribe end end else flash.now[:alert] = t("newsletters.unsubscribe.token_error", scope: "decidim") render action: :unsubscribe end end |