[code=ruby]# encoding: utf-8
class ApplicationController < ActionController::Base
#protect_from_forgery
protect_from_forgery
skip_before_filter :verify_authenticity_token, :only => [:parse_signed_request]
def chech_isset_app_on_page
redirect_to app_list_path unless params[:app_id] != nil && App.where([“block = ? AND active = ? AND page_id IN (?)”,
0, 1, Fanpage.where(:uid => session[‘page_id’]).pluck(:id)]).count > 0
end
def parse_signed_request
signed_request = Facebook::SignedRequest.new( params[:signed_request].to_s, secret: SECRET )
#session[‘signed_request’] = signed_request.data
#TODO aktualizujemy tabele user
if params[:signed_request]
::Rails.logger.info('Rozpoczynam parsowanie signed_request dla IP: '+request.remote_ip)
::Rails.logger.info('Signed_request przekazany z FB dla IP: '+params[:signed_request].to_s)
::Rails.logger.info('Sparsowane dane z signed_request dla IP: '+signed_request.data.inspect)
if !session['user_id']
session['user_id'] = signed_request.data[:user_id]
session['user_id_app'] = User.where("uid = '"+signed_request.data[:user_id]+"'")[0].id if User.where(:uid => signed_request.data[:user_id]).count > 0
::Rails.logger.info('Zapisano informacje (user) dla IP: '+request.remote_ip+' session: '+session.inspect+' signed_request '+signed_request.data[:user_id].inspect)
end
if !session['oauth_token']
session['oauth_token'] = signed_request.data[:oauth_token]
end
if !session['page_id']
session['page_id'] = signed_request.data[:page][:id]
session['page_id_app'] =Fanpage.find_by_uid(signed_request.data[:page][:id]).id
::Rails.logger.info('Zapisano informacje (page) dla IP: '+request.remote_ip+' session: '+session.inspect+' signed_request '+signed_request.data[:page].inspect)
end
end
end
end[/code]