diff --git a/README.rdoc b/README.rdoc index 4fb0315..720c8c0 100644 --- a/README.rdoc +++ b/README.rdoc @@ -2,6 +2,8 @@ This is beta version of aavkontakte - another authlogic vkontakte authorization gem. It provides vkontakte authorization to authlogic. This gem is tested with authlogic and authlogic-rpx on my project. Please report me about bugs. +Vkontakte uses domain protection for url address of your site. But I noticed that: +http://your-really-domain:3000/ after closing popup window is works too. You must add your domain in /etc/hosts == Install @@ -11,7 +13,7 @@ gem install aavkontakte In environment.rb: - config.gem 'aavkontakte', :version => '>=0.1.0' + config.gem 'aavkontakte' * User model @@ -23,18 +25,29 @@ Add following line: * Migrations -Create migration: +Create migration "script/generate migration add_vkontakte_id_to_user vk_id:string": class AddVkontakteIdToUser < ActiveRecord::Migration def self.up add_column :users, :vk_id, :string + # Wait a little time for some options for this. + # Now you are using only auto-registration, you must remove any database constraints for fields: + # Uncomment follow lines + # change_column :users, :crypted_password, :string, :null => true + # change_column :users, :password_salt, :string, :null => true + # change_column :users, :login, :string, :null => true end def self.down - remove_column :users, :vk_id + remove_column :users, :vk_id + # Uncomment follow lines + # change_column :users, :crypted_password, :string, :null => false + # change_column :users, :password_salt, :string, :null => false + # change_column :users, :login, :string, :null => false end end + * Layout In the body section: @@ -49,7 +62,9 @@ After first start your application, it's copying vkontakte.js to your javascript Put link somewhere, where you want: - <%= vkontakte_login_link "Login with vkontakte" %> + <%= vkontakte_login_link_to "Login with vkontakte" %> + +By default it uses action create of user_sessions controller. Parameters are identical link_to without block. * User session diff --git a/lib/migrate/add_vkontakte_id_to_user.rb b/lib/migrate/add_vkontakte_id_to_user.rb deleted file mode 100644 index 75602c1..0000000 --- a/lib/migrate/add_vkontakte_id_to_user.rb +++ /dev/null @@ -1,9 +0,0 @@ -class AddVkontakteIdToUser < ActiveRecord::Migration - def self.up - add_column :users, :vk_id, :string - end - - def self.down - remove_column :users, :vk_id - end -end diff --git a/lib/vkontakte.js b/lib/vkontakte.js index 6e36d10..25198f5 100644 --- a/lib/vkontakte.js +++ b/lib/vkontakte.js @@ -20,7 +20,7 @@ function vkLogin(options) { if(response.session) { /* User is logged in */ // need ajax request? $.post(url, response, "script" ); - post(options['url'], response, options['authenticity_token'], options['session_name'], options['session_key']); + post(options['url'], response, options['authenticity_token'], options['session_key'], options['session_id']); if (response.settings){ /* Selected user access settings */ } } else { /* User pressed the Cancel button */ } @@ -28,7 +28,7 @@ function vkLogin(options) { return false; } -function post(url, params, token, session_name, session_key) { +function post(url, params, token, session_key, session_id) { var method = "post"; var form = document.createElement("form"); @@ -43,8 +43,8 @@ function post(url, params, token, session_name, session_key) { var sessionField = document.createElement("input"); sessionField.setAttribute("type", "hidden"); - sessionField.setAttribute("name", session_name); - sessionField.setAttribute("value", session_key); + sessionField.setAttribute("name", session_key); + sessionField.setAttribute("value", session_id); form.appendChild(sessionField); // recursively adds nested inputs to form diff --git a/lib/vkontakte/helper.rb b/lib/vkontakte/helper.rb index 28aaca1..842a1ff 100644 --- a/lib/vkontakte/helper.rb +++ b/lib/vkontakte/helper.rb @@ -4,9 +4,9 @@ def init_vkontakte vkontakte_div + vkontakte_init if vk_app_id end - def vkontakte_login_link(name, url = user_sessions_path, html_options = {}) + def vkontakte_login_link_to(name, url = user_session_path, html_options = {}) authenticity_token = protect_against_forgery? ? form_authenticity_token : '' - options = "{ url: '#{url}', authenticity_token: '#{authenticity_token}', session_name: '#{session_key_name}', session_key: '#{cookies[session_key_name]}' }" + options = "{ url: '#{url}', authenticity_token: '#{authenticity_token}', session_key: '#{request.session_options[:key]}', session_id: '#{request.session_options[:id]}' }" html_options.merge!(:onclick => "vkLogin(#{options});") if vk_app_id link_to name, "#", html_options end