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
|
2011-10-24 08:27:06 +00:00
|
|
|
render partial: 'greetings'
|
2011-09-17 11:38:49 +00:00
|
|
|
end
|
|
|
|
|
2011-09-19 12:31:05 +00:00
|
|
|
def about
|
2011-10-24 08:27:06 +00:00
|
|
|
render partial: 'about'
|
2011-09-19 12:31:05 +00:00
|
|
|
end
|
|
|
|
|
2011-10-24 10:15:00 +00:00
|
|
|
def stat
|
|
|
|
@artists = Artist.count
|
|
|
|
@albums = Album.count
|
|
|
|
@tracks = Track.count
|
|
|
|
@users = User.count
|
|
|
|
render partial: 'stat'
|
|
|
|
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] = {
|
2011-10-24 07:33:32 +00:00
|
|
|
:value => Session.generate_key,
|
2011-10-05 21:54:35 +00:00
|
|
|
: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
|