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,50 @@
|
|
1
|
+
class OauthGg < Oauth
|
2
|
+
def auth_request step = :step1, add_params = nil
|
3
|
+
uri = URI CONFIG[:oauth][@name][:auth][step][:uri]
|
4
|
+
params = CONFIG[:oauth][@name][:auth][:united_params].merge(CONFIG[:oauth][@name][:auth][step].except(:uri)).merge({redirect_uri: @verify_url, state: @key})
|
5
|
+
# для второго шага
|
6
|
+
params.merge!(add_params) unless add_params.nil?
|
7
|
+
|
8
|
+
case step
|
9
|
+
when :step1
|
10
|
+
uri.query = URI.encode_www_form params
|
11
|
+
uri.to_s
|
12
|
+
when :step2
|
13
|
+
oauth_access_card_params Net::HTTP.post_form uri, params
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def oauth_access_card_params result
|
19
|
+
begin
|
20
|
+
params = ActiveSupport::JSON.decode(result.body)
|
21
|
+
|
22
|
+
unless params['error'].present?
|
23
|
+
add_info = token_info({id_token: params['id_token']})
|
24
|
+
{
|
25
|
+
state: :ok,
|
26
|
+
oauth_name: @name,
|
27
|
+
oauth_uid: add_info['sub'],
|
28
|
+
access_token: params['access_token'],
|
29
|
+
token_expired: (DateTime.now + params['expires_in'].second).to_s(:db),
|
30
|
+
photourl: add_info['picture']
|
31
|
+
}
|
32
|
+
else
|
33
|
+
error_response params['error']
|
34
|
+
end
|
35
|
+
|
36
|
+
rescue Exception => error
|
37
|
+
error_response error.message
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def token_info access_params
|
42
|
+
uri = URI CONFIG[:oauth][@name][:api][:tokeninfo][:uri]
|
43
|
+
params = access_params
|
44
|
+
uri.query = URI.encode_www_form params
|
45
|
+
result = Net::HTTP.get_response uri
|
46
|
+
|
47
|
+
ActiveSupport::JSON.decode(result.body)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class OauthIm < Oauth
|
2
|
+
def auth_request step = :step1, add_params = nil
|
3
|
+
|
4
|
+
uri = URI CONFIG[:oauth][@name][:auth][step][:uri]
|
5
|
+
params = CONFIG[:oauth][@name][:auth][:united_params].merge(CONFIG[:oauth][@name][:auth][step].except(:uri)).merge({redirect_uri: @verify_url, state: @key})
|
6
|
+
# для второго шага
|
7
|
+
params.merge!(add_params) unless add_params.nil?
|
8
|
+
|
9
|
+
case step
|
10
|
+
when :step1
|
11
|
+
uri.query = URI.encode_www_form params
|
12
|
+
uri.to_s
|
13
|
+
when :step2
|
14
|
+
oauth_access_card_params Net::HTTP.post_form uri, params
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def oauth_access_card_params result
|
20
|
+
begin
|
21
|
+
params = ActiveSupport::JSON.decode(result.body)
|
22
|
+
|
23
|
+
unless params['error'].present?
|
24
|
+
# add_info = user_self({access_token: params['access_token']})
|
25
|
+
{
|
26
|
+
state: :ok,
|
27
|
+
oauth_name: @name,
|
28
|
+
oauth_uid: params['user']['id'],
|
29
|
+
access_token: params['access_token'],
|
30
|
+
token_expired: DateTime.now + 30.days,
|
31
|
+
photourl: params['user']['profile_picture']
|
32
|
+
}
|
33
|
+
else
|
34
|
+
error_response "#{params['error']} #{params['error_reason']} #{params['error_description']}"
|
35
|
+
end
|
36
|
+
rescue Exception => error
|
37
|
+
error_response "rescue #{error.message} #{params} #{result.body}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def user_self access_params
|
42
|
+
uri = URI CONFIG[:oauth][@name][:api][:passport][:uri]
|
43
|
+
params = CONFIG[:oauth][@name][:api][:passport][:params]
|
44
|
+
params.merge!(access_params) unless access_params.nil?
|
45
|
+
uri.query = URI.encode_www_form params
|
46
|
+
result = Net::HTTP.get_response uri
|
47
|
+
|
48
|
+
ActiveSupport::JSON.decode(result.body)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class OauthMr < Oauth
|
2
|
+
def auth_request step = :step1, add_params = nil
|
3
|
+
|
4
|
+
uri = URI CONFIG[:oauth][@name][:auth][step][:uri]
|
5
|
+
params = CONFIG[:oauth][@name][:auth][:united_params].merge(CONFIG[:oauth][@name][:auth][step].except(:uri)).merge({redirect_uri: @verify_url, state: @key})
|
6
|
+
# для второго шага
|
7
|
+
params.merge!(add_params) unless add_params.nil?
|
8
|
+
|
9
|
+
case step
|
10
|
+
when :step1
|
11
|
+
uri.query = URI.encode_www_form params
|
12
|
+
uri.to_s
|
13
|
+
when :step2
|
14
|
+
oauth_access_card_params Net::HTTP.post_form uri, params
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def oauth_access_card_params result
|
20
|
+
begin
|
21
|
+
params = ActiveSupport::JSON.decode(result.body)
|
22
|
+
|
23
|
+
unless params['error'].present?
|
24
|
+
add_info = get_user_info({session_key: params['access_token'], uid: params['x_mailru_vid']})
|
25
|
+
{
|
26
|
+
state: :ok,
|
27
|
+
oauth_name: @name,
|
28
|
+
oauth_uid: params['x_mailru_vid'],
|
29
|
+
access_token: params['access_token'],
|
30
|
+
token_expired: (DateTime.now + params['expires_in'].second).to_s(:db),
|
31
|
+
photourl: add_info['has_pic'].to_i == 0 ? nil : add_info['pic_128']
|
32
|
+
}
|
33
|
+
else
|
34
|
+
error_response "#{params['error']}:#{params['error_description']} #{params} #{result.body}"
|
35
|
+
end
|
36
|
+
rescue Exception => error
|
37
|
+
error_response "rescue #{error.message} #{params} #{result.body} #{add_info}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_user_info access_params
|
42
|
+
uri = URI CONFIG[:oauth][@name][:api][:get_user_info][:uri]
|
43
|
+
params = CONFIG[:oauth][@name][:api][:get_user_info][:params]
|
44
|
+
params.merge!(access_params) unless access_params.nil?
|
45
|
+
sig = Digest::MD5.hexdigest params.sort.map{|k,v| "#{k}=#{v}"}.join() + CONFIG[:oauth][@name][:auth][:step2][:client_secret] # охуенная подпись !
|
46
|
+
params = params.merge({sig: sig})
|
47
|
+
uri.query = URI.encode_www_form params
|
48
|
+
result = Net::HTTP.get_response uri
|
49
|
+
|
50
|
+
ActiveSupport::JSON.decode(result.body)[0]
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class OauthYx < Oauth
|
2
|
+
def auth_request step = :step1, add_params = nil
|
3
|
+
|
4
|
+
uri = URI CONFIG[:oauth][@name][:auth][step][:uri]
|
5
|
+
params = CONFIG[:oauth][@name][:auth][:united_params].merge(CONFIG[:oauth][@name][:auth][step].except(:uri)).merge({redirect_uri: @verify_url, state: @key})
|
6
|
+
# для второго шага
|
7
|
+
params.merge!(add_params) unless add_params.nil?
|
8
|
+
|
9
|
+
case step
|
10
|
+
when :step1
|
11
|
+
uri.query = URI.encode_www_form params
|
12
|
+
uri.to_s
|
13
|
+
when :step2
|
14
|
+
oauth_access_card_params Net::HTTP.post_form uri, params
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def oauth_access_card_params result
|
20
|
+
begin
|
21
|
+
params = ActiveSupport::JSON.decode(result.body)
|
22
|
+
|
23
|
+
unless params['error'].present?
|
24
|
+
add_info = yandex_passport_api({oauth_token: params['access_token']})
|
25
|
+
{
|
26
|
+
state: :ok,
|
27
|
+
oauth_name: @name,
|
28
|
+
oauth_uid: add_info['id'],
|
29
|
+
access_token: params['access_token'],
|
30
|
+
token_expired: (DateTime.now + params['expires_in'].second).to_s(:db),
|
31
|
+
photourl: add_info['is_avatar_empty'] == true ? nil : "https://avatars.yandex.net/get-yapic/#{add_info['default_avatar_id']}/islands-retina-50"
|
32
|
+
}
|
33
|
+
else
|
34
|
+
error_response "#{params['error']}:#{params['error_description']}"
|
35
|
+
end
|
36
|
+
rescue Exception => error
|
37
|
+
error_response "rescue #{error.message} #{params} #{result.body} #{add_info}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def yandex_passport_api access_params
|
42
|
+
uri = URI CONFIG[:oauth][@name][:api][:passport][:uri]
|
43
|
+
params = CONFIG[:oauth][@name][:api][:passport][:params]
|
44
|
+
params.merge!(access_params) unless access_params.nil?
|
45
|
+
uri.query = URI.encode_www_form params
|
46
|
+
result = Net::HTTP.get_response uri
|
47
|
+
|
48
|
+
ActiveSupport::JSON.decode(result.body)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class Openid
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
def initialize verify_url, state
|
7
|
+
@verify_url = verify_url
|
8
|
+
@key = state.keys.first
|
9
|
+
@name = state.values.first[:name].to_sym
|
10
|
+
end
|
11
|
+
|
12
|
+
def auth_request step = :step1
|
13
|
+
|
14
|
+
uri = URI CONFIG[:oauth][@name][:auth][step][:uri]
|
15
|
+
params = CONFIG[:oauth][@name][:auth][:united_params].merge(CONFIG[:oauth][@name][:auth][step].except(:uri)).merge({'openid.return_to' => @verify_url, 'openid.state' => @key})
|
16
|
+
uri.query = URI.encode_www_form params
|
17
|
+
uri.to_s
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
def oauth_access_card_params id
|
22
|
+
begin
|
23
|
+
{
|
24
|
+
state: :ok,
|
25
|
+
oauth_name: @name,
|
26
|
+
oauth_uid: id,
|
27
|
+
access_token: nil,
|
28
|
+
token_expired: nil,
|
29
|
+
photourl: nil
|
30
|
+
}
|
31
|
+
rescue Exception => error
|
32
|
+
{
|
33
|
+
state: :shit,
|
34
|
+
error: error.message
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def error_response error_message
|
40
|
+
{
|
41
|
+
state: :shit,
|
42
|
+
error: error_message
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/lib/phone_cutter.rb
ADDED
data/lib/response.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
class Response
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
@details = []
|
5
|
+
@url = nil
|
6
|
+
@state = 'bad'
|
7
|
+
@additional_vars = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_var hash
|
11
|
+
@additional_vars << hash
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_detail detail
|
15
|
+
@details << detail
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_url url
|
19
|
+
@url = url
|
20
|
+
end
|
21
|
+
|
22
|
+
def details?
|
23
|
+
@details.any?
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_state state
|
27
|
+
@state = state
|
28
|
+
end
|
29
|
+
|
30
|
+
def error_state _error
|
31
|
+
set_state 'shit'
|
32
|
+
add_detail _error.message
|
33
|
+
end
|
34
|
+
|
35
|
+
def get
|
36
|
+
|
37
|
+
if @state == 'bad'
|
38
|
+
set_state 'ok' unless details?
|
39
|
+
end
|
40
|
+
|
41
|
+
result = {state: @state, details: @details, url: @url}
|
42
|
+
|
43
|
+
@additional_vars.each do |h|
|
44
|
+
result.merge! h
|
45
|
+
end
|
46
|
+
|
47
|
+
result
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class SessionManager
|
2
|
+
|
3
|
+
def set_session session
|
4
|
+
@session = session
|
5
|
+
end
|
6
|
+
|
7
|
+
def set_cookies cookies
|
8
|
+
@cookies = cookies
|
9
|
+
end
|
10
|
+
|
11
|
+
def authorize! id
|
12
|
+
@session[:uid] = id
|
13
|
+
@cookies[:uid] = id
|
14
|
+
@cookies[:chk] = (Digest::MD5.new.update "#{CONFIG[:pepper]}#{id}#{CONFIG[:salt]}").to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def whoami
|
18
|
+
if @session && @session[:uid]
|
19
|
+
user = UserCard.find(@session[:uid]).userable
|
20
|
+
username = user.name == '' ? "#{user.class.name}##{user.id}" : user.name
|
21
|
+
username << " из компании #{user.company.name}" if user.class.name == 'Manager' && user.company.name
|
22
|
+
username
|
23
|
+
else
|
24
|
+
'Anonymous'
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def login_data
|
30
|
+
check_login_data
|
31
|
+
@session[:login_data]
|
32
|
+
end
|
33
|
+
|
34
|
+
def login_data_update account
|
35
|
+
@session[:login_data] = {type: account.class.name, id: account.id}
|
36
|
+
@session[:uid] = account.user_card.id
|
37
|
+
end
|
38
|
+
|
39
|
+
def check_login_data
|
40
|
+
begin
|
41
|
+
@session[:login_data][:type].constantize.find_by({id: @session[:login_data][:id]}).present?
|
42
|
+
rescue
|
43
|
+
@session[:login_data] = nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/lib/sms_lib.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module SmsLib
|
2
|
+
|
3
|
+
def sms_new_bee(user, password)
|
4
|
+
message = "пароль на #{CONFIG[:domain]} #{password}"
|
5
|
+
send_sms user.phone, message
|
6
|
+
end
|
7
|
+
|
8
|
+
def sms_password_reset(user, new_password)
|
9
|
+
message = "новый пароль на #{CONFIG[:domain]} #{new_password}"
|
10
|
+
send_sms user.phone, message
|
11
|
+
end
|
12
|
+
|
13
|
+
def sms_phone_verify_code(phone, code)
|
14
|
+
message = "skillhunt код подтверждения - #{code}"
|
15
|
+
send_sms phone, message
|
16
|
+
|
17
|
+
session[:sms_lock] = Time.now + 59.seconds
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def send_sms(recepient_10dgt, message)
|
23
|
+
require 'russland_sms'
|
24
|
+
|
25
|
+
message.to_s.sms recepient_10dgt
|
26
|
+
|
27
|
+
# p "message #{message} send2 #{recepient_10dgt}"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|