oldhaven/app/controllers/application_controller.rb

55 lines
1.0 KiB
Ruby
Raw Normal View History

2011-06-22 04:55:09 +04:00
require 'digest'
2011-09-17 15:38:49 +04:00
require 'vkontakte'
2011-06-22 04:55:09 +04:00
2011-04-03 20:21:05 +04:00
class ApplicationController < ActionController::Base
protect_from_forgery
2011-09-17 14:20:07 +04:00
before_filter :set_locale
2011-06-22 04:55:09 +04:00
2011-09-17 15:38:49 +04:00
def index; end
def greetings
2011-10-24 12:27:06 +04:00
render partial: 'greetings'
2011-09-17 15:38:49 +04:00
end
2011-09-19 16:31:05 +04:00
def about
2011-10-24 12:27:06 +04:00
render partial: 'about'
2011-09-19 16:31:05 +04:00
end
2011-10-24 14:15:00 +04:00
def stat
@artists = Artist.count
@albums = Album.count
@tracks = Track.count
@users = User.count
render partial: 'stat'
end
2011-10-20 15:01:57 +04:00
protected
2011-09-17 15:38:49 +04:00
def authorize
unless Vkontakte.check(params)
render :json => { :status => 'login failed' }
2011-06-22 04:55:09 +04:00
end
end
2011-09-17 14:20:07 +04:00
def set_locale
2011-09-17 15:38:49 +04:00
session = Session.find_by_key(session_key)
2011-09-17 14:20:07 +04:00
unless session.nil?
I18n.locale = session.user.lang
end
end
2011-09-17 15:38:49 +04:00
def session_key
2011-10-06 01:54:35 +04:00
if cookies[:beathaven_sid].nil?
cookies[:beathaven_sid] = {
2011-10-24 11:33:32 +04:00
:value => Session.generate_key,
2011-10-06 01:54:35 +04:00
:expire => 42.years.from_now.utc
}
2011-09-17 15:38:49 +04:00
end
2011-10-06 01:54:35 +04:00
cookies[:beathaven_sid]
2011-09-17 14:20:07 +04:00
end
2011-10-20 15:01:57 +04:00
def render_compact_partial partial_name
(render_to_string :partial => partial_name.to_s).gsub(/\n(\s+)?/, '')
end
2011-04-03 20:21:05 +04:00
end