Sha256: ad4fdbdecb6b4e0d7024b8b1bd8fc8116cacde9bd10b17821ab473323dd4cbc6

Contents?: true

Size: 847 Bytes

Versions: 7

Compression:

Stored size: 847 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.unathorized", scope: "decidim")
        redirect_to decidim.root_path(host: current_organization)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-core-0.28.4 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.28.3 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.28.2 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.28.1 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.28.0 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.28.0.rc5 app/controllers/decidim/newsletters_opt_in_controller.rb
decidim-core-0.28.0.rc4 app/controllers/decidim/newsletters_opt_in_controller.rb