oa-vkontakte 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Nick Recobra
1
+ Copyright (c) 2010 Nick Recobra
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  gem install oa-vkontakte
8
8
 
9
- Добавить в config/initializers/moniauth.rb:
9
+ Добавить в config/initializers/omniauth.rb:
10
10
 
11
11
  Rails.application.config.middleware.use OmniAuth::Builder do
12
12
  provider :vkontakte_open_api, <ID приложения>
@@ -20,16 +20,27 @@
20
20
 
21
21
  <%= vkontakte_login_button %>
22
22
 
23
- Этот хелпер предполагает наличие jQuery на странице для совершения ajax запроса.
23
+ Также кнопка доступна по адресу /auth/vkontakte. Можно пропробовать встроить её как iframe.
24
24
 
25
- Также кнопка с подключенной jQuery доступна по адресу /auth/vkontakte. Можно пропробовать встроить её как iframe.
26
-
27
- После клика на кнопку и разрешения добавления приложения, будет совершен ajax-запрос на /auth/vkontakte/callback.
25
+ После клика на кнопку и разрешения добавления приложения, будет совершен POST-запрос на /auth/vkontakte/callback.
28
26
  В action, к которому будет привязан этот путь, будет доступна переменная
29
27
 
30
- request["omniauth.auth"].
31
-
32
- После ajax-запроса страница, на которой находится пользователь, будет перезагружена.
28
+ request["omniauth.auth"]
29
+
30
+ Содержание этой переменной примерно следующее:
31
+
32
+ {
33
+ 'uid' => '1234567890', # ID пользователя vkontakte.ru
34
+ 'provider' => 'vkontakte',
35
+ 'user_info' => {
36
+ 'name' => 'Nick Recobra',
37
+ 'nickname' => 'oruen',
38
+ 'firstName' => 'Nick',
39
+ 'lastName' => 'Recobra',
40
+ 'image' => 'http://cs191.vkontakte.ru/u00001/e_375bc433.jpg', # путь до вконтактовского аватара
41
+ 'urls' => { 'Page' => 'http://vkontakte.ru/id1234567890' }
42
+ }
43
+ }
33
44
 
34
45
  == Ссылки
35
46
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -16,7 +16,6 @@ module OmniAuth
16
16
  <head>
17
17
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
18
18
  <title>Вход во ВКонтакте</title>
19
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
20
19
  </head>
21
20
  <body>
22
21
  HEADER
@@ -27,64 +26,82 @@ HEADER
27
26
  <div id="vk_api_transport"></div>
28
27
  <script type="text/javascript">
29
28
  window.vkAsyncInit = function() {
30
- /*VK.Observer.subscribe('auth.login', function(response) {
31
- window.location = '/omniauth/vkontakte/callback';
32
- });*/
33
29
  VK.init({
34
- apiId: #{OmniAuth.config.vkontakte_app_id},
30
+ apiId: '#{OmniAuth.config.vkontakte_app_id}',
35
31
  nameTransportPath: "/xd_receiver.html"
36
32
  });
37
33
  VK.UI.button('vk_login');
38
34
  };
39
- LOGINZA = {
40
- vkLoginResult: function (r) {
41
- //console.log('called vkLoginResult');
42
- if (r.session && r.session.expire != "0") {
43
- LOGINZA.vkGetUserProfile(LOGINZA.vkPutUserProfile)
44
- } else if (r.session.expire == "0") {
45
- //console.log('VK.bugFix recall login');
46
- VK.Observer.subscribe("auth.sessionChange", function (r) {
47
- //console.log('called bugFuxFunc');
48
- VK.Observer.unsubscribe("auth.sessionChange");
49
- if (r.session && r.session.expire != "0") {
50
- LOGINZA.vkGetUserProfile(LOGINZA.vkPutUserProfile)
51
- } else {
52
- //console.log("FAILED")
35
+ vkLogin = {
36
+ doLogin: function() {
37
+ VK.Auth.login(vkLogin.loginResult);
38
+ },
39
+ redirectWithPost: function(url, data) {
40
+ method = "POST";
41
+ data = data || {};
42
+ var form = document.createElement("form"),
43
+ input;
44
+ form.setAttribute("action", url);
45
+ form.setAttribute("method", "POST");
46
+
47
+ for (var property in data) {
48
+ if (data.hasOwnProperty(property)) {
49
+ var value = data[property];
50
+ if (value instanceof Array) {
51
+ for (var i = 0, l = value.length; i < l; i++) {
52
+ input = document.createElement("input");
53
+ input.setAttribute("type", "hidden");
54
+ input.setAttribute("name", property);
55
+ input.setAttribute("value", value[i]);
56
+ form.appendChild(input);
57
+ }
58
+ }
59
+ else {
60
+ input = document.createElement("input");
61
+ input.setAttribute("type", "hidden");
62
+ input.setAttribute("name", property);
63
+ input.setAttribute("value", value);
64
+ form.appendChild(input);
53
65
  }
54
- });
55
- VK.Auth.login()
66
+ }
67
+ }
68
+ document.body.appendChild(form);
69
+ form.submit();
70
+ document.body.removeChild(form);
71
+ },
72
+ loginResult: function (r) {
73
+ if (r.session) {
74
+ if (r.session.expire != "0") {
75
+ vkLogin.getUserProfile(vkLogin.putUserProfile);
76
+ } else if (r.session.expire == "0") {
77
+ VK.Observer.subscribe("auth.sessionChange", function (r) {
78
+ VK.Observer.unsubscribe("auth.sessionChange");
79
+ if (r.session && r.session.expire != "0") {
80
+ vkLogin.getUserProfile(vkLogin.putUserProfile)
81
+ } else {
82
+ }
83
+ });
84
+ VK.Auth.login()
85
+ }
56
86
  }
57
87
  },
58
- vkGetUserProfile: function (callFunc) {
59
- //console.log('called vkGetUserProfile');
88
+ getUserProfile: function (callFunc) {
60
89
  var code;
61
90
  code = 'return {';
62
- code += 'me: API.getProfiles({uids: API.getVariable({key: 1280}), fields: "nickname,sex,bdate,city,country,photo,photo_big,has_mobile,rate,home_phone,mobile_phone"})[0]';
91
+ code += 'me: API.getProfiles({uids: API.getVariable({key: 1280}), fields: "nickname,sex,photo"})[0]';
63
92
  code += '};';
64
93
  VK.Api.call('execute', {
65
94
  'code': code
66
95
  },
67
96
  callFunc);
68
97
  },
69
- vkPutUserProfile: function (data) {
70
- //console.log('called vkPutUserProfile');
98
+ putUserProfile: function (data) {
71
99
  if (data.response) {
72
100
  r = data.response;
73
- $.ajax({
74
- type: "POST",
75
- url: '#{OmniAuth.config.path_prefix}/vkontakte/callback',
76
- data: r.me,
77
- success: function () {
78
- document.location.reload();
79
- }
80
- });
81
- //console.log(data);
101
+ vkLogin.redirectWithPost('#{OmniAuth.config.path_prefix}/vkontakte/callback', r.me);
82
102
  }
83
103
  }
84
104
  };
85
- window.doLogin = function() {
86
- VK.Auth.login(LOGINZA.vkLoginResult);
87
- };
88
105
  (function() {
89
106
  var el = document.createElement("script");
90
107
  el.type = "text/javascript";
@@ -94,7 +111,7 @@ HEADER
94
111
  document.getElementById("vk_api_transport").appendChild(el);
95
112
  }());
96
113
  </script>
97
- <div id="vk_login" style="margin: 0 auto 20px auto;" onclick="doLogin();"></div>
114
+ <div id="vk_login" style="margin: 0 auto 20px auto;" onclick="vkLogin.doLogin();"></div>
98
115
  BUTTON
99
116
  end
100
117
 
data/oa-vkontakte.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{oa-vkontakte}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nick Recobra"]
12
- s.date = %q{2010-10-14}
12
+ s.date = %q{2010-10-19}
13
13
  s.description = %q{OmniAuth extension for vkontakte.ru authentication}
14
14
  s.email = %q{oruenu@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -1,7 +1,4 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "OaVkontakte" do
4
- it "fails" do
5
- fail "hey buddy, you should probably rename this file and start specing for real"
6
- end
7
4
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
3
4
  require 'oa-vkontakte'
4
5
  require 'spec'
5
6
  require 'spec/autorun'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oa-vkontakte
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nick Recobra
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-14 00:00:00 +04:00
18
+ date: 2010-10-19 00:00:00 +04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency