-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.rb
69 lines (51 loc) · 1.55 KB
/
plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# name: VK.COM authentication
# about: http://discourse-forum.ru/t/topic/34
# version: 1.0.0
# authors: Dmitry Fedyuk
gem 'omniauth-vkontakte', '1.4.0'
class VkAuthenticator < ::Auth::Authenticator
def name
'vkontakte'
end
def after_authenticate(auth_token)
result = Auth::Result.new
# grap the info we need from omni auth
data = auth_token[:info]
raw_info = auth_token["extra"]["raw_info"]
name = data["name"]
vk_uid = auth_token["uid"]
# plugin specific data storage
current_info = ::PluginStore.get("vk", "vk_uid_#{vk_uid}")
result.user =
if current_info
User.where(id: current_info[:user_id]).first
end
result.name = name
result.extra_data = { vk_uid: vk_uid }
result
end
def after_create_account(user, auth)
data = auth[:extra_data]
::PluginStore.set("vk", "vk_uid_#{data[:vk_uid]}", {user_id: user.id })
end
def register_middleware(omniauth)
omniauth.provider :vkontakte, :setup => lambda { |env|
strategy = env['omniauth.strategy']
strategy.options[:client_id] = SiteSetting.vk_client_id
strategy.options[:client_secret] = SiteSetting.vk_client_secret
}
end
end
auth_provider :frame_width => 920,
:frame_height => 800,
:authenticator => VkAuthenticator.new
# We ship with zocial, it may have an icon you like http://zocial.smcllns.com/sample.html
# in our current case we have an icon for vk
register_css <<CSS
.btn-social.vkontakte {
background: #46698f;
}
.btn-social.vkontakte:before {
content: "N";
}
CSS