Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adds config

  • Loading branch information...
commit c80b22ea9e59e7ca216ec4ad8fcf361c8f3eecb9 1 parent d135258
Dmitry Vorotilin authored
View
BIN  aavkontakte-0.1.0.gem
Binary file not shown
View
1  lib/aavkontakte.rb
@@ -1,3 +1,4 @@
+require "vkontakte/configuration"
require "vkontakte/authentication"
require "vkontakte/session"
require "vkontakte/helper"
View
29 lib/vkontakte/authentication.rb
@@ -2,8 +2,8 @@ module VkontakteAuthentication
module ActsAsAuthentic
def self.included(klass)
klass.class_eval do
- extend Config
- if defined? AuthlogicRpx::ActsAsAuthentic::Methods
+ extend Configuration, Config
+ if defined? AuthlogicRpx
remove_acts_as_authentic_module AuthlogicRpx::ActsAsAuthentic::Methods
add_acts_as_authentic_module Methods, :prepend
add_acts_as_authentic_module AuthlogicRpx::ActsAsAuthentic::Methods
@@ -12,28 +12,16 @@ def self.included(klass)
end
end
end
-
- class NotInitializedError < StandardError
- end
module Config
def vkontakte_enabled(vk_app_data = {})
- value = vk_app_data.present? ? vk_app_data[:vk_app_id].present? && vk_app_data[:vk_app_password] : false
- vkontakte_enabled_value(value)
- if vkontakte_enabled_value
- rw_config(:vk_app_id, vk_app_data[:vk_app_id])
- rw_config(:vk_app_password, vk_app_data[:vk_app_password])
- rw_config(:vk_app_cookie, "vk_app_#{vk_app_data[:vk_app_id]}")
-
- message = "Set vk_app_id and vk_app_password in your environment."
- raise NotInitializedError, message if vkontakte_enabled_value && VK_APP_ID.blank? && VK_APP_PASSWORD.blank? && VK_APP_COOKIE.blank?
+ value = true if vk_app_data.present? && vk_app_data[:vk_app_id] && vk_app_data[:vk_app_password]
+ if vkontakte_enabled_value(value)
+ vk_app_id vk_app_data[:vk_app_id]
+ vk_app_password vk_app_data[:vk_app_password]
end
end
- alias_method :vkontakte_enabled=,:vkontakte_enabled
-
- def vkontakte_enabled_value(value = nil)
- rw_config(:vkontakte_enabled, value, false)
- end
+ alias_method :vkontakte_enabled=, :vkontakte_enabled
end
module Methods
@@ -47,13 +35,12 @@ def self.included(klass)
private
def validate_password_not_vkontakte?
- !authenticating_with_vkontakte? && (defined? AuthlogicRpx::ActsAsAuthentic::Methods ? !using_rpx? : true) && require_password?
+ !authenticating_with_vkontakte? && (defined?(AuthlogicRpx) ? !using_rpx? : true) && require_password?
end
def authenticating_with_vkontakte?
vk_id.present?
end
end
-
end
end
View
19 lib/vkontakte/configuration.rb
@@ -0,0 +1,19 @@
+module VkontakteAuthentication
+ module Configuration
+ def vkontakte_enabled_value(value = nil)
+ rw_config(:vkontakte_enabled, value, false)
+ end
+
+ def vk_app_id(value = nil)
+ rw_config(:vk_app_id, value)
+ end
+
+ def vk_app_password(value = nil)
+ rw_config(:vk_app_password, value)
+ end
+
+ def vk_app_cookie
+ rw_config(:vk_app_cookie, nil) || rw_config(:vk_app_cookie, "vk_app_#{vk_app_id}") if vk_app_id
+ end
+ end
+end
View
4 lib/vkontakte/helper.rb
@@ -1,7 +1,7 @@
module VkontakteAuthentication
module Helper
def init_vkontakte
- vkontakte_div + vkontakte_init
+ vkontakte_div + vkontakte_init if User.vkontakte_enabled_value
end
def vkontakte_login_link(name, url = user_sessions_path, html_options = {})
@@ -16,7 +16,7 @@ def vkontakte_div
end
def vkontakte_init
- javascript_include_tag("vkontakte") + javascript_tag("vkInit(#{VK_APP_ID});") if ActiveRecord::Base.vkontakte_enabled_value
+ javascript_include_tag("vkontakte") + javascript_tag("vkInit(#{User.vk_app_id});")
end
end
end
View
15 lib/vkontakte/session.rb
@@ -2,12 +2,10 @@
module VkontakteAuthentication
module Session
-
def self.included(klass)
klass.class_eval do
- extend Config
+ extend Config, Configuration
include InstanceMethods
-
after_destroy :destroy_vkontakte_cookies
validate :validate_by_vk_cookie, :if => :authenticating_with_vkontakte?
end
@@ -33,17 +31,17 @@ module InstanceMethods
def credentials=(value)
super
cookies = value.is_a?(Array) ? value.first : value
- if record_class.vkontakte_enabled_value && cookies && cookies[VK_APP_COOKIE]
- @vk_cookies = CGI::parse(cookies[VK_APP_COOKIE])
+ if self.class.vkontakte_enabled_value && cookies && cookies[self.class.vk_app_cookie]
+ @vk_cookies = CGI::parse(cookies[self.class.vk_app_cookie])
end
end
def authenticating_with_vkontakte?
- record_class.vkontakte_enabled_value && @vk_cookies
+ self.class.vkontakte_enabled_value && @vk_cookies
end
def validate_by_vk_cookie
- result = "expire=%smid=%ssecret=%ssid=%s%s" % [@vk_cookies['expire'], @vk_cookies['mid'], @vk_cookies['secret'], @vk_cookies['sid'], VK_APP_PASSWORD]
+ result = "expire=%smid=%ssecret=%ssid=%s%s" % [@vk_cookies['expire'], @vk_cookies['mid'], @vk_cookies['secret'], @vk_cookies['sid'], self.class.vk_app_password]
if MD5.md5(result).to_s == @vk_cookies['sig'].to_s
raise(NotInitializedError, "You must define vk_id column in your User model") unless record_class.respond_to? find_by_vk_id_method
mid_cookie = @vk_cookies['mid'].first
@@ -71,9 +69,8 @@ def record_class
end
def destroy_vkontakte_cookies
- controller.cookies.delete VK_APP_COOKIE
+ controller.cookies.delete vk_app_cookie
end
end
-
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.