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

47 lines
985 B
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-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-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' }
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] = {
: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
}
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