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.194 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.193 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.192 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.191 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.190 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.189 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.188 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.187 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.185 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.184 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.183 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.182 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.181 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.180 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.178 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.177 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.176 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.175 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.174 app/controllers/ishapi/sites_controller.rb
ishapi-0.1.8.173 app/controllers/ishapi/sites_controller.rb