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-09-17 11:38:49 +00:00
|
|
|
def index; end
|
|
|
|
|
|
|
|
def greetings
|
|
|
|
render :partial => 'greetings'
|
|
|
|
end
|
|
|
|
|
2011-09-19 12:31:05 +00:00
|
|
|
def about
|
|
|
|
render :partial => 'about'
|
|
|
|
end
|
|
|
|
|
2011-09-17 11:38:49 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def authorize
|
|
|
|
unless Vkontakte.check(params)
|
|
|
|
render :json => { :status => 'login failed' }
|
|
|
|
false
|
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
|
|
|
|
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)
|
2011-09-17 10:20:07 +00:00
|
|
|
end
|
2011-04-03 16:21:05 +00:00
|
|
|
end
|