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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/omniauth/strategies/mailru_api/view_helper.rb', line 25
def mailru_login_button(control = nil)
unless control.present?
control = '<a class="mrc__connectButton">вход в mail.ru</a>'
init_control = "mailru.connect.initButton();"
end
" <script type=\"text/javascript\" src=\"http://cdn.connect.mail.ru/js/loader.js\"></script>\n <script type=\"text/javascript\">\n mailruLogin = {\n initialized: false,\n initMailRuApi: function() {\n mailru.connect.init('\#{OmniAuth.config.mailru_app_id}', '\#{OmniAuth.config.mailru_private_key}');\n \#{init_control}\n mailru.events.listen(mailru.connect.events.login, function(session){\n mailru.common.users.getInfo(function(result){\n mailruLogin.redirectWithPost('\#{OmniAuth.config.path_prefix}/mailru/callback', result[0]);\n });\n });\n mailruLogin.initialized = true;\n },\n load: function() {\n mailru.loader.require('api', function() {\n mailruLogin.initMailRuApi();\n });\n },\n login: function(){\n if(!mailruLogin.initialized) mailruLogin.initMailRuApi();\n mailru.connect.login();\n },\n redirectWithPost: function(url, data) {\n data = data || {};\n \#{ if respond_to?(:form_authenticity_token)\n \"data['authenticity_token'] = '\#{form_authenticity_token}'; var method = 'POST';\" \n else\n \"var method = 'GET';\"\n end\n }\n var form = document.createElement(\"form\"), input;\n form.setAttribute(\"action\", url);\n form.setAttribute(\"method\", method);\n\n for (var property in data) {\n if (data.hasOwnProperty(property)) {\n var value = data[property];\n if(property == 'location') {\n input = document.createElement(\"input\");\n input.setAttribute(\"type\", \"hidden\");\n input.setAttribute(\"name\", 'country');\n input.setAttribute(\"value\", value['country']['name']);\n form.appendChild(input);\n input = document.createElement(\"input\");\n input.setAttribute(\"type\", \"hidden\");\n input.setAttribute(\"name\", 'city');\n input.setAttribute(\"value\", value['city']['name']);\n form.appendChild(input);\n }\n else if (value instanceof Array) {\n for (var i = 0, l = value.length; i < l; i++) {\n input = document.createElement(\"input\");\n input.setAttribute(\"type\", \"hidden\");\n input.setAttribute(\"name\", property);\n input.setAttribute(\"value\", value[i]);\n form.appendChild(input);\n }\n }\n else {\n input = document.createElement(\"input\");\n input.setAttribute(\"type\", \"hidden\");\n input.setAttribute(\"name\", property);\n input.setAttribute(\"value\", value);\n form.appendChild(input);\n }\n }\n }\n document.body.appendChild(form);\n form.submit();\n document.body.removeChild(form);\n }\n };\n jQuery(document).ready(function(){\n mailruLogin.load();\n });\n </script>\n \#{control}\n BUTTON\nend\n"
|