Permalink
Browse files

* added merge option

  • Loading branch information...
1 parent a1c2690 commit 951d0fbe8621db4e9d8b324cd8c8349183fa2bc7 Dmitry Vorotilin committed Feb 1, 2011
Showing with 35 additions and 11 deletions.
  1. +15 −4 README.rdoc
  2. +17 −6 lib/vkontakte/authentication.rb
  3. +3 −1 lib/vkontakte/session.rb
View
@@ -21,7 +21,21 @@ 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
@@ -30,17 +44,14 @@ Create migration "script/generate migration add_vkontakte_id_to_user vk_id:strin
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
+ # 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
- # 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
@@ -27,13 +27,24 @@ def vkontakte_enabled_value(value = nil)
rw_config(:vkontakte_enabled, value, false)
end
- def vkontakte_auto_registration(value = true)
- rw_config(:vkontakte_auto_registration, value, true)
+ # Auto registration
+ # def vkontakte_auto_registration(value = true)
+ # rw_config(:vkontakte_auto_registration, value, true)
+ # end
+ # alias_method :vkontakte_auto_registration=, :vkontakte_auto_registration
+ #
+ # def vkontakte_auto_registration_value(value = nil)
+ # rw_config(:vkontakte_auto_registration, value, true)
+ # end
+
+ # Auto merge
+ def vkontakte_merge_enabled(value = true)
+ rw_config(:vkontakte_merge_enabled, value, true)
end
- alias_method :vkontakte_auto_registration=, :vkontakte_auto_registration
-
- def vkontakte_auto_registration_value(value = nil)
- rw_config(:vkontakte_enabled, value, true)
+ alias_method :vkontakte_merge_enabled=, :vkontakte_merge_enabled
+
+ def vkontakte_merge_enabled_value(value = nil)
+ rw_config(:vkontakte_merge_enabled, value, true)
end
def vk_app_id(value = nil)
View
@@ -52,8 +52,10 @@ def validate_by_vk_cookie
self.attempted_record = record_class.new
self.attempted_record.send "#{vk_id_field}=", @vkontakte_data[:mid]
self.attempted_record.send :persistence_token=, Authlogic::Random.hex_token if self.attempted_record.respond_to? :persistence_token=
- map_vkontakte_data
+ map_vkontakte_data if record_class.vkontakte_merge_enabled_value
self.attempted_record.save_without_session_maintenance
+ elsif !record_class.vkontakte_auto_registration_value
+ self.attempted_record = record_class.new
end
end
return true

0 comments on commit 951d0fb

Please sign in to comment.