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

59 lines
1.1 KiB
Ruby

require 'digest'
require 'vkontakte'
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_locale
def index; end
def greetings
render partial: 'greetings'
end
def about
render partial: 'about'
end
def stat
@artists = Artist.count
@albums = Album.count
@tracks = Track.count
@users = User.count
render partial: 'stat'
end
def cache_for time
response.headers['Cache-Control'] = 'public, max-age=' + time.seconds.to_s
end
protected
def authorize
unless Vkontakte.check(params)
render :json => { :status => 'login failed' }
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