diff --git a/app/assets/javascripts/ajax.coffee b/app/assets/javascripts/ajax.coffee index 90babf0..905be2b 100644 --- a/app/assets/javascripts/ajax.coffee +++ b/app/assets/javascripts/ajax.coffee @@ -7,6 +7,10 @@ class window.Ajax $('.data-container .inner').html data false + loadIndexPage: -> + $('#content').load '/greetings/' + false + loadAboutPage: -> $.get '/templates/about.html', (data) -> _page.renderTextpage data @@ -30,8 +34,8 @@ class window.Ajax detectPage: () -> if m = _ajax.getAnchor().match /\/artist\/(.+)\// _search.loadArtistData m[1] - else if _ajax.getAnchor() == '' or _ajax.getAnchor().match /\/search\// - #_ajax.loadSearchPage(); + else if _ajax.getAnchor() == '' + _ajax.loadIndexPage(); else if _ajax.getAnchor().match /\/settings\// _settings.loadSettingsPage() else if _ajax.getAnchor().match /\/about\// diff --git a/app/assets/javascripts/vkontakte.coffee b/app/assets/javascripts/vkontakte.coffee index f3ceaf1..28f45ac 100644 --- a/app/assets/javascripts/vkontakte.coffee +++ b/app/assets/javascripts/vkontakte.coffee @@ -25,6 +25,9 @@ class window.Vkontakte if typeof response isnt 'undefined' and response.session _session = new Session(response.session) _session.query '/user/auth', {}, (ar) -> + if ar.ok_reload + window.location.reload() + false if ar.newbie VK.Api.call 'getVariable', key: 1281, (r) -> _session.query '/user/update', name: r.response, (ar2) -> diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2a438a5..fa5a5ae 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,6 +2,7 @@ require 'digest' class ApplicationController < ActionController::Base protect_from_forgery + before_filter :set_locale def authorized? # secret_key = request.host == 'beathaven.org' ? 'sdgwSbl3nNE4ZxafuPrp' : 's5zyjb693z6uV4rbhEyc' @@ -24,8 +25,19 @@ class ApplicationController < ActionController::Base end end + def set_locale + session = Session.find_by_key(request.cookies['_beathaven_session'][0..31]) + unless session.nil? + I18n.locale = session.user.lang + end + end + def index end + def greetings + render :partial => 'greetings' + end + end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index fd4338a..f8f65f5 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -12,9 +12,15 @@ class UserController < ApplicationController user.save @res[:newbie] = true end + + cookie_key = request.cookies['_beathaven_session'][0..31] session = Session.find_or_create_by_user_id(user.id) - session.key = Digest::SHA256.hexdigest(rand(99999999).to_s + user.id.to_s + rand(99999999).to_s) - session.save + if session.key != cookie_key + session.key = cookie_key + session.save + render :json => { 'ok_reload' => true } + return + end @res[:user] = { :id => user.id, diff --git a/app/views/application/_greetings.ru.html.haml b/app/views/application/_greetings.ru.html.haml new file mode 100644 index 0000000..4628499 --- /dev/null +++ b/app/views/application/_greetings.ru.html.haml @@ -0,0 +1 @@ +%h1 Привет! \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index dc0b6a1..776864d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,6 +57,7 @@ Beathaven::Application.routes.draw do # match ':controller(/:action(/:id(.:format)))' match '/' => 'application#index' + match '/greetings/' => 'application#greetings' match 'user/auth' => 'user#auth' match 'user/update' => 'user#update'