1
0
Fork 0
oldhaven/app/controllers/application_controller.rb

58 lines
1.4 KiB
Ruby

require 'digest'
require 'vkontakte'
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_locale
def cache_for time
response.headers['Cache-Control'] = 'public, max-age=' + time.seconds.to_s
end
def compile_page params
@data = params[:data] unless params[:data].nil?
@status = params[:status] unless params[:status].nil?
render json: {
renderer: "unified",
data: @data,
html: render_compact_partial(params[:partial]),
title: params[:title],
status: (params[:status] unless params[:status].nil?),
callback: (params[:callback] unless params[:callback].nil?)
}, include: (params[:include] unless params[:include].nil?)
end
def get_artist_name_from_query
params[:artist].gsub('%20', ' ').gsub('+', ' ').gsub('.html', '')
end
protected
def authorize
unless Vkontakte.check(params)
render json: { status: 'login failed' }, status: 403
end
end
def set_locale
session = Session.find_by_key(session_key)
unless session.nil?
I18n.locale = session.user.lang
end
end
def session_key
if cookies[:beathaven_sid].nil?
cookies[:beathaven_sid] = {
:value => Session.generate_key,
:expire => 42.years.from_now.utc
}
end
cookies[:beathaven_sid]
end
def render_compact_partial partial_name
(render_to_string :partial => partial_name.to_s).gsub(/\n(\s+)?/, '')
end
end