1
0
Fork 0

Users model and integration

This commit is contained in:
magnolia-fan 2011-06-21 04:48:53 +04:00
parent 93130968fd
commit 49f1fba33a
9 changed files with 75 additions and 3 deletions

View File

@ -14,6 +14,18 @@ class UserController < ApplicationController
if Digest::MD5.hexdigest(hash) == params[:sig] if Digest::MD5.hexdigest(hash) == params[:sig]
@res[:status] = 'hello' @res[:status] = 'hello'
user = User.find_by_vkid(params[:mid])
if user.nil?
user = User.new
user.vkid = params[:mid]
user.save
end
if user.name.nil? and not params[:name].nil?
user.name = params[:name]
user.save
end
@res[:id] = user.id
@res[:username] = user.name
else else
@res[:status] = 'bad signature' @res[:status] = 'bad signature'
end end

2
app/models/user.rb Normal file
View File

@ -0,0 +1,2 @@
class User < ActiveRecord::Base
end

View File

@ -0,0 +1,15 @@
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :name
t.string :email
t.integer :vkid
t.timestamps
end
end
def self.down
drop_table :users
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110618191349) do ActiveRecord::Schema.define(:version => 20110621001100) do
create_table "albums", :force => true do |t| create_table "albums", :force => true do |t|
t.string "name" t.string "name"
@ -62,4 +62,12 @@ ActiveRecord::Schema.define(:version => 20110618191349) do
t.string "country" t.string "country"
end end
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.integer "vkid"
t.datetime "created_at"
t.datetime "updated_at"
end
end end

View File

@ -19,6 +19,7 @@
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/audio.js"></script> <script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/audio.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/player.js"></script> <script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/player.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/vkontakte.js"></script> <script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/vkontakte.js"></script>
<script type="text/javascript" charset="utf-8" src="/javascripts/beathaven/session.js"></script>
<script type="text/javascript" charset="windows-1251" src="http://vkontakte.ru/js/api/openapi.js"></script> <script type="text/javascript" charset="windows-1251" src="http://vkontakte.ru/js/api/openapi.js"></script>
</head> </head>
<body> <body>

View File

@ -0,0 +1,5 @@
var Session = {
user_id: null,
vkid: null
}

View File

@ -5,8 +5,18 @@ function authInfo(response) {
if ($('#search_field').length > 0) { if ($('#search_field').length > 0) {
$('#search_field').focus(); $('#search_field').focus();
} }
VK.Api.call('getVariable', {key: 1281}, function(r) { $.post('/user/auth', response.session, function(ar){
$('#header-container .hello').text('Hi there, '+ r.response +'!'); if (!ar.username) {
VK.Api.call('getVariable', {key: 1281}, function(r) {
response.session.name = r.response;
$.post('/user/auth', response.session, function(ar2) {
$('#header-container .hello').text('Hi there, '+ ar2.username +'!');
});
});
}
$('#header-container .hello').text('Hi there, '+ (ar.username ? ar.username : '%username%') +'!');
Session.user_id = ar.id;
Session.vkid = response.session.mid;
}); });
} else { } else {
$('#vk_login, .auth_notice').css('display', 'block'); $('#vk_login, .auth_notice').css('display', 'block');

11
test/fixtures/users.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
one:
name: MyString
email: MyString
vkid: 1
two:
name: MyString
email: MyString
vkid: 1

8
test/unit/user_test.rb Normal file
View File

@ -0,0 +1,8 @@
require 'test_helper'
class UserTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end