Sha256: fad29adfe341b2a9eaf8182bf55274faa773d4fa1524507e2b7efd4d3ca02240

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

Contents

module Feste
  module Authenticatable
    extend ActiveSupport::Concern

    included do
      if Feste.options[:authenticate_with] == :clearance
        include Feste::Authentication::Clearance
      elsif Feste.options[:authenticate_with] == :devise
        include Feste::Authentication::Devise
      elsif Feste.options[:authenticate_with].is_a?(Proc)
        include Feste::Authentication::Custom
      else
        include Feste::Authentication::DefaultInstanceMethods
      end

      before_action :get_user_data
    end

    def subscriber
      @_subscriber ||= Feste::Subscription.find_by(token: params[:token])&.subscriber ||
        current_user
    end

    def get_user_data
      if subscriber.present?
        find_or_create_subscriptions
      else
        render file: "#{Rails.root}/public/404.html",  status: 404
      end
    end

    def find_or_create_subscriptions
      Feste.options[:categories].each do |category|
        Feste::Subscription.find_or_create_by(
          subscriber: subscriber,
          category: category
        )
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
feste-0.4.2 app/controllers/concerns/feste/authenticatable.rb
feste-0.4.1 app/controllers/concerns/feste/authenticatable.rb
feste-0.4.0 app/controllers/concerns/feste/authenticatable.rb
feste-0.3.0 app/controllers/concerns/feste/authenticatable.rb
feste-0.2.1 app/controllers/concerns/feste/authenticatable.rb