digital_heroes_startkit 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +37 -0
- data/Rakefile +36 -0
- data/app/assets/config/digital_heroes_startkit_manifest.js +0 -0
- data/app/assets/javascripts/authorization.coffee +79 -0
- data/app/assets/javascripts/avatar.coffee +16 -0
- data/app/assets/javascripts/datepicker.js +2 -0
- data/app/assets/javascripts/digital_heroes_startkit/cable.js +13 -0
- data/app/assets/javascripts/digital_heroes_startkit/channels/pills.coffee +23 -0
- data/app/assets/javascripts/digital_heroes_startkit/input.coffee +5 -0
- data/app/assets/javascripts/digital_heroes_startkit/pills.coffee +2 -0
- data/app/assets/javascripts/digital_heroes_startkit/snap.svg-min.js +21 -0
- data/app/assets/javascripts/digital_heroes_startkit.js +26 -0
- data/app/assets/javascripts/profile.coffee +53 -0
- data/app/assets/javascripts/profile_geodata.coffee +68 -0
- data/app/assets/javascripts/reg_fields_checkup.coffee +96 -0
- data/app/assets/javascripts/registration.coffee +35 -0
- data/app/assets/javascripts/resurrection.coffee +20 -0
- data/app/channels/application_cable/channel.rb +4 -0
- data/app/channels/application_cable/connection.rb +4 -0
- data/app/channels/pills_channel.rb +10 -0
- data/app/controllers/avatars_controller.rb +11 -0
- data/app/controllers/clients_controller.rb +62 -0
- data/app/controllers/email_access_cards_controller.rb +28 -0
- data/app/controllers/geodata_controller.rb +84 -0
- data/app/controllers/nickname_access_cards_controller.rb +30 -0
- data/app/controllers/oauth_controller.rb +178 -0
- data/app/controllers/openid_controller.rb +124 -0
- data/app/controllers/phone_access_cards_controller.rb +28 -0
- data/app/controllers/profile_controller.rb +114 -0
- data/app/controllers/response_controller.rb +17 -0
- data/app/controllers/start_kit_controller.rb +86 -0
- data/app/controllers/user_cards_controller.rb +305 -0
- data/app/jobs/log_analyzer_job.rb +50 -0
- data/app/jobs/password_resurrection_kill_job.rb +9 -0
- data/app/mailers/admin_mailer.rb +9 -0
- data/app/mailers/client_mailer.rb +3 -0
- data/app/mailers/kreator_mailer.rb +9 -0
- data/app/mailers/manager_mailer.rb +9 -0
- data/app/mailers/prometeus_mailer.rb +16 -0
- data/app/mailers/user_cards_mailer.rb +9 -0
- data/app/models/admin.rb +3 -0
- data/app/models/avatar.rb +23 -0
- data/app/models/city.rb +7 -0
- data/app/models/client.rb +31 -0
- data/app/models/country.rb +7 -0
- data/app/models/delayed_job.rb +20 -0
- data/app/models/email_access_card.rb +30 -0
- data/app/models/kreator.rb +3 -0
- data/app/models/log_error.rb +56 -0
- data/app/models/log_error_type.rb +3 -0
- data/app/models/manager.rb +3 -0
- data/app/models/nickname_access_card.rb +18 -0
- data/app/models/oauth_access_card.rb +38 -0
- data/app/models/phone_access_card.rb +19 -0
- data/app/models/prometeus.rb +50 -0
- data/app/models/user_card.rb +158 -0
- data/app/views/admin_mailer/greetings_email.html.erb +191 -0
- data/app/views/client_mailer/greetings_email.html.erb +191 -0
- data/app/views/kreator_mailer/greetings_email.html.erb +191 -0
- data/app/views/manager_mailer/greetings_email.html.erb +191 -0
- data/app/views/oauth/verify.slim +1 -0
- data/app/views/profile/_add_avatar.slim +12 -0
- data/app/views/profile/_user_profile.slim +95 -0
- data/app/views/profile/index.slim +12 -0
- data/app/views/user_cards/authorization.slim +72 -0
- data/app/views/user_cards/confirmation_but_access_code.slim +7 -0
- data/app/views/user_cards/confirmation_complete.slim +7 -0
- data/app/views/user_cards/registration.slim +86 -0
- data/app/views/user_cards/resurrection.slim +19 -0
- data/app/views/user_cards/resurrection_but_access_code.slim +7 -0
- data/app/views/user_cards/resurrection_no_access_code.slim +7 -0
- data/app/views/user_cards_mailer/email.html.erb +191 -0
- data/app/views/user_cards_mailer/resurrection.html.erb +191 -0
- data/config/initializers/session_manager.rb +2 -0
- data/config/routes.rb +53 -0
- data/lib/access_control.rb +3 -0
- data/lib/digital_heroes_startkit/engine.rb +25 -0
- data/lib/digital_heroes_startkit/version.rb +3 -0
- data/lib/digital_heroes_startkit.rb +5 -0
- data/lib/generators/digital_heroes_startkit/install_generator.rb +61 -0
- data/lib/generators/project/Capfile +36 -0
- data/lib/generators/project/Procfile +3 -0
- data/lib/generators/project/app/assets/stylesheets/application.scss +16 -0
- data/lib/generators/project/app/assets/stylesheets/base/_auth.scss +37 -0
- data/lib/generators/project/app/assets/stylesheets/base/_buttons.scss +62 -0
- data/lib/generators/project/app/assets/stylesheets/base/_checkbox.scss +71 -0
- data/lib/generators/project/app/assets/stylesheets/base/_datepicker.scss +620 -0
- data/lib/generators/project/app/assets/stylesheets/base/_form.scss +81 -0
- data/lib/generators/project/app/assets/stylesheets/base/_notice.scss +14 -0
- data/lib/generators/project/app/assets/stylesheets/base/_pills.scss +39 -0
- data/lib/generators/project/app/assets/stylesheets/base/_profile.scss +67 -0
- data/lib/generators/project/app/assets/stylesheets/base/_reset.scss +49 -0
- data/lib/generators/project/app/assets/stylesheets/base/_social.scss +52 -0
- data/lib/generators/project/app/assets/stylesheets/base/_user.scss +0 -0
- data/lib/generators/project/app/assets/stylesheets/base/_user_avatar.scss +18 -0
- data/lib/generators/project/app/assets/stylesheets/base/styles.scss.txt +35 -0
- data/lib/generators/project/app/assets/stylesheets/plugins/sumoselect.scss +296 -0
- data/lib/generators/project/app/controllers/application_controller.rb +3 -0
- data/lib/generators/project/app/views/layouts/_counts.html.erb +29 -0
- data/lib/generators/project/app/views/layouts/_footer.slim +6 -0
- data/lib/generators/project/app/views/layouts/_head.slim +7 -0
- data/lib/generators/project/app/views/layouts/_header.slim +47 -0
- data/lib/generators/project/app/views/layouts/_mobile_menu.slim +11 -0
- data/lib/generators/project/app/views/layouts/application.slim +26 -0
- data/lib/generators/project/app/views/layouts/mailer.html.erb +13 -0
- data/lib/generators/project/app/views/layouts/mailer.text.erb +1 -0
- data/lib/generators/project/config/application.access.yml +66 -0
- data/lib/generators/project/config/application.db.yml +5 -0
- data/lib/generators/project/config/application.google.yml +3 -0
- data/lib/generators/project/config/application.oauth.yml +135 -0
- data/lib/generators/project/config/application.robokassa.yml +10 -0
- data/lib/generators/project/config/application.sendgrid.yml +3 -0
- data/lib/generators/project/config/application.telegram.yml +22 -0
- data/lib/generators/project/config/application.yml +28 -0
- data/lib/generators/project/config/cable.yml +6 -0
- data/lib/generators/project/config/capistrano.yml +78 -0
- data/lib/generators/project/config/database.yml +52 -0
- data/lib/generators/project/config/deploy/application.secrets.yml +4 -0
- data/lib/generators/project/config/deploy/domain.crt +92 -0
- data/lib/generators/project/config/deploy/domain.key +51 -0
- data/lib/generators/project/config/deploy/nginx.conf +50 -0
- data/lib/generators/project/config/deploy/production.rb +67 -0
- data/lib/generators/project/config/deploy/secrets.yml +32 -0
- data/lib/generators/project/config/deploy/secrets.yml.enc +1 -0
- data/lib/generators/project/config/deploy/secrets.yml.key +1 -0
- data/lib/generators/project/config/deploy/staging.rb +61 -0
- data/lib/generators/project/config/deploy/virgin_conf/database.yml +42 -0
- data/lib/generators/project/config/deploy/virgin_conf/nginx_site.conf +47 -0
- data/lib/generators/project/config/deploy/virgin_conf/nginx_site_ssl.conf +57 -0
- data/lib/generators/project/config/deploy/virgin_conf/postfix.cf +685 -0
- data/lib/generators/project/config/deploy/virgin_conf/production.rb +67 -0
- data/lib/generators/project/config/deploy/virgin_conf/puma.rb +66 -0
- data/lib/generators/project/config/deploy/virgin_sh/capistrano.sh +18 -0
- data/lib/generators/project/config/deploy/virgin_sh/foreman.sh +19 -0
- data/lib/generators/project/config/deploy/virgin_sh/rvm_install.sh +10 -0
- data/lib/generators/project/config/deploy.rb +377 -0
- data/lib/generators/project/config/environments/development.rb +91 -0
- data/lib/generators/project/config/environments/production.rb +142 -0
- data/lib/generators/project/config/initializers/session_store.rb +3 -0
- data/lib/generators/project/config/locales/ru.yml +444 -0
- data/lib/generators/project/db/migrate/10_create_user_cards.rb +19 -0
- data/lib/generators/project/db/migrate/12_create_email_access_cards.rb +15 -0
- data/lib/generators/project/db/migrate/13_create_nickname_access_cards.rb +15 -0
- data/lib/generators/project/db/migrate/14_create_phone_access_cards.rb +16 -0
- data/lib/generators/project/db/migrate/15_create_oauth_access_cards.rb +19 -0
- data/lib/generators/project/db/migrate/1_create_kreators.rb +9 -0
- data/lib/generators/project/db/migrate/21_create_avatars.rb +12 -0
- data/lib/generators/project/db/migrate/30_create_countries.rb +12 -0
- data/lib/generators/project/db/migrate/32_create_cities.rb +12 -0
- data/lib/generators/project/db/migrate/3_create_admins.rb +9 -0
- data/lib/generators/project/db/migrate/44_add_sessions_table.rb +12 -0
- data/lib/generators/project/db/migrate/4_create_managers.rb +10 -0
- data/lib/generators/project/db/migrate/5_create_clients.rb +17 -0
- data/lib/generators/project/db/migrate/60_create_log_error_types.rb +9 -0
- data/lib/generators/project/db/migrate/61_create_log_errors.rb +12 -0
- data/lib/generators/project/db/migrate/78_create_delayed_jobs.rb +22 -0
- data/lib/generators/project/db/seeds.rb +27 -0
- data/lib/generators/project/geodata/cities.csv +25305 -0
- data/lib/generators/project/geodata/countries.csv +250 -0
- data/lib/generators/project/public/401.html +75 -0
- data/lib/generators/project/public/404.html +67 -0
- data/lib/generators/project/public/422.html +67 -0
- data/lib/generators/project/public/500.html +66 -0
- data/lib/generators/project/public/_receiver.html +10 -0
- data/lib/generators/project/public/apple-touch-icon-precomposed.png +0 -0
- data/lib/generators/project/public/apple-touch-icon.png +0 -0
- data/lib/generators/project/public/favicon.ico +0 -0
- data/lib/generators/project/public/robots.txt +1 -0
- data/lib/happy_birthday.rb +5 -0
- data/lib/link.rb +16 -0
- data/lib/oauth/oauth.rb +72 -0
- data/lib/oauth/oauth_fb.rb +48 -0
- data/lib/oauth/oauth_gg.rb +50 -0
- data/lib/oauth/oauth_im.rb +51 -0
- data/lib/oauth/oauth_mr.rb +53 -0
- data/lib/oauth/oauth_vk.rb +3 -0
- data/lib/oauth/oauth_yx.rb +51 -0
- data/lib/openid/openid.rb +46 -0
- data/lib/openid/openid_st.rb +2 -0
- data/lib/phone_cutter.rb +9 -0
- data/lib/response.rb +51 -0
- data/lib/session_manager.rb +47 -0
- data/lib/sms_lib.rb +30 -0
- data/lib/social_networks.rb +328 -0
- data/lib/tasks/digital_heroes_startkit_tasks.rake +83 -0
- data/lib/telegram.rb +33 -0
- metadata +497 -0
@@ -0,0 +1,328 @@
|
|
1
|
+
class SocialNetworksLib
|
2
|
+
|
3
|
+
def side_signin sign_as, user_id, email, access_token, token_expired
|
4
|
+
# решил прикрепить скрепу!
|
5
|
+
if @current_user
|
6
|
+
access_card_exist = OauthAccessCard.find_by({oauth_name: sign_as, oauth_uid: user_id})
|
7
|
+
access_card = @current_user.oauth_access_cards.find_by({oauth_name: sign_as, oauth_uid: user_id})
|
8
|
+
if access_card.nil?
|
9
|
+
if access_card_exist
|
10
|
+
# спизданул
|
11
|
+
u = access_card_exist.user_card
|
12
|
+
access_card_exist.update(user_id: @current_user.id)
|
13
|
+
access_card = access_card_exist
|
14
|
+
# если забрал последнюю скрепу и нет больше карточек доступа - дезинтегрируем юзера
|
15
|
+
if u.access_cards_count == 0
|
16
|
+
u.destroy
|
17
|
+
else
|
18
|
+
u.set_active_card
|
19
|
+
end
|
20
|
+
else
|
21
|
+
# прикрепил
|
22
|
+
access_card = @current_user.oauth_access_cards.create({oauth_name: sign_as, oauth_uid: user_id, access_token: access_token, token_expired: token_expired})
|
23
|
+
end
|
24
|
+
else
|
25
|
+
# просто заапдейтил токен
|
26
|
+
access_card.update(access_token: access_token, token_expired: token_expired)
|
27
|
+
end
|
28
|
+
|
29
|
+
social_network_api :update_user_profile, sign_as, access_card # дополнение профиля пользователя данными из соц сети
|
30
|
+
set_cookies @current_user, access_card
|
31
|
+
|
32
|
+
else
|
33
|
+
|
34
|
+
access_card = OauthAccessCard.find_by({oauth_name: sign_as, oauth_uid: user_id})
|
35
|
+
|
36
|
+
if access_card
|
37
|
+
user = access_card.user_card
|
38
|
+
access_card.update(access_token: access_token, token_expired: token_expired)
|
39
|
+
social_network_api :update_user_profile, sign_as, access_card # дополнение профиля пользователя данными из соц сети
|
40
|
+
user.authenticate(user.password)
|
41
|
+
|
42
|
+
set_cookies user, access_card
|
43
|
+
|
44
|
+
else
|
45
|
+
|
46
|
+
# создаём клиента
|
47
|
+
user = UserCard.new get_params ActionController::Parameters.new({user: {password: SecureRandom.hex(8), oauth_access_cards_attributes: [oauth_name: sign_as, oauth_uid: user_id, access_token: access_token, token_expired: token_expired]}})
|
48
|
+
|
49
|
+
if user.save
|
50
|
+
# печеньки для кабеля
|
51
|
+
access_card = user.oauth_access_cards.first
|
52
|
+
set_cookies user, access_card
|
53
|
+
|
54
|
+
social_network_api :update_user_profile, sign_as, access_card # дополнение профиля пользователя данными из соц сети
|
55
|
+
|
56
|
+
else
|
57
|
+
msg = ''
|
58
|
+
user.errors.full_messages.each do |message|
|
59
|
+
msg += message
|
60
|
+
end
|
61
|
+
@result = {type: :bad, msg: msg}
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
redirect_to profile_path
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
def social_network_auth
|
74
|
+
social_network = params[:social_network]
|
75
|
+
rerequest = params[:rerequest].present?? {auth_type: 'rerequest'} : nil # https, reauthenticate, rerequest
|
76
|
+
social_network_auth_request social_network, :step1, rerequest
|
77
|
+
end
|
78
|
+
|
79
|
+
def social_network_verify_vk
|
80
|
+
result = verify_vk_fb_yandex_mailru_google params
|
81
|
+
side_signin :vk, result['user_id'], result['email'], result['access_token'], (DateTime.now + result['expires_in'].second).to_s(:db)
|
82
|
+
end
|
83
|
+
|
84
|
+
def social_network_verify_fb
|
85
|
+
result = verify_vk_fb_yandex_mailru_google params # предварительный результат, даёт только result['access_token'], result['expires_in']
|
86
|
+
# проверка привелегий которые пользователь разрешил с полным списком необходимых
|
87
|
+
# zuker_result = inspecting_access_token :fb, result['access_token']
|
88
|
+
# missed_permissions = get_missed_permissions :fb, zuker_result['data']['scopes']
|
89
|
+
# unless missed_permissions.empty?
|
90
|
+
# redirect_to social_network_auth_path(social_network: :fb, rerequest: true), method: :post, notice: "для использования сайта необходимо разрешить привелегии: #{missed_permissions.to_s}"
|
91
|
+
# else
|
92
|
+
reg_info = get_reg_info :fb, {access_token: result['access_token']} # а здесь мы получаем и дополнительную информацию
|
93
|
+
side_signin :fb, reg_info['id'], reg_info['email'], result['access_token'], (DateTime.now + result['expires_in'].second).to_s(:db)
|
94
|
+
# end
|
95
|
+
# declined_permissions = get_declined_permissions :fb, result['access_token']
|
96
|
+
|
97
|
+
#zuker_result = inspecting_access_token :fb, result['access_token']['data'] # цукермановый результат - это типа разшифровка полученного того результата с помощью полученного токена приложения
|
98
|
+
end
|
99
|
+
|
100
|
+
def social_network_verify_google
|
101
|
+
result = verify_vk_fb_yandex_mailru_google params
|
102
|
+
user_info = get_user_info :google, {access_token: result['access_token']} # а здесь мы получаем и дополнительную информацию
|
103
|
+
side_signin :google, user_info['id'], user_info['email'], result['access_token'], (DateTime.now + result['expires_in'].second).to_s(:db)
|
104
|
+
end
|
105
|
+
|
106
|
+
def social_network_verify_yandex
|
107
|
+
result = verify_vk_fb_yandex_mailru_google params
|
108
|
+
user_info = get_user_info :yandex, {oauth_token: result['access_token']} # а здесь мы получаем и дополнительную информацию
|
109
|
+
side_signin :yandex, user_info['id'], user_info['default_email'], result['access_token'], (DateTime.now + result['expires_in'].second).to_s(:db)
|
110
|
+
end
|
111
|
+
|
112
|
+
def social_network_verify_mailru
|
113
|
+
result = verify_vk_fb_yandex_mailru_google params
|
114
|
+
user_info = get_user_info :mailru, {session_key: result['access_token'], uid: result['x_mailru_vid']} # а здесь мы получаем и дополнительную информацию
|
115
|
+
side_signin :mailru, result['x_mailru_vid'], user_info['email'], result['access_token'], (DateTime.now + result['expires_in'].second).to_s(:db)
|
116
|
+
end
|
117
|
+
|
118
|
+
private
|
119
|
+
|
120
|
+
def check_social_network_access_token_expired uid
|
121
|
+
user = UserCard.find(uid)
|
122
|
+
redirect_to logout_path if DateTime.now > user.token_expired.to_datetime
|
123
|
+
end
|
124
|
+
|
125
|
+
def social_network_api req, social_network, access_card
|
126
|
+
|
127
|
+
case req
|
128
|
+
when :update_user_profile
|
129
|
+
case social_network
|
130
|
+
when :vk
|
131
|
+
add_info = get_user_info social_network, {access_token: access_card.access_token}
|
132
|
+
p add_info
|
133
|
+
# заливка инфы из соцсети (имя, фамилия, клёвая ава, возраст, пол)
|
134
|
+
|
135
|
+
sex = get_sex add_info['sex'], social_network
|
136
|
+
age = add_info['bdate'].present? ? (get_age DateTime.strptime(add_info['bdate'],'%d.%m.%Y')) : nil
|
137
|
+
|
138
|
+
params = {
|
139
|
+
firstname: add_info['first_name'],
|
140
|
+
lastname: add_info['last_name'],
|
141
|
+
# nickname: add_info['nickname'],
|
142
|
+
sex: sex,
|
143
|
+
age: age,
|
144
|
+
# city: add_info[:city][:title],
|
145
|
+
photourl: add_info['photo_100']
|
146
|
+
}
|
147
|
+
|
148
|
+
when :fb
|
149
|
+
add_info = get_user_info social_network, {:access_token => access_card.access_token}
|
150
|
+
picture = get_user_picture social_network, 100, 100, {:access_token => access_card.access_token}
|
151
|
+
age = add_info['birthday'].present? ? (get_age DateTime.strptime(add_info['birthday'],'%m/%d/%Y')) : nil
|
152
|
+
|
153
|
+
params = {
|
154
|
+
firstname: add_info['first_name'],
|
155
|
+
lastname: add_info['last_name'],
|
156
|
+
# nickname: add_info['middle_name'],
|
157
|
+
sex: add_info['gender'],
|
158
|
+
age: age,
|
159
|
+
# city: add_info[:location][:name],
|
160
|
+
photourl: picture['data']['url']
|
161
|
+
}
|
162
|
+
when :google
|
163
|
+
add_info = get_user_info social_network, {:access_token => access_card.access_token}
|
164
|
+
params = {
|
165
|
+
firstname: add_info['given_name'],
|
166
|
+
lastname: add_info['family_name'],
|
167
|
+
# nickname: add_info['name'],
|
168
|
+
sex: add_info['gender'],
|
169
|
+
age: nil,
|
170
|
+
# city: add_info[:location][:name],
|
171
|
+
photourl: add_info['picture']
|
172
|
+
}
|
173
|
+
when :yandex
|
174
|
+
add_info = get_user_info social_network, {:access_token => access_card.access_token}
|
175
|
+
picture = add_info['default_avatar_id'] == '0/0-0' ? nil : "https://avatars.yandex.net/get-yapic/#{add_info['default_avatar_id']}/islands-retina-50"
|
176
|
+
age = add_info['birthday'].present? ? (get_age DateTime.strptime(add_info['birthday'],'%Y-%m-%d')) : nil
|
177
|
+
|
178
|
+
params = {
|
179
|
+
firstname: add_info['first_name'],
|
180
|
+
lastname: add_info['last_name'],
|
181
|
+
# nickname: add_info['real_name'],
|
182
|
+
sex: add_info['sex'],
|
183
|
+
age: age,
|
184
|
+
# city: add_info[:location][:name],
|
185
|
+
photourl: picture
|
186
|
+
}
|
187
|
+
|
188
|
+
when :mailru
|
189
|
+
add_info = get_user_info social_network, {session_key: access_card.access_token, uid: access_card.oauth_uid} # а здесь мы получаем и дополнительную информацию
|
190
|
+
picture = add_info['has_pic'].to_i == 0 ? nil : add_info['pic_128']
|
191
|
+
sex = get_sex add_info['sex'], social_network
|
192
|
+
age = add_info['birthday'].present? ? (get_age DateTime.strptime(add_info['birthday'],'%d.%m.%Y')) : nil
|
193
|
+
|
194
|
+
params = {
|
195
|
+
firstname: add_info['first_name'],
|
196
|
+
lastname: add_info['last_name'],
|
197
|
+
# nickname: add_info['nick'],
|
198
|
+
sex: sex,
|
199
|
+
age: age,
|
200
|
+
# city: add_info[:location][:name],
|
201
|
+
photourl: picture
|
202
|
+
}
|
203
|
+
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
access_card.update(params)
|
208
|
+
end
|
209
|
+
|
210
|
+
def get_user_info social_network, access_params
|
211
|
+
case social_network
|
212
|
+
when :vk
|
213
|
+
uri = URI "#{CONFIG[social_network][:api][:uri]}#{CONFIG[social_network][:api][:users_get][:prefix]}"
|
214
|
+
params = CONFIG[social_network][:api][:united_params].merge!(CONFIG[social_network][:api][:users_get][:params])
|
215
|
+
params.merge!(access_params) unless access_params.nil?
|
216
|
+
uri.query = URI.encode_www_form params
|
217
|
+
result = Net::HTTP.get_response uri
|
218
|
+
|
219
|
+
ActiveSupport::JSON.decode(result.body)['response'][0]
|
220
|
+
when :fb
|
221
|
+
uri = URI CONFIG[social_network][:api][:uri]
|
222
|
+
params = CONFIG[social_network][:api][:get_user_info][:params]
|
223
|
+
params.merge!(access_params) unless access_params.nil?
|
224
|
+
uri.query = URI.encode_www_form params
|
225
|
+
result = Net::HTTP.get_response uri
|
226
|
+
|
227
|
+
ActiveSupport::JSON.decode(result.body)
|
228
|
+
when :google
|
229
|
+
uri = URI CONFIG[social_network][:api][:get_user_info][:uri]
|
230
|
+
params = access_params
|
231
|
+
uri.query = URI.encode_www_form params
|
232
|
+
result = Net::HTTP.get_response uri
|
233
|
+
|
234
|
+
ActiveSupport::JSON.decode(result.body)
|
235
|
+
when :yandex
|
236
|
+
uri = URI CONFIG[social_network][:api][:get_user_info][:uri]
|
237
|
+
params = CONFIG[social_network][:api][:get_user_info][:params]
|
238
|
+
params.merge!(access_params) unless access_params.nil?
|
239
|
+
uri.query = URI.encode_www_form params
|
240
|
+
result = Net::HTTP.get_response uri
|
241
|
+
|
242
|
+
ActiveSupport::JSON.decode(result.body)
|
243
|
+
when :mailru
|
244
|
+
uri = URI CONFIG[social_network][:api][:get_user_info][:uri]
|
245
|
+
params = CONFIG[social_network][:api][:get_user_info][:params]
|
246
|
+
params.merge!(access_params) unless access_params.nil?
|
247
|
+
sig = Digest::MD5.hexdigest params.sort.map{|k,v| "#{k}=#{v}"}.join() + CONFIG[social_network][:auth][:step2][:client_secret] # охуенная подпись !
|
248
|
+
params = params.merge({sig: sig})
|
249
|
+
uri.query = URI.encode_www_form params
|
250
|
+
result = Net::HTTP.get_response uri
|
251
|
+
|
252
|
+
ActiveSupport::JSON.decode(result.body)[0]
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
def get_user_picture social_network, width, height, access_params
|
258
|
+
case social_network
|
259
|
+
when :fb
|
260
|
+
uri = URI "#{CONFIG[social_network][:api][:uri]}#{CONFIG[social_network][:api][:get_picture][:prefix]}"
|
261
|
+
params = {width: width, height: height, redirect: false}
|
262
|
+
params.merge!(access_params) unless access_params.nil?
|
263
|
+
uri.query = URI.encode_www_form params
|
264
|
+
result = Net::HTTP.get_response uri
|
265
|
+
|
266
|
+
ActiveSupport::JSON.decode(result.body)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
def get_reg_info social_network, access_params
|
271
|
+
case social_network
|
272
|
+
when :fb
|
273
|
+
uri = URI CONFIG[social_network][:api][:uri]
|
274
|
+
params = CONFIG[social_network][:api][:get_reg_info][:params]
|
275
|
+
params.merge!(access_params) unless access_params.nil?
|
276
|
+
uri.query = URI.encode_www_form params
|
277
|
+
result = Net::HTTP.get_response uri
|
278
|
+
|
279
|
+
ActiveSupport::JSON.decode(result.body)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def get_missed_permissions social_network, scopes
|
284
|
+
CONFIG[social_network][:auth][:step1][:scope].split(',') - scopes
|
285
|
+
end
|
286
|
+
|
287
|
+
def get_declined_permissions social_network, access_token
|
288
|
+
case social_network
|
289
|
+
when :fb
|
290
|
+
uri = URI "#{CONFIG[social_network][:api][:uri]}#{CONFIG[social_network][:api][:check_permissions][:prefix]}"
|
291
|
+
params = {access_token: access_token}
|
292
|
+
uri.query = URI.encode_www_form params
|
293
|
+
result = Net::HTTP.get_response uri
|
294
|
+
|
295
|
+
permissions = ActiveSupport::JSON.decode(result.body)['data'].map { |permission_obj| permission_obj['permission'] if permission_obj['status'] == 'declined' }.compact
|
296
|
+
|
297
|
+
permissions.empty?? nil : permissions
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def get_sex sex, network
|
302
|
+
case network
|
303
|
+
when :vk
|
304
|
+
case sex.to_i
|
305
|
+
when 1
|
306
|
+
:female
|
307
|
+
when 2
|
308
|
+
:male
|
309
|
+
else
|
310
|
+
nil
|
311
|
+
end
|
312
|
+
when :mailru
|
313
|
+
case sex.to_i
|
314
|
+
when 0
|
315
|
+
:male
|
316
|
+
when 1
|
317
|
+
:female
|
318
|
+
else
|
319
|
+
nil
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
def get_age bday
|
325
|
+
TimeDifference.between(bday, DateTime.now).in_years.floor
|
326
|
+
end
|
327
|
+
|
328
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
namespace :db do
|
2
|
+
desc "reborn database"
|
3
|
+
task :fuck do
|
4
|
+
begin
|
5
|
+
Rake::Task['db:environment:set'].invoke('RAILS_ENV=development')
|
6
|
+
Rake::Task['db:drop'].invoke
|
7
|
+
rescue Exception => e
|
8
|
+
p e.message
|
9
|
+
end
|
10
|
+
Rake::Task['db:create'].invoke
|
11
|
+
Rake::Task['db:migrate'].invoke
|
12
|
+
Rake::Task['db:seed'].invoke
|
13
|
+
# страны города тоже в посев
|
14
|
+
Rake::Task['geodata:cc'].invoke
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
namespace :geodata do
|
19
|
+
desc "countries cities deploy"
|
20
|
+
task :cc do
|
21
|
+
`mysqlimport -u#{CONFIG[:db][:login]} -p#{CONFIG[:db][:pass]} --local --fields-optionally-enclosed-by='"' --fields-terminated-by=',' --lines-terminated-by='\n' #{CONFIG[:db][:name]} '#{Rails.root}/geodata/countries.csv'`
|
22
|
+
`mysqlimport -u#{CONFIG[:db][:login]} -p#{CONFIG[:db][:pass]} --local --fields-optionally-enclosed-by='"' --fields-terminated-by=',' --lines-terminated-by='\n' #{CONFIG[:db][:name]} '#{Rails.root}/geodata/cities.csv'`
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
namespace :cap do
|
27
|
+
desc 'корректирование конфигурационных файлов для деплоя'
|
28
|
+
task :conf_update do
|
29
|
+
# загрузка конфига в полноценный символьный хэш
|
30
|
+
require 'active_support/core_ext/hash'
|
31
|
+
CAP_CONFIG = YAML.load_file(File.expand_path('config/capistrano.yml', Rails.root)).with_indifferent_access
|
32
|
+
|
33
|
+
# получение девственных файлов
|
34
|
+
CAP_CONFIG[:sh][:files].each do |filename|
|
35
|
+
# получение девственных файлов
|
36
|
+
sh "cp #{CAP_CONFIG[:sh][:virgin_dir]}#{filename} #{CAP_CONFIG[:conf][:dir]}"
|
37
|
+
|
38
|
+
path = "#{CAP_CONFIG[:conf][:dir]}#{filename}"
|
39
|
+
if File.exist? path
|
40
|
+
f = open(path, 'r+')
|
41
|
+
str = f.read
|
42
|
+
# замена переменных на реальные значения
|
43
|
+
CAP_CONFIG[:conf][:vars].each do |variable, value|
|
44
|
+
str.gsub! Regexp.new(variable, Regexp::MULTILINE), value
|
45
|
+
end
|
46
|
+
# теперь ты опустошитель, брат
|
47
|
+
f.truncate 0
|
48
|
+
# перемотка
|
49
|
+
f.rewind
|
50
|
+
# запись
|
51
|
+
f.write str
|
52
|
+
f.close
|
53
|
+
else
|
54
|
+
err path
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
CAP_CONFIG[:conf][:files].each do |k, filename|
|
59
|
+
# получение девственных файлов
|
60
|
+
sh "cp #{CAP_CONFIG[:conf][:virgin_dir]}#{filename} #{CAP_CONFIG[:conf][:dir]}#{filename}"
|
61
|
+
|
62
|
+
path = "#{CAP_CONFIG[:conf][:dir]}#{filename}"
|
63
|
+
if File.exist? path
|
64
|
+
f = open(path, 'r+')
|
65
|
+
str = f.read
|
66
|
+
# замена переменных на реальные значения
|
67
|
+
CAP_CONFIG[:conf][:vars].each do |variable, value|
|
68
|
+
str.gsub! Regexp.new(variable, Regexp::MULTILINE), value
|
69
|
+
end
|
70
|
+
# теперь ты опустошитель, брат
|
71
|
+
f.truncate 0
|
72
|
+
# перемотка
|
73
|
+
f.rewind
|
74
|
+
# запись
|
75
|
+
f.write str
|
76
|
+
f.close
|
77
|
+
else
|
78
|
+
err path
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
data/lib/telegram.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
class Telegram
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
def sendMessage(message, channel)
|
7
|
+
|
8
|
+
uri = URI "#{CONFIG[:telegram][:bot_path]}#{CONFIG[:telegram][:bot_token]}/sendMessage"
|
9
|
+
params = {
|
10
|
+
chat_id: CONFIG[:telegram][:chat_ids][channel],
|
11
|
+
text: message
|
12
|
+
}
|
13
|
+
uri.query = URI.encode_www_form params
|
14
|
+
|
15
|
+
res = Net::HTTP.get_response(uri)
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def sendSticker(sticker, channel)
|
20
|
+
|
21
|
+
uri = URI "#{CONFIG[:telegram][:bot_path]}#{CONFIG[:telegram][:bot_token]}/sendSticker"
|
22
|
+
|
23
|
+
params = {
|
24
|
+
chat_id: CONFIG[:telegram][:chat_ids][channel],
|
25
|
+
sticker: CONFIG[:telegram][:stickers][sticker]
|
26
|
+
}
|
27
|
+
uri.query = URI.encode_www_form params
|
28
|
+
|
29
|
+
res = Net::HTTP.get_response(uri)
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|