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

58 lines
1.4 KiB
Ruby
Raw Normal View History

2011-06-22 00:55:09 +00:00
require 'digest'
2011-09-17 11:38:49 +00:00
require 'vkontakte'
2011-06-22 00:55:09 +00:00
2011-04-03 16:21:05 +00:00
class ApplicationController < ActionController::Base
protect_from_forgery
2011-09-17 10:20:07 +00:00
before_filter :set_locale
2011-06-22 00:55:09 +00:00
2011-11-26 20:56:09 +00:00
def cache_for time
response.headers['Cache-Control'] = 'public, max-age=' + time.seconds.to_s
end
2011-11-27 08:41:28 +00:00
def compile_page params
2011-11-27 09:56:10 +00:00
@data = params[:data] unless params[:data].nil?
@status = params[:status] unless params[:status].nil?
2011-11-27 08:41:28 +00:00
render json: {
2011-11-27 09:56:10 +00:00
renderer: "unified",
2011-11-27 08:41:28 +00:00
data: @data,
2011-11-27 09:56:10 +00:00
html: render_compact_partial(params[:partial]),
title: params[:title],
status: (params[:status] unless params[:status].nil?),
callback: (params[:callback] unless params[:callback].nil?)
2011-11-27 08:41:28 +00:00
}, include: (params[:include] unless params[:include].nil?)
end
def get_artist_name_from_query
params[:artist].gsub('%20', ' ').gsub('+', ' ').gsub('.html', '')
end
2011-10-20 11:01:57 +00:00
protected
2011-09-17 11:38:49 +00:00
def authorize
unless Vkontakte.check(params)
render json: { status: 'login failed' }, status: 403
2011-06-22 00:55:09 +00:00
end
end
2011-09-17 10:20:07 +00:00
def set_locale
2011-09-17 11:38:49 +00:00
session = Session.find_by_key(session_key)
2011-09-17 10:20:07 +00:00
unless session.nil?
I18n.locale = session.user.lang
end
end
2011-09-17 11:38:49 +00:00
def session_key
2011-10-05 21:54:35 +00:00
if cookies[:beathaven_sid].nil?
cookies[:beathaven_sid] = {
2011-10-24 07:33:32 +00:00
:value => Session.generate_key,
2011-10-05 21:54:35 +00:00
:expire => 42.years.from_now.utc
}
2011-09-17 11:38:49 +00:00
end
2011-10-05 21:54:35 +00:00
cookies[:beathaven_sid]
2011-09-17 10:20:07 +00:00
end
2011-10-20 11:01:57 +00:00
def render_compact_partial partial_name
(render_to_string :partial => partial_name.to_s).gsub(/\n(\s+)?/, '')
end
2011-04-03 16:21:05 +00:00
end