1
0
Fork 0

Locale switch, greetings page

This commit is contained in:
magnolia-fan 2011-09-17 14:20:07 +04:00
parent 95c0b9fc12
commit 67e79acf23
6 changed files with 31 additions and 4 deletions

View File

@ -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\//

View File

@ -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) ->

View File

@ -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

View File

@ -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,

View File

@ -0,0 +1 @@
%h1 Привет!

View File

@ -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'