Sha256: 016f49c961298b97bcea18668d3345b233b80ed95fc9b51a8ba347ab35cb3ea9

Contents?: true

Size: 1.42 KB

Versions: 10

Compression:

Stored size: 1.42 KB

Contents

require_dependency "proclaim/application_controller"

module Proclaim
	class SubscriptionsController < ApplicationController
		after_action :verify_authorized, except: [:subscribed, :unsubscribed]
		before_action :set_subscription, only: [:unsubscribe, :destroy]

		def new
			@subscription = Subscription.new
			authorize @subscription
		end

		def subscribed
		end

		def unsubscribe
			authorize @subscription
		end

		def unsubscribed
		end

		def create
			@subscription = Subscription.new(subscription_params)

			authorize @subscription

			if antispam_params[:answer] == antispam_params[:solution]
				respond_to do |format|
					if @subscription.save
						format.html { redirect_to subscribed_path }
					else
						format.html { render :new }
					end
				end
			else
				@subscription.errors.add(:base, "Antispam question wasn't answered correctly")
				respond_to do |format|
					format.html { render :new }
				end
			end
		end

		def destroy
			authorize @subscription

			@subscription.destroy
			redirect_to unsubscribed_path, notice: "Successfully unsubscribed."
		end

		private

		def set_subscription
			@subscription = Subscription.from_token(params[:token])
		end

		# Only allow a trusted parameter "white list" through.
		def subscription_params
			params.require(:subscription).permit(:email)
		end

		def antispam_params
			params.require(:antispam).permit(:solution,
			                                 :answer)
		end
	end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
proclaim-0.3.1 app/controllers/proclaim/subscriptions_controller.rb
proclaim-0.3.0 app/controllers/proclaim/subscriptions_controller.rb
proclaim-0.2.4 app/controllers/proclaim/subscriptions_controller.rb
proclaim-0.2.2 app/controllers/proclaim/subscriptions_controller.rb
proclaim-0.2.1 app/controllers/proclaim/subscriptions_controller.rb
proclaim-0.2.0 app/controllers/proclaim/subscriptions_controller.rb
proclaim-0.1.3 app/controllers/proclaim/subscriptions_controller.rb
proclaim-0.1.2 app/controllers/proclaim/subscriptions_controller.rb
proclaim-0.1.1 app/controllers/proclaim/subscriptions_controller.rb
proclaim-0.1.0 app/controllers/proclaim/subscriptions_controller.rb