aavkontakte-rails3

This is aavkontakte-rails3 - yet 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: your-really-domain:3000 after closing popup window is works too. You must add your domain in /etc/hosts

Install

gem install aavkontakte-rails3

In environment.rb:

config.gem 'aavkontakte-rails3'

Add following line:

acts_as_authentic do |c|
  c.vkontakte_enabled = { :vk_app_id => "id", :vk_app_password => "password" }
  c.vkontakte_merge_enabled true     # mapping user data from vkontakte to new user account, true by default
end

By default “vkontakte_merge_enabled” uses “map_vkontakte_data” method:

private
def map_vkontakte_data
  self.attempted_record.send("#{klass.login_field}=", @vkontakte_data[:user][:nickname]) if self.attempted_record.send(klass.login_field).blank?
  self.attempted_record.send("first_name=", @vkontakte_data[:user][:first_name]) if @vkontakte_data[:user][:first_name]
  self.attempted_record.send("last_name=", @vkontakte_data[:user][:last_name]) if @vkontakte_data[:user][:last_name]
end

If you set option to true, you need override it in user_session model.

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
    # You must remove any database constraints for fields:
    # 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
    # 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

In the body section:

<%= init_vkontakte %>

After first start your application, it’s copying vkontakte.js to your javascripts directory or if it doesn’t exist.

Put link somewhere, where you want:

<%= vkontakte_login_link_to "Login with vkontakte" %>

By default it uses action create of user_sessions controller. Parameters are identical link_to without block.

Contributing to aavkontakte-rails3

Copyright © 2011 Dmitry Vorotilin. See LICENSE.txt for further details.