Users model and integration
This commit is contained in:
		
							parent
							
								
									93130968fd
								
							
						
					
					
						commit
						49f1fba33a
					
				@ -14,6 +14,18 @@ class UserController < ApplicationController
 | 
			
		||||
      
 | 
			
		||||
      if Digest::MD5.hexdigest(hash) == params[:sig]
 | 
			
		||||
        @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
 | 
			
		||||
        @res[:status] = 'bad signature'
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								app/models/user.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								app/models/user.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
			
		||||
class User < ActiveRecord::Base
 | 
			
		||||
end
 | 
			
		||||
							
								
								
									
										15
									
								
								db/migrate/20110621001100_create_users.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								db/migrate/20110621001100_create_users.rb
									
									
									
									
									
										Normal 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
 | 
			
		||||
							
								
								
									
										10
									
								
								db/schema.rb
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								db/schema.rb
									
									
									
									
									
								
							@ -10,7 +10,7 @@
 | 
			
		||||
#
 | 
			
		||||
# 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|
 | 
			
		||||
    t.string   "name"
 | 
			
		||||
@ -62,4 +62,12 @@ ActiveRecord::Schema.define(:version => 20110618191349) do
 | 
			
		||||
    t.string   "country"
 | 
			
		||||
  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
 | 
			
		||||
 | 
			
		||||
@ -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/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/session.js"></script>
 | 
			
		||||
		<script type="text/javascript" charset="windows-1251" src="http://vkontakte.ru/js/api/openapi.js"></script>
 | 
			
		||||
	</head>
 | 
			
		||||
	<body>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										5
									
								
								public/javascripts/beathaven/session.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								public/javascripts/beathaven/session.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
			
		||||
var Session = {
 | 
			
		||||
	
 | 
			
		||||
	user_id: null,
 | 
			
		||||
	vkid: null
 | 
			
		||||
}
 | 
			
		||||
@ -5,8 +5,18 @@ function authInfo(response) {
 | 
			
		||||
		if ($('#search_field').length > 0) {
 | 
			
		||||
			$('#search_field').focus();
 | 
			
		||||
		}
 | 
			
		||||
		VK.Api.call('getVariable', {key: 1281}, function(r) {
 | 
			
		||||
			$('#header-container .hello').text('Hi there, '+ r.response +'!');
 | 
			
		||||
		$.post('/user/auth', response.session, function(ar){
 | 
			
		||||
			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 {
 | 
			
		||||
		$('#vk_login, .auth_notice').css('display', 'block');
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										11
									
								
								test/fixtures/users.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								test/fixtures/users.yml
									
									
									
									
										vendored
									
									
										Normal 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
									
								
							
							
						
						
									
										8
									
								
								test/unit/user_test.rb
									
									
									
									
									
										Normal 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
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user