Skip to content
This repository has been archived by the owner on Jul 17, 2018. It is now read-only.

Commit

Permalink
* fixed session bugs in helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Vorotilin committed Jan 31, 2011
1 parent a2c42af commit 2ac40a0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
23 changes: 19 additions & 4 deletions README.rdoc
Expand Up @@ -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

Expand All @@ -11,7 +13,7 @@ gem install aavkontakte

In environment.rb:

config.gem 'aavkontakte', :version => '>=0.1.0'
config.gem 'aavkontakte'

* User model

Expand All @@ -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:
Expand All @@ -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

Expand Down
9 changes: 0 additions & 9 deletions lib/migrate/add_vkontakte_id_to_user.rb

This file was deleted.

8 changes: 4 additions & 4 deletions lib/vkontakte.js
Expand Up @@ -20,15 +20,15 @@ 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 */ }
}, VK.access.FRIENDS | VK.access.WIKI);
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");
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/vkontakte/helper.rb
Expand Up @@ -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
Expand Down

0 comments on commit 2ac40a0

Please sign in to comment.