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 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 => Digest::SHA1.hexdigest(Beathaven::Application.config.secret_token+Time.now.to_f.to_s+Random.rand().to_s), :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