Sha256: 96d5f8ac6602b9fb4b00a30236394ac9888b3bef2bcdd8f4511480a0af3b8517

Contents?: true

Size: 848 Bytes

Versions: 10

Compression:

Stored size: 848 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # The controller to control newsletter Opt-in for GDPR
  class NewslettersOptInController < Decidim::ApplicationController
    include FormFactory

    before_action :check_current_user_with_token

    def update
      enforce_permission_to(:update, :user, current_user:)

      current_user.newsletter_opt_in_validate
      if current_user.save
        flash[:notice] = t(".success")
      else
        flash[:alert] = t(".error")
      end
      redirect_to decidim.root_path(host: current_organization)
    end

    private

    def check_current_user_with_token
      unless current_user.newsletter_token == params[:token]
        flash[:alert] = t("newsletters_opt_in.unauthorized", scope: "decidim")
        redirect_to decidim.root_path(host: current_organization)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
decidim-core-0.30.0.rc3 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.30.0.rc2 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.30.0.rc1 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.29.2 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.29.1 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.29.0 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.29.0.rc4 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.29.0.rc3 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.29.0.rc2 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.29.0.rc1 app/controllers/decidim/newsletters_opt_in_controller.rb