authlogic_vkontakte 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +3 -1
- data/README.rdoc +1 -1
- data/Rakefile +1 -1
- data/authlogic_vkontakte.gemspec +3 -3
- data/lib/tasks/vkontakte.rake +7 -5
- data/lib/vkontakte_authentication.rb +94 -94
- data/{js → resources}/vkontakte.js +0 -0
- data/resources/xd_receiver.html +10 -0
- data/vkontakte.yml +2 -0
- metadata +7 -5
data/Manifest
CHANGED
@@ -2,10 +2,12 @@ README.rdoc
|
|
2
2
|
Rakefile
|
3
3
|
authlogic_vkontakte.gemspec
|
4
4
|
init.rb
|
5
|
-
js/vkontakte.js
|
6
5
|
lib/profile_loader.rb
|
7
6
|
lib/settings.rb
|
8
7
|
lib/tasks/vkontakte.rake
|
9
8
|
lib/vkontakte_authentication.rb
|
10
9
|
lib/vkontakte_helper.rb
|
10
|
+
resources/vkontakte.js
|
11
|
+
resources/xd_receiver.html
|
12
|
+
vkontakte.yml
|
11
13
|
Manifest
|
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
|
|
2
2
|
require "rake"
|
3
3
|
require "echoe"
|
4
4
|
|
5
|
-
Echoe.new("authlogic_vkontakte", "0.1.
|
5
|
+
Echoe.new("authlogic_vkontakte", "0.1.1") do |p|
|
6
6
|
p.description= "Bind vkontakte authentication to your authlogic project"
|
7
7
|
p.url= "http://github.com/GarPit/authlogic_vkontakte"
|
8
8
|
p.author= "Igor Petrov"
|
data/authlogic_vkontakte.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{authlogic_vkontakte}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Igor Petrov"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-11-17}
|
10
10
|
s.description = %q{Bind vkontakte authentication to your authlogic project}
|
11
11
|
s.email = %q{garik.piton@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["README.rdoc", "lib/profile_loader.rb", "lib/settings.rb", "lib/tasks/vkontakte.rake", "lib/vkontakte_authentication.rb", "lib/vkontakte_helper.rb"]
|
13
|
-
s.files = ["README.rdoc", "Rakefile", "authlogic_vkontakte.gemspec", "init.rb", "
|
13
|
+
s.files = ["README.rdoc", "Rakefile", "authlogic_vkontakte.gemspec", "init.rb", "lib/profile_loader.rb", "lib/settings.rb", "lib/tasks/vkontakte.rake", "lib/vkontakte_authentication.rb", "lib/vkontakte_helper.rb", "resources/vkontakte.js", "resources/xd_receiver.html", "vkontakte.yml", "Manifest"]
|
14
14
|
s.homepage = %q{http://github.com/GarPit/authlogic_vkontakte}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Authlogic_vkontakte", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
data/lib/tasks/vkontakte.rake
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
namespace :vkontakte do
|
2
2
|
desc "Init resources for plugin"
|
3
|
-
task :init => [:yml, :
|
3
|
+
task :init => [:yml, :resources]
|
4
4
|
|
5
5
|
desc "Copy vkontakte.yml to current rails application"
|
6
6
|
task :yml do
|
@@ -11,12 +11,14 @@ namespace :vkontakte do
|
|
11
11
|
puts "vkontakte.yml copied successfully!"
|
12
12
|
end
|
13
13
|
|
14
|
-
desc "Copy
|
15
|
-
task :
|
16
|
-
puts "Copying
|
14
|
+
desc "Copy resources to current rails application"
|
15
|
+
task :resources do
|
16
|
+
puts "Copying resources files..."
|
17
17
|
project_dir = RAILS_ROOT + '/public/javascripts/'
|
18
|
-
scripts = Dir[File.join(File.dirname(__FILE__), '..', '..', '/
|
18
|
+
scripts = Dir[File.join(File.dirname(__FILE__), '..', '..', '/resources/', '*.js')]
|
19
|
+
htmls = Dir[File.join(File.dirname(__FILE__), '..', '..', '/resources/', '*.html')]
|
19
20
|
FileUtils.cp(scripts, project_dir)
|
21
|
+
FileUtils.cp(htmls, RAILS_ROOT + '/public/')
|
20
22
|
puts "Files copied successfully!"
|
21
23
|
end
|
22
24
|
end
|
@@ -1,94 +1,94 @@
|
|
1
|
-
require "profile_loader"
|
2
|
-
require "settings"
|
3
|
-
require "md5"
|
4
|
-
|
5
|
-
module VkontakteAuthentication
|
6
|
-
|
7
|
-
class NotInitializedError < StandardError;
|
8
|
-
end
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
include Settings
|
12
|
-
|
13
|
-
def find_by_vk_id_method(value = nil)
|
14
|
-
rw_config(:find_by_vk_id_method, value, "find_by_vk_id")
|
15
|
-
end
|
16
|
-
alias_method :find_by_vk_id_method=, :find_by_vk_id_method
|
17
|
-
|
18
|
-
def vk_id_field(value = nil)
|
19
|
-
rw_config(:vk_id_field, value, :vk_id)
|
20
|
-
end
|
21
|
-
alias_method :vk_id_field=, :vk_id_field
|
22
|
-
|
23
|
-
def vkontakte_authentication
|
24
|
-
raise(NotInitializedError, "create and initialize vkontakte.yml") unless profile_loader.vkontakte_yml_defined? && vk_app_id && vk_app_password
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
module InstanceMethods
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def credentials=(value)
|
34
|
-
super
|
35
|
-
cookies = value.is_a?(Array) ? value.first : value
|
36
|
-
if cookies
|
37
|
-
@vk_cookies = CGI::parse(cookies[vk_app_cookie])
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def authenticating_with_vkontakte?
|
42
|
-
@vk_cookies
|
43
|
-
end
|
44
|
-
|
45
|
-
def validate_by_vk_cookie
|
46
|
-
result = "expire=%smid=%ssecret=%ssid=%s%s" % [@vk_cookies['expire'], @vk_cookies['mid'], @vk_cookies['secret'], @vk_cookies['sid'], self.class.vk_app_password]
|
47
|
-
if MD5.md5(result).to_s == @vk_cookies['sig'].to_s
|
48
|
-
raise(NotInitializedError, "you must define vk_id column in your User model") unless record_class.respond_to? find_by_vk_id_method
|
49
|
-
mid_cookie = @vk_cookies['mid'].first
|
50
|
-
possible_record = search_for_record(find_by_vk_id_method, mid_cookie)
|
51
|
-
if possible_record.nil?
|
52
|
-
possible_record = record_class.new
|
53
|
-
possible_record.send
|
54
|
-
possible_record.send :
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
Authlogic::Session::Base.class_eval do
|
90
|
-
include VkontakteAuthentication::InstanceMethods
|
91
|
-
extend VkontakteAuthentication::ClassMethods
|
92
|
-
after_destroy :destroy_vkontakte_cookies
|
93
|
-
validate :validate_by_vk_cookie, :if => :authenticating_with_vkontakte?
|
94
|
-
end
|
1
|
+
require "profile_loader"
|
2
|
+
require "settings"
|
3
|
+
require "md5"
|
4
|
+
|
5
|
+
module VkontakteAuthentication
|
6
|
+
|
7
|
+
class NotInitializedError < StandardError;
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
include Settings
|
12
|
+
|
13
|
+
def find_by_vk_id_method(value = nil)
|
14
|
+
rw_config(:find_by_vk_id_method, value, "find_by_vk_id")
|
15
|
+
end
|
16
|
+
alias_method :find_by_vk_id_method=, :find_by_vk_id_method
|
17
|
+
|
18
|
+
def vk_id_field(value = nil)
|
19
|
+
rw_config(:vk_id_field, value, :vk_id)
|
20
|
+
end
|
21
|
+
alias_method :vk_id_field=, :vk_id_field
|
22
|
+
|
23
|
+
def vkontakte_authentication
|
24
|
+
raise(NotInitializedError, "create and initialize vkontakte.yml") unless profile_loader.vkontakte_yml_defined? && vk_app_id && vk_app_password
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
module InstanceMethods
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def credentials=(value)
|
34
|
+
super
|
35
|
+
cookies = value.is_a?(Array) ? value.first : value
|
36
|
+
if cookies && cookies[vk_app_cookie]
|
37
|
+
@vk_cookies = CGI::parse(cookies[vk_app_cookie])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def authenticating_with_vkontakte?
|
42
|
+
@vk_cookies
|
43
|
+
end
|
44
|
+
|
45
|
+
def validate_by_vk_cookie
|
46
|
+
result = "expire=%smid=%ssecret=%ssid=%s%s" % [@vk_cookies['expire'], @vk_cookies['mid'], @vk_cookies['secret'], @vk_cookies['sid'], self.class.vk_app_password]
|
47
|
+
if MD5.md5(result).to_s == @vk_cookies['sig'].to_s
|
48
|
+
raise(NotInitializedError, "you must define vk_id column in your User model") unless record_class.respond_to? find_by_vk_id_method
|
49
|
+
mid_cookie = @vk_cookies['mid'].first
|
50
|
+
possible_record = search_for_record(find_by_vk_id_method, mid_cookie)
|
51
|
+
if possible_record.nil?
|
52
|
+
possible_record = record_class.new
|
53
|
+
possible_record.send "#{vk_id_field}=", mid_cookie
|
54
|
+
possible_record.send :persistence_token=, Authlogic::Random.hex_token if possible_record.respond_to? :persistence_token=
|
55
|
+
possible_record.send :save, false
|
56
|
+
end
|
57
|
+
self.attempted_record = possible_record
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def vk_app_cookie
|
62
|
+
self.class.vk_app_cookie
|
63
|
+
end
|
64
|
+
|
65
|
+
def find_by_vk_id_method
|
66
|
+
self.class.find_by_vk_id_method
|
67
|
+
end
|
68
|
+
|
69
|
+
def vk_id_field
|
70
|
+
self.class.vk_id_field
|
71
|
+
end
|
72
|
+
|
73
|
+
def record_class
|
74
|
+
self.class.klass
|
75
|
+
end
|
76
|
+
|
77
|
+
def destroy_vkontakte_cookies
|
78
|
+
controller.cookies.delete vk_app_cookie
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
ActiveRecord::Base.class_eval do
|
86
|
+
extend VkontakteAuthentication::ClassMethods
|
87
|
+
end
|
88
|
+
|
89
|
+
Authlogic::Session::Base.class_eval do
|
90
|
+
include VkontakteAuthentication::InstanceMethods
|
91
|
+
extend VkontakteAuthentication::ClassMethods
|
92
|
+
after_destroy :destroy_vkontakte_cookies
|
93
|
+
validate :validate_by_vk_cookie, :if => :authenticating_with_vkontakte?
|
94
|
+
end
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
4
|
+
<head>
|
5
|
+
<title>Open API XD Receiver</title>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<script src="http://vkontakte.ru/js/api/xd_receiver.js" type="text/javascript"></script>
|
9
|
+
</body>
|
10
|
+
</html>
|
data/vkontakte.yml
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authlogic_vkontakte
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Igor Petrov
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-17 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -37,12 +37,14 @@ files:
|
|
37
37
|
- Rakefile
|
38
38
|
- authlogic_vkontakte.gemspec
|
39
39
|
- init.rb
|
40
|
-
- js/vkontakte.js
|
41
40
|
- lib/profile_loader.rb
|
42
41
|
- lib/settings.rb
|
43
42
|
- lib/tasks/vkontakte.rake
|
44
43
|
- lib/vkontakte_authentication.rb
|
45
44
|
- lib/vkontakte_helper.rb
|
45
|
+
- resources/vkontakte.js
|
46
|
+
- resources/xd_receiver.html
|
47
|
+
- vkontakte.yml
|
46
48
|
- Manifest
|
47
49
|
has_rdoc: true
|
48
50
|
homepage: http://github.com/GarPit/authlogic_vkontakte
|