Sha256: 28bbbb55412337a9abb8eab72e0ec82c32e48321941dde473e06d063fac5f687

Contents?: true

Size: 1.63 KB

Versions: 47

Compression:

Stored size: 1.63 KB

Contents

require_dependency "ishapi/application_controller"

module Ishapi
  class SitesController < ApplicationController

    before_action :check_profile, only: %i| show |

    def index
      authorize! :index, ::Site
      @sites = ::Site.all
    end

    def show
      if params[:domain].include?(".json")
        domain = params[:domain][0...-5]
      else
        domain = params[:domain]
      end
      @site = ::Site.find_by(domain: domain, lang: :en)
      authorize! :show, @site

      if @site.is_private
        if !params[:accessToken]
          render :json => { :status => :unauthorized}, :status => :unauthorized
          return
        end
        access_token = params[:accessToken]
        @graph = Koala::Facebook::API.new( access_token, ::FB[@site.domain][:secret] )
        @profile = @graph.get_object "me", :fields => 'email'
        if @site.private_user_emails.include?( @profile['email'] )
          ;
        else
          render :json => { :status => :unauthorized}, :status => :unauthorized
          render :status => :unauthorized
          return
        end
      end

      @galleries    = @site.galleries.limit( 10 ) # @TODO: paginate
      @newsitems    = @site.newsitems.limit( @site.newsitems_per_page ) # @TODO: paginate
      @reports      = @site.reports.limit( 10 ) # @TODO: paginate
      @langs        = ::Site.where( :domain => domain ).map( &:lang )
      @feature_tags = @site.tags.where( :is_feature => true )
    end

    private

    # # jwt
    # def decode(token)
    #   decoded = JWT.decode(token, Rails.application.secrets.secret_key_base.to_s)[0]
    #   HashWithIndifferentAccess.new decoded
    # end

  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
ishapi-0.1.8.149 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.148 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.147 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.146 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.145 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.144 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.143 app/controllers/ishapi/sites_controller.rb