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

43 lines
894 B
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
protected
def authorize
unless Vkontakte.check(params)
render :json => { :status => 'login failed' }
false
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
unless request.cookies['_beathaven_session'].nil?
rails_key = request.cookies['_beathaven_session'][0..31]
else
rails_key = Digest::SHA512.hexdigest(Beathaven::Application.config.secret_token+Time.now.to_f.to_s+Random.rand().to_s)
end
Digest::SHA512.hexdigest(rails_key)
end
end