No commit activity in last 3 years
No release in over 3 years
Vkontakte authorization for authlogic with ruby 1.9 and rails 3.0
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

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

  • Environment

In environment.rb:

config.gem 'aavkontakte-rails3'
  • User model

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
  • UserSession model:

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.

  • Migrations

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
  • Layout

In the body section:

<%= init_vkontakte %>
  • Javascripts

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

  • Link

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¶ ↑

  • Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet

  • Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

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