digital_heroes_startkit 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +37 -0
  4. data/Rakefile +36 -0
  5. data/app/assets/config/digital_heroes_startkit_manifest.js +0 -0
  6. data/app/assets/javascripts/authorization.coffee +79 -0
  7. data/app/assets/javascripts/avatar.coffee +16 -0
  8. data/app/assets/javascripts/datepicker.js +2 -0
  9. data/app/assets/javascripts/digital_heroes_startkit/cable.js +13 -0
  10. data/app/assets/javascripts/digital_heroes_startkit/channels/pills.coffee +23 -0
  11. data/app/assets/javascripts/digital_heroes_startkit/input.coffee +5 -0
  12. data/app/assets/javascripts/digital_heroes_startkit/pills.coffee +2 -0
  13. data/app/assets/javascripts/digital_heroes_startkit/snap.svg-min.js +21 -0
  14. data/app/assets/javascripts/digital_heroes_startkit.js +26 -0
  15. data/app/assets/javascripts/profile.coffee +53 -0
  16. data/app/assets/javascripts/profile_geodata.coffee +68 -0
  17. data/app/assets/javascripts/reg_fields_checkup.coffee +96 -0
  18. data/app/assets/javascripts/registration.coffee +35 -0
  19. data/app/assets/javascripts/resurrection.coffee +20 -0
  20. data/app/channels/application_cable/channel.rb +4 -0
  21. data/app/channels/application_cable/connection.rb +4 -0
  22. data/app/channels/pills_channel.rb +10 -0
  23. data/app/controllers/avatars_controller.rb +11 -0
  24. data/app/controllers/clients_controller.rb +62 -0
  25. data/app/controllers/email_access_cards_controller.rb +28 -0
  26. data/app/controllers/geodata_controller.rb +84 -0
  27. data/app/controllers/nickname_access_cards_controller.rb +30 -0
  28. data/app/controllers/oauth_controller.rb +178 -0
  29. data/app/controllers/openid_controller.rb +124 -0
  30. data/app/controllers/phone_access_cards_controller.rb +28 -0
  31. data/app/controllers/profile_controller.rb +114 -0
  32. data/app/controllers/response_controller.rb +17 -0
  33. data/app/controllers/start_kit_controller.rb +86 -0
  34. data/app/controllers/user_cards_controller.rb +305 -0
  35. data/app/jobs/log_analyzer_job.rb +50 -0
  36. data/app/jobs/password_resurrection_kill_job.rb +9 -0
  37. data/app/mailers/admin_mailer.rb +9 -0
  38. data/app/mailers/client_mailer.rb +3 -0
  39. data/app/mailers/kreator_mailer.rb +9 -0
  40. data/app/mailers/manager_mailer.rb +9 -0
  41. data/app/mailers/prometeus_mailer.rb +16 -0
  42. data/app/mailers/user_cards_mailer.rb +9 -0
  43. data/app/models/admin.rb +3 -0
  44. data/app/models/avatar.rb +23 -0
  45. data/app/models/city.rb +7 -0
  46. data/app/models/client.rb +31 -0
  47. data/app/models/country.rb +7 -0
  48. data/app/models/delayed_job.rb +20 -0
  49. data/app/models/email_access_card.rb +30 -0
  50. data/app/models/kreator.rb +3 -0
  51. data/app/models/log_error.rb +56 -0
  52. data/app/models/log_error_type.rb +3 -0
  53. data/app/models/manager.rb +3 -0
  54. data/app/models/nickname_access_card.rb +18 -0
  55. data/app/models/oauth_access_card.rb +38 -0
  56. data/app/models/phone_access_card.rb +19 -0
  57. data/app/models/prometeus.rb +50 -0
  58. data/app/models/user_card.rb +158 -0
  59. data/app/views/admin_mailer/greetings_email.html.erb +191 -0
  60. data/app/views/client_mailer/greetings_email.html.erb +191 -0
  61. data/app/views/kreator_mailer/greetings_email.html.erb +191 -0
  62. data/app/views/manager_mailer/greetings_email.html.erb +191 -0
  63. data/app/views/oauth/verify.slim +1 -0
  64. data/app/views/profile/_add_avatar.slim +12 -0
  65. data/app/views/profile/_user_profile.slim +95 -0
  66. data/app/views/profile/index.slim +12 -0
  67. data/app/views/user_cards/authorization.slim +72 -0
  68. data/app/views/user_cards/confirmation_but_access_code.slim +7 -0
  69. data/app/views/user_cards/confirmation_complete.slim +7 -0
  70. data/app/views/user_cards/registration.slim +86 -0
  71. data/app/views/user_cards/resurrection.slim +19 -0
  72. data/app/views/user_cards/resurrection_but_access_code.slim +7 -0
  73. data/app/views/user_cards/resurrection_no_access_code.slim +7 -0
  74. data/app/views/user_cards_mailer/email.html.erb +191 -0
  75. data/app/views/user_cards_mailer/resurrection.html.erb +191 -0
  76. data/config/initializers/session_manager.rb +2 -0
  77. data/config/routes.rb +53 -0
  78. data/lib/access_control.rb +3 -0
  79. data/lib/digital_heroes_startkit/engine.rb +25 -0
  80. data/lib/digital_heroes_startkit/version.rb +3 -0
  81. data/lib/digital_heroes_startkit.rb +5 -0
  82. data/lib/generators/digital_heroes_startkit/install_generator.rb +61 -0
  83. data/lib/generators/project/Capfile +36 -0
  84. data/lib/generators/project/Procfile +3 -0
  85. data/lib/generators/project/app/assets/stylesheets/application.scss +16 -0
  86. data/lib/generators/project/app/assets/stylesheets/base/_auth.scss +37 -0
  87. data/lib/generators/project/app/assets/stylesheets/base/_buttons.scss +62 -0
  88. data/lib/generators/project/app/assets/stylesheets/base/_checkbox.scss +71 -0
  89. data/lib/generators/project/app/assets/stylesheets/base/_datepicker.scss +620 -0
  90. data/lib/generators/project/app/assets/stylesheets/base/_form.scss +81 -0
  91. data/lib/generators/project/app/assets/stylesheets/base/_notice.scss +14 -0
  92. data/lib/generators/project/app/assets/stylesheets/base/_pills.scss +39 -0
  93. data/lib/generators/project/app/assets/stylesheets/base/_profile.scss +67 -0
  94. data/lib/generators/project/app/assets/stylesheets/base/_reset.scss +49 -0
  95. data/lib/generators/project/app/assets/stylesheets/base/_social.scss +52 -0
  96. data/lib/generators/project/app/assets/stylesheets/base/_user.scss +0 -0
  97. data/lib/generators/project/app/assets/stylesheets/base/_user_avatar.scss +18 -0
  98. data/lib/generators/project/app/assets/stylesheets/base/styles.scss.txt +35 -0
  99. data/lib/generators/project/app/assets/stylesheets/plugins/sumoselect.scss +296 -0
  100. data/lib/generators/project/app/controllers/application_controller.rb +3 -0
  101. data/lib/generators/project/app/views/layouts/_counts.html.erb +29 -0
  102. data/lib/generators/project/app/views/layouts/_footer.slim +6 -0
  103. data/lib/generators/project/app/views/layouts/_head.slim +7 -0
  104. data/lib/generators/project/app/views/layouts/_header.slim +47 -0
  105. data/lib/generators/project/app/views/layouts/_mobile_menu.slim +11 -0
  106. data/lib/generators/project/app/views/layouts/application.slim +26 -0
  107. data/lib/generators/project/app/views/layouts/mailer.html.erb +13 -0
  108. data/lib/generators/project/app/views/layouts/mailer.text.erb +1 -0
  109. data/lib/generators/project/config/application.access.yml +66 -0
  110. data/lib/generators/project/config/application.db.yml +5 -0
  111. data/lib/generators/project/config/application.google.yml +3 -0
  112. data/lib/generators/project/config/application.oauth.yml +135 -0
  113. data/lib/generators/project/config/application.robokassa.yml +10 -0
  114. data/lib/generators/project/config/application.sendgrid.yml +3 -0
  115. data/lib/generators/project/config/application.telegram.yml +22 -0
  116. data/lib/generators/project/config/application.yml +28 -0
  117. data/lib/generators/project/config/cable.yml +6 -0
  118. data/lib/generators/project/config/capistrano.yml +78 -0
  119. data/lib/generators/project/config/database.yml +52 -0
  120. data/lib/generators/project/config/deploy/application.secrets.yml +4 -0
  121. data/lib/generators/project/config/deploy/domain.crt +92 -0
  122. data/lib/generators/project/config/deploy/domain.key +51 -0
  123. data/lib/generators/project/config/deploy/nginx.conf +50 -0
  124. data/lib/generators/project/config/deploy/production.rb +67 -0
  125. data/lib/generators/project/config/deploy/secrets.yml +32 -0
  126. data/lib/generators/project/config/deploy/secrets.yml.enc +1 -0
  127. data/lib/generators/project/config/deploy/secrets.yml.key +1 -0
  128. data/lib/generators/project/config/deploy/staging.rb +61 -0
  129. data/lib/generators/project/config/deploy/virgin_conf/database.yml +42 -0
  130. data/lib/generators/project/config/deploy/virgin_conf/nginx_site.conf +47 -0
  131. data/lib/generators/project/config/deploy/virgin_conf/nginx_site_ssl.conf +57 -0
  132. data/lib/generators/project/config/deploy/virgin_conf/postfix.cf +685 -0
  133. data/lib/generators/project/config/deploy/virgin_conf/production.rb +67 -0
  134. data/lib/generators/project/config/deploy/virgin_conf/puma.rb +66 -0
  135. data/lib/generators/project/config/deploy/virgin_sh/capistrano.sh +18 -0
  136. data/lib/generators/project/config/deploy/virgin_sh/foreman.sh +19 -0
  137. data/lib/generators/project/config/deploy/virgin_sh/rvm_install.sh +10 -0
  138. data/lib/generators/project/config/deploy.rb +377 -0
  139. data/lib/generators/project/config/environments/development.rb +91 -0
  140. data/lib/generators/project/config/environments/production.rb +142 -0
  141. data/lib/generators/project/config/initializers/session_store.rb +3 -0
  142. data/lib/generators/project/config/locales/ru.yml +444 -0
  143. data/lib/generators/project/db/migrate/10_create_user_cards.rb +19 -0
  144. data/lib/generators/project/db/migrate/12_create_email_access_cards.rb +15 -0
  145. data/lib/generators/project/db/migrate/13_create_nickname_access_cards.rb +15 -0
  146. data/lib/generators/project/db/migrate/14_create_phone_access_cards.rb +16 -0
  147. data/lib/generators/project/db/migrate/15_create_oauth_access_cards.rb +19 -0
  148. data/lib/generators/project/db/migrate/1_create_kreators.rb +9 -0
  149. data/lib/generators/project/db/migrate/21_create_avatars.rb +12 -0
  150. data/lib/generators/project/db/migrate/30_create_countries.rb +12 -0
  151. data/lib/generators/project/db/migrate/32_create_cities.rb +12 -0
  152. data/lib/generators/project/db/migrate/3_create_admins.rb +9 -0
  153. data/lib/generators/project/db/migrate/44_add_sessions_table.rb +12 -0
  154. data/lib/generators/project/db/migrate/4_create_managers.rb +10 -0
  155. data/lib/generators/project/db/migrate/5_create_clients.rb +17 -0
  156. data/lib/generators/project/db/migrate/60_create_log_error_types.rb +9 -0
  157. data/lib/generators/project/db/migrate/61_create_log_errors.rb +12 -0
  158. data/lib/generators/project/db/migrate/78_create_delayed_jobs.rb +22 -0
  159. data/lib/generators/project/db/seeds.rb +27 -0
  160. data/lib/generators/project/geodata/cities.csv +25305 -0
  161. data/lib/generators/project/geodata/countries.csv +250 -0
  162. data/lib/generators/project/public/401.html +75 -0
  163. data/lib/generators/project/public/404.html +67 -0
  164. data/lib/generators/project/public/422.html +67 -0
  165. data/lib/generators/project/public/500.html +66 -0
  166. data/lib/generators/project/public/_receiver.html +10 -0
  167. data/lib/generators/project/public/apple-touch-icon-precomposed.png +0 -0
  168. data/lib/generators/project/public/apple-touch-icon.png +0 -0
  169. data/lib/generators/project/public/favicon.ico +0 -0
  170. data/lib/generators/project/public/robots.txt +1 -0
  171. data/lib/happy_birthday.rb +5 -0
  172. data/lib/link.rb +16 -0
  173. data/lib/oauth/oauth.rb +72 -0
  174. data/lib/oauth/oauth_fb.rb +48 -0
  175. data/lib/oauth/oauth_gg.rb +50 -0
  176. data/lib/oauth/oauth_im.rb +51 -0
  177. data/lib/oauth/oauth_mr.rb +53 -0
  178. data/lib/oauth/oauth_vk.rb +3 -0
  179. data/lib/oauth/oauth_yx.rb +51 -0
  180. data/lib/openid/openid.rb +46 -0
  181. data/lib/openid/openid_st.rb +2 -0
  182. data/lib/phone_cutter.rb +9 -0
  183. data/lib/response.rb +51 -0
  184. data/lib/session_manager.rb +47 -0
  185. data/lib/sms_lib.rb +30 -0
  186. data/lib/social_networks.rb +328 -0
  187. data/lib/tasks/digital_heroes_startkit_tasks.rake +83 -0
  188. data/lib/telegram.rb +33 -0
  189. metadata +497 -0
@@ -0,0 +1,305 @@
1
+ class UserCardsController < ResponseController
2
+
3
+ require 'sms_lib'
4
+
5
+ require 'digest'
6
+
7
+ def authorization
8
+ @access_cards_placeholder = UserCard.access_cards_placeholder
9
+ end
10
+ def registration
11
+ end
12
+
13
+ def confirmation
14
+ template = 'user_cards/confirmation_but_access_code'
15
+
16
+ if params[:access_code].present? && params[:id].present?
17
+ access_code = params[:access_code]
18
+ # мощная проверка - мощный результат ! вместе сделаем Мощный рывок вперёд ! )) за Жириновского !!11
19
+ user_card = UserCard.find_by(id: params[:id])
20
+ if user_card.present? && user_card.passive?
21
+ if user_card.confirm_access_code == access_code
22
+ user_card.confirm
23
+ template = 'user_cards/confirmation_complete'
24
+ end
25
+ end
26
+ end
27
+
28
+ render template: template
29
+
30
+ end
31
+
32
+ def login
33
+ # если не мыло то вырезается всякий код страны
34
+ if (/@/ =~ params[:login]).nil?
35
+ params[:login] = params[:login].to_s.phone_cutter_cc
36
+ end
37
+
38
+ # предварительное определение типа логина
39
+ login_type_result = login_type params[:login]
40
+ access_card = login_type_result[:access_card]
41
+ sign_as = login_type_result[:sign_as]
42
+
43
+ disclaimer = login_type_result[:sign_as].nil? ? CONFIG[:access_cards_info][:bad_login_fiasco_disclaimer] : CONFIG[:access_cards_info][:bad_login_disclaimer].sub(/мистер/, I18n.t(login_type_result[:sign_as], scope: 'access_cards'))
44
+ @response.add_var ({disclaimer: disclaimer })
45
+
46
+ unless access_card.nil?
47
+ user_card = access_card.user_card
48
+
49
+ if user_card.authenticate(params[:password])
50
+ user_card.authorize! access_card
51
+ current_user
52
+
53
+ @response.set_url profile_path
54
+ @response.add_detail 'login'
55
+ @response.set_state 'ok'
56
+ else
57
+ # пароль не подходит
58
+ session[:ressurection_uid] = user_card.id
59
+
60
+ @response.add_var ({have_email: user_card.email_access_cards.where.not(value: nil).any?})
61
+ @response.add_detail 'bad_password'
62
+ end
63
+ else
64
+ # регистрация + авторизация
65
+ if sign_as.present? && sign_as != :id
66
+ # user = Client.create get_params ActionController::Parameters.new({user: {password: params[:password], "#{sign_as.downcase}_access_cards_attributes" => [{value: params[:login]}]}})
67
+ # if user
68
+ # access_card = "#{sign_as.downcase}AccessCard".classify.constantize.find_by(user_id: user.id)
69
+ # user.user_card.authorize! access_card
70
+
71
+ @response.set_url root_path
72
+ @response.add_detail 'reg'
73
+ @response.set_state 'ok'
74
+ # end
75
+ else
76
+ # вводи норм логин
77
+ CONFIG[:access_by].each do |by, options|
78
+ if /#{options[:nearly]}/i =~ params[:sign_as]
79
+ disclaimer = options[:disclaimer]
80
+ break
81
+ end
82
+ end
83
+
84
+ @response.add_detail 'bad_login'
85
+ @response.set_state 'bad'
86
+ end
87
+ # end
88
+ end
89
+
90
+ send_response
91
+
92
+ end
93
+
94
+ def add_access_card
95
+ params[:classname].constantize.create(user_id: @current_user.id)
96
+
97
+ render json: {answer: 'ok'}
98
+ end
99
+
100
+ def remove_access_card
101
+ params[:classname].constantize.find(params[:id]).destroy
102
+
103
+ render json: {answer: 'ok'}
104
+ end
105
+
106
+ def send_phone_confirmation
107
+ phone = params[:phone].to_s.phone_cutter
108
+ if phone =~ /^\d{10}$/
109
+ result[:code] = rand 1000..9999
110
+ session[:code] = encode64 code
111
+ # sms_phone_verify_code phone, code
112
+ # @code = code
113
+ session[:sms_verify_attempt] = 5
114
+ session[:phone] = phone
115
+ @response.set_state 'ok'
116
+ else
117
+ @response.add_detail 'неправильный номер'
118
+ end
119
+
120
+ send_response
121
+
122
+ end
123
+
124
+ def verify_phone_confirmation
125
+ result = {answer: 'ok'}
126
+
127
+ if session[:sms_verify_attempt] < 2
128
+ session[:code] = nil
129
+ result[:answer] = 'attemptsgone'
130
+ else
131
+ if (encode64 params[:code]) == session[:code]
132
+ if @current_user
133
+ access_card = @current_user.phone_access_cards.find_by(value: params[:phone])
134
+ if access_card
135
+ access_card.update(verified: 1)
136
+ else
137
+ result[:answer] = 'phonelost'
138
+ end
139
+ else
140
+ result[:answer] = 'userlost'
141
+ end
142
+ else
143
+ result[:answer] = 'wrongcode'
144
+
145
+ session[:sms_verify_attempt] -= 1
146
+ end
147
+ end
148
+
149
+ result[:attempt] = session[:sms_verify_attempt]
150
+
151
+ render json: result
152
+
153
+ end
154
+
155
+ def password_reset
156
+
157
+ details = []
158
+ state = 'ok'
159
+
160
+ resurrection = SecureRandom.hex(8)
161
+ user_card = UserCard.find_by(id: session[:ressurection_uid])
162
+ if user_card
163
+ begin
164
+ unless user_card.update(resurrection: resurrection)
165
+ state = 'shit'
166
+ details << 'невозможно записать код доступа'
167
+ else
168
+ uri = URI.join(request.base_url, 'resurrection')
169
+ params = { :resurrection_code => resurrection }
170
+ uri.query = URI.encode_www_form(params)
171
+
172
+ UserCardsMailer.resurrection(user_card.my_email, uri.to_s).deliver_now
173
+
174
+ # снаряжаем фоновую задачу правильным образом !
175
+ kill_time = DateTime.now + CONFIG[:resurrection_ttl].to_i.minutes
176
+ PasswordResurrectionKillJob.set(wait_until: kill_time).perform_later(user_card.id)
177
+ end
178
+ rescue Exception => error
179
+ state = 'shit'
180
+ details << error.message
181
+ end
182
+ else
183
+ state = 'shit'
184
+ details << 'пользователь не найден'
185
+ end
186
+
187
+ render json: {state: state, details: details}
188
+
189
+ end
190
+
191
+ def resurrection
192
+ if params[:resurrection_code].present?
193
+ @resurrection_code = params[:resurrection_code]
194
+ user_card = UserCard.find_by(resurrection: params[:resurrection_code])
195
+ if user_card.nil?
196
+ render template: 'user_cards/resurrection_but_access_code'
197
+ end
198
+ else
199
+ render template: 'user_cards/resurrection_no_access_code'
200
+ end
201
+ end
202
+
203
+ def resurrection_password_update
204
+ user_card = UserCard.find_by(resurrection: params[:resurrection_code])
205
+ unless user_card.nil?
206
+ if user_card.update(password: params[:password], resurrection: nil)
207
+ # require 'authorizer'
208
+ # authorizer = Authorizer.new
209
+ # authorizer.authorize! user_card, user_card.email_access_cards.first
210
+ user_card.authorize! user_card.email_access_cards.first
211
+ current_user
212
+
213
+ redirect_to root_url
214
+ end
215
+ end
216
+ end
217
+
218
+ def check_login_by
219
+ value = params[:by] == 'phone' ? params[:value].to_s.phone_cutter : params[:value]
220
+ unless (/#{CONFIG[:access_by][params[:by].to_sym][:truly]}/i =~ value).nil?
221
+ # проверка на совпадение логина в любом из полей указанных в конфиге (разрешённых для аутентификации) - при совпадении авторизация, в противном случае - регистрация
222
+ value.downcase! if value.class.name == 'String' # к общему знаменателю все эти строки
223
+ state = "#{params[:by]}AccessCard".classify.constantize.find_by(value: value).nil? ? 'reg' : 'login'
224
+ # подтверждение по смс
225
+ state = 'reg' if session[params[:by]] == value
226
+ else
227
+ state = 'bad_login'
228
+ end
229
+
230
+ @response.add_var ({disclaimer: CONFIG[:access_by][params[:by].to_sym][:disclaimer], fieldname: params[:by]})
231
+
232
+ @response.set_state state
233
+
234
+ send_response
235
+ end
236
+
237
+ def check_login
238
+ login_type_result = login_type params[:login]
239
+ access_card = login_type_result[:access_card]
240
+ sign_as = login_type_result[:sign_as]
241
+
242
+ state = 'bad_login'
243
+ unless sign_as.nil?
244
+ unless access_card.nil?
245
+ state = 'login'
246
+ else
247
+ state = 'reg'
248
+ end
249
+ end
250
+
251
+ render json: {state: state, sign_as: sign_as}
252
+ end
253
+
254
+ def login_type login
255
+ # предварительное определение типа логина
256
+ access_card = nil
257
+ sign_as = nil
258
+ CONFIG[:access_by].each do |by, options|
259
+ unless (/#{options[:truly]}/i =~ login).nil?
260
+ # проверка на совпадение логина в любом из полей указанных в конфиге (разрешённых для аутентификации) - при совпадении авторизация, в противном случае - регистрация
261
+ login.downcase! if by == 'email' # к общему знаменателю тока мыло
262
+ access_card = "#{by}AccessCard".classify.constantize.find_by(value: login)
263
+ sign_as = by
264
+ break
265
+ end
266
+ end
267
+
268
+ {access_card: access_card, sign_as: sign_as}
269
+ end
270
+
271
+ def check_password_line
272
+ begin
273
+ if /#{CONFIG[:access_cards_info][:password_line]}/ =~ params[:value]
274
+ @response.set_state 'ok'
275
+ else
276
+ @response.add_detail CONFIG[:access_cards_info][:password_disclaimer]
277
+ end
278
+ rescue Exception => error
279
+ @response.error_state error.message
280
+ end
281
+
282
+ send_response
283
+ end
284
+
285
+ def offline
286
+ user = UserCard.find_by(id: params[:uid])
287
+ user.update({online: false}) unless user.nil?
288
+ end
289
+
290
+ def logout
291
+ if @current_user_card
292
+ @current_user_card.update({online: false})
293
+ reset_session
294
+ end
295
+
296
+ redirect_to root_url
297
+ end
298
+
299
+ private
300
+
301
+ def encode64 code
302
+ Digest::SHA256.base64digest "#{code} и сольцы пизданём"
303
+ end
304
+
305
+ end
@@ -0,0 +1,50 @@
1
+ class LogAnalyzerJob < ApplicationJob
2
+ queue_as :log_analyzer
3
+
4
+ def perform
5
+
6
+ Delayed::Worker.logger.debug('стартуем')
7
+ CONFIG[:logs].each do |name, path|
8
+ Delayed::Worker.logger.debug(path)
9
+ if File.exist?("#{Rails.root}#{path}")
10
+ log = File.read("#{Rails.root}#{path}")
11
+ log.scan(/(^I,[^\n]+\n(F,[^\n]+\n)+)/m).each do |error|
12
+ Delayed::Worker.logger.debug('получение времени ошибки')
13
+ datetime = (DateTime.parse error[0].match(/\d{4}\-\d{2}\-\d{2}T\d{2}:\d{2}:\d{2}/)[0]).to_s(:db)
14
+ Delayed::Worker.logger.debug(datetime)
15
+ Delayed::Worker.logger.debug('получение инфы ошибки')
16
+ e = error[0].gsub(/F,.+FATAL -- :\n/, '').gsub(/[FI],.+(FATAL|INFO) -- :\s/, '')
17
+ Delayed::Worker.logger.debug(e)
18
+ Delayed::Worker.logger.debug("занесение ошибки в #{name}")
19
+ Delayed::Worker.logger.debug(LogErrorType.find_by(value: name))
20
+ LogErrorType.find_by(value: name).log_errors.create(value: e, date: datetime)
21
+ end
22
+
23
+ # puma
24
+ # log.scan(/(Started.{20,3000}(Completed 400|Completed 500|RoutingError).+?)(Started|\Z)/m).each do |error|
25
+ # LogErrorType.find_by(value: name).log_errors.create(value: error[0], date: (DateTime.parse error[0].match(/\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}/)[0]).to_s(:db))
26
+ # end
27
+ # dj
28
+ # log.scan(/^E.+$/).each do |error|
29
+ # LogErrorType.find_by(value: name).log_errors.create(value: error, date: (DateTime.parse error.match(/\d{4}\-\d{2}\-\d{2}T\d{2}:\d{2}:\d{2}/)[0]).to_s(:db))
30
+ # end
31
+ # и подчищаем )
32
+ # if File.size("#{Rails.root}#{path}").to_i > 5538210
33
+ File.truncate("#{Rails.root}#{path}", 0)
34
+ # end
35
+ end
36
+
37
+ end
38
+
39
+ # и подчищаем также DJ.log когда он уже велик
40
+ dj_log_path = "#{Rails.root}/log/dj.log"
41
+ if File.size(dj_log_path).to_i > 1538210
42
+ File.truncate(dj_log_path, 0)
43
+ end
44
+
45
+ Delayed::Backend::ActiveRecord::Job.where(queue: :log_analyzer).destroy_all
46
+ LogAnalyzerJob.set(wait_until: DateTime.now + CONFIG[:log_analyzer_timeout].minute).perform_later
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,9 @@
1
+ class PasswordResurrectionKillJob < ApplicationJob
2
+ queue_as :password_resurrection_killers
3
+
4
+ def perform(uid)
5
+ user_card = UserCard.find_by(id: uid)
6
+ # user_card.update(resurrection:nil) unless user_card.nil?
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ class AdminMailer < PrometeusMailer
2
+
3
+ # Subject can be set in your I18n file at config/locales/en.yml
4
+ # with the following lookup:
5
+ #
6
+ # en.manager_mailer.new_manager.subject
7
+ #
8
+
9
+ end
@@ -0,0 +1,3 @@
1
+ class ClientMailer < PrometeusMailer
2
+
3
+ end
@@ -0,0 +1,9 @@
1
+ class KreatorMailer < PrometeusMailer
2
+
3
+ # Subject can be set in your I18n file at config/locales/en.yml
4
+ # with the following lookup:
5
+ #
6
+ # en.manager_mailer.new_manager.subject
7
+ #
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ class ManagerMailer < PrometeusMailer
2
+
3
+ # Subject can be set in your I18n file at config/locales/en.yml
4
+ # with the following lookup:
5
+ #
6
+ # en.manager_mailer.new_manager.subject
7
+ #
8
+
9
+ end
@@ -0,0 +1,16 @@
1
+ class PrometeusMailer < ApplicationMailer
2
+
3
+ def greetings_email user
4
+
5
+ @domain = CONFIG[:domain]
6
+ @title = "Добро пожаловать на #{@domain}"
7
+ @text1 = 'Нажмите на кнопку ниже для завершения регистрации.'
8
+ @text2 = "Если вы не регистрировались на сайте #{@domain}, то оставьте это письмо без внимания."
9
+ @link = account_confirmation_url({access_code: user.user_card.confirm_access_code, id: user.user_card.id})
10
+ @button_text = 'Подтвердить регистрацию'
11
+
12
+ mail(to: user.user_card.my_email, subject: @title)
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,9 @@
1
+ class UserCardsMailer < ApplicationMailer
2
+
3
+ def resurrection email, link
4
+ @link = link
5
+
6
+ mail(to: email, subject: "Восстановление доступа на сайт | #{CONFIG[:domain]}")
7
+ end
8
+
9
+ end
@@ -0,0 +1,3 @@
1
+ class Admin < Prometeus
2
+
3
+ end
@@ -0,0 +1,23 @@
1
+ class Avatar < ApplicationRecord
2
+
3
+ belongs_to :imageable, polymorphic: true
4
+
5
+ has_attached_file :uploaded_file,
6
+ :path => ":rails_root/public/avatars/:attachment/:id/:basename_:style.:extension",
7
+ :url => "/avatars/:attachment/:id/:basename_:style.:extension",
8
+ :styles => {
9
+ :default => ['220x220#', :png, :quality => 100],
10
+ :preview => ['130x130#', :png, :quality => 100],
11
+ },
12
+ :convert_options => {
13
+ :default => '-set colorspace sRGB -strip',
14
+ :preview => '-set colorspace sRGB -strip',
15
+ }
16
+
17
+ validates_attachment :uploaded_file,
18
+ :presence => true,
19
+ :size => { :in => 0..10.megabytes },
20
+ :content_type => { :content_type => /^image\/(jpeg|png|gif|tiff|bmp)$/ }
21
+
22
+
23
+ end
@@ -0,0 +1,7 @@
1
+ class City < ApplicationRecord
2
+ belongs_to :country
3
+ has_many :clients
4
+
5
+ scope :russia, -> {where(country_id: Country.find_by(iso_code: 'RU').id)}
6
+
7
+ end
@@ -0,0 +1,31 @@
1
+ class Client < Prometeus
2
+ extend Enumerize
3
+ extend ActiveModel::Naming
4
+
5
+ belongs_to :country
6
+ belongs_to :city
7
+
8
+ enumerize :sex, in: %w[male female other], i18n_scope: 'sex'
9
+
10
+ scope :males, -> {where(sex: 'male')}
11
+ scope :females, -> {where(sex: 'female')}
12
+ scope :others, -> {where(sex: 'other')}
13
+ scope :birthdays, -> {where('DATE_FORMAT(birthday, "%m%d")=?', DateTime.now.strftime('%m%d'))}
14
+
15
+ after_update :check_country
16
+
17
+ def happy_birthday?
18
+ require 'happy_birthday'
19
+ self.birthday.happy_birthday?
20
+ end
21
+
22
+ # назначение страны если первым выбирается город
23
+ def check_country
24
+ if saved_change_to_attribute?(:city_id)
25
+ unless self.city.nil?
26
+ self.update(country: self.city.country) unless self.country
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,7 @@
1
+ class Country < ApplicationRecord
2
+ has_many :cities
3
+ has_many :clients
4
+
5
+ scope :eurounion, -> { where(eu: true) }
6
+
7
+ end
@@ -0,0 +1,20 @@
1
+ class DelayedJob < ApplicationRecord
2
+ after_update :telegram_me
3
+
4
+ private
5
+
6
+ def telegram_me
7
+
8
+ if saved_change_to_attribute?(:last_error)
9
+ require 'telegram'
10
+
11
+ telegram = Telegram.new
12
+
13
+ telegram.sendSticker :pepe_depression, :tech
14
+ message = "Хьюстон ! У нас проблемы в Delayed Job::#{self.queue} #{self.last_error}"
15
+ telegram.sendMessage message, :tech
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,30 @@
1
+ class EmailAccessCard < ApplicationRecord
2
+
3
+ belongs_to :user_card
4
+
5
+ after_create :greetings_email
6
+ after_update :greetings_email
7
+ # after_destroy :check_active
8
+
9
+ before_validation :normalize
10
+ validates :value, presence: true, uniqueness: true, format: {with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i}, :allow_blank => false
11
+ validates :value, :length => {:minimum => 6, :message => 'шорты'}
12
+
13
+ def check_active
14
+ self.user_card.set_active_card
15
+ end
16
+
17
+ def normalize
18
+ self.value.downcase! unless self.value.nil?
19
+ end
20
+
21
+ def greetings_email
22
+ unless self.value.blank?
23
+ if saved_change_to_attribute?(:value)
24
+ user = self.user_card.userable
25
+ "#{user.class.name}Mailer".constantize.greetings_email(user).deliver_now
26
+ end
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,3 @@
1
+ class Kreator < Prometeus
2
+
3
+ end
@@ -0,0 +1,56 @@
1
+ class LogError < ApplicationRecord
2
+ belongs_to :log_error_type
3
+
4
+ after_create :telegram_me
5
+
6
+ private
7
+
8
+ def telegram_me
9
+ require 'telegram'
10
+
11
+ telegram = Telegram.new
12
+
13
+ telegram.sendSticker :dog, :tech
14
+ message = "#{I18n.l self.date, format: :long} в #{self.log_error_type.value} замечена проблема на #{CONFIG[:domain]} !
15
+ #{self.value}
16
+ "
17
+ telegram.sendMessage message, :tech
18
+ # LogMailer.error(self).deliver_later
19
+ #
20
+ # - @error.split(/\n/).each do |str|
21
+ # - if /Failed|Exists|Error|ROLLBACK|Completed 400|Completed 500|RoutingError/ =~ str
22
+ # dvi.log_err
23
+ # = str
24
+ # - elsif /Goodbye|shutdown|Gracefully|startup|INFO/ =~ str
25
+ # dvi.log_puma
26
+ # = str
27
+ # - elsif /WARNING/ =~ str
28
+ # dvi.log_warning
29
+ # = str
30
+ # - elsif /ActiveJob/ =~ str
31
+ # dvi.log_active_job
32
+ # = str
33
+ # - elsif /WebSocket|Channel/ =~ str
34
+ # dvi.log_action_cable
35
+ # = str
36
+ # - elsif /SELECT|INSERT INTO|UPDATE|BEGIN|DELETE|COMMIT|ActiveRecord/ =~ str
37
+ # dvi.log_active_record
38
+ # = str
39
+ # - elsif /Parameters/ =~ str
40
+ # dvi.log_params
41
+ # = str
42
+ # - elsif /Started|Processing|Redirected|DEBUG/ =~ str
43
+ # dvi.log_processing
44
+ # = str
45
+ # - elsif /Completed/ =~ str
46
+ # dvi.log_processing_end
47
+ # = str
48
+ # - else
49
+ # = str
50
+ # br
51
+
52
+
53
+ end
54
+
55
+
56
+ end
@@ -0,0 +1,3 @@
1
+ class LogErrorType < ApplicationRecord
2
+ has_many :log_errors, dependent: :destroy
3
+ end
@@ -0,0 +1,3 @@
1
+ class Manager < Prometeus
2
+
3
+ end
@@ -0,0 +1,18 @@
1
+ class NicknameAccessCard < ApplicationRecord
2
+
3
+ belongs_to :user_card
4
+
5
+ before_validation :normalize
6
+ validates :value, presence: true, uniqueness: true, format: {with: /\A([a-zA-Z][\w]{0,14})\z/i}, :allow_blank => false
7
+
8
+ def normalize
9
+ self.value.downcase!
10
+ end
11
+
12
+ # after_destroy :check_active
13
+
14
+ def check_active
15
+ self.user_card.set_active_card
16
+ end
17
+
18
+ end