rails_base 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +32 -0
- data/Rakefile +32 -0
- data/app/assets/config/rails_base/manifest.js +3 -0
- data/app/assets/images/rails_base/favicon.ico +0 -0
- data/app/assets/javascripts/rails_base/admin.js +2 -0
- data/app/assets/javascripts/rails_base/application.js +22 -0
- data/app/assets/javascripts/rails_base/cable.js +13 -0
- data/app/assets/javascripts/rails_base/mfa_auth.coffee +3 -0
- data/app/assets/javascripts/rails_base/secondary_authentication.coffee +3 -0
- data/app/assets/javascripts/rails_base/sessions.js +152 -0
- data/app/assets/javascripts/rails_base/user_settings.coffee +3 -0
- data/app/assets/stylesheets/rails_base/admin.css +4 -0
- data/app/assets/stylesheets/rails_base/application.scss +15 -0
- data/app/assets/stylesheets/rails_base/mfa_auth.scss +3 -0
- data/app/assets/stylesheets/rails_base/scaffolds.scss +84 -0
- data/app/assets/stylesheets/rails_base/secondary_authentication.scss +3 -0
- data/app/assets/stylesheets/rails_base/user_settings.scss +3 -0
- data/app/controllers/rails_base/admin_controller.rb +315 -0
- data/app/controllers/rails_base/application_controller.rb +153 -0
- data/app/controllers/rails_base/errors_controller.rb +29 -0
- data/app/controllers/rails_base/mfa_auth_controller.rb +50 -0
- data/app/controllers/rails_base/secondary_authentication_controller.rb +224 -0
- data/app/controllers/rails_base/switch_user_controller.rb +29 -0
- data/app/controllers/rails_base/user_settings_controller.rb +81 -0
- data/app/controllers/rails_base/users/passwords_controller.rb +19 -0
- data/app/controllers/rails_base/users/registrations_controller.rb +80 -0
- data/app/controllers/rails_base/users/sessions_controller.rb +108 -0
- data/app/helpers/rails_base/admin_helper.rb +107 -0
- data/app/helpers/rails_base/appearance_helper.rb +58 -0
- data/app/helpers/rails_base/application_helper.rb +26 -0
- data/app/helpers/rails_base/capture_reference_helper.rb +57 -0
- data/app/helpers/rails_base/mfa_auth_helper.rb +2 -0
- data/app/helpers/rails_base/secondary_authentication_helper.rb +2 -0
- data/app/helpers/rails_base/user_field_validators.rb +108 -0
- data/app/helpers/rails_base/user_settings_helper.rb +22 -0
- data/app/jobs/rails_base/application_job.rb +10 -0
- data/app/jobs/twilio_job.rb +9 -0
- data/app/mailers/rails_base/application_mailer.rb +9 -0
- data/app/mailers/rails_base/email_verification_mailer.rb +22 -0
- data/app/mailers/rails_base/event_mailer.rb +16 -0
- data/app/models/admin_action.rb +119 -0
- data/app/models/rails_base/application_record.rb +22 -0
- data/app/models/rails_base/user_constants.rb +28 -0
- data/app/models/secret.rb +37 -0
- data/app/models/short_lived_data.rb +132 -0
- data/app/models/user.rb +143 -0
- data/app/services/rails_base/admin_risky_mfa_send.rb +80 -0
- data/app/services/rails_base/admin_update_attribute.rb +100 -0
- data/app/services/rails_base/authentication/authenticate_user.rb +28 -0
- data/app/services/rails_base/authentication/constants.rb +60 -0
- data/app/services/rails_base/authentication/decision_twofa_type.rb +76 -0
- data/app/services/rails_base/authentication/destroy_user.rb +45 -0
- data/app/services/rails_base/authentication/mfa_set_encrypt_token.rb +32 -0
- data/app/services/rails_base/authentication/mfa_validator.rb +88 -0
- data/app/services/rails_base/authentication/modify_password.rb +67 -0
- data/app/services/rails_base/authentication/send_forgot_password.rb +26 -0
- data/app/services/rails_base/authentication/send_login_mfa_to_user.rb +77 -0
- data/app/services/rails_base/authentication/send_verification_email.rb +103 -0
- data/app/services/rails_base/authentication/session_token_verifier.rb +31 -0
- data/app/services/rails_base/authentication/single_sign_on_create.rb +44 -0
- data/app/services/rails_base/authentication/single_sign_on_send.rb +101 -0
- data/app/services/rails_base/authentication/single_sign_on_verify.rb +42 -0
- data/app/services/rails_base/authentication/sso_verify_email.rb +43 -0
- data/app/services/rails_base/authentication/update_phone_send_verification.rb +46 -0
- data/app/services/rails_base/authentication/verify_forgot_password.rb +46 -0
- data/app/services/rails_base/email_change.rb +20 -0
- data/app/services/rails_base/encryption.rb +87 -0
- data/app/services/rails_base/name_change.rb +71 -0
- data/app/services/rails_base/service_base.rb +65 -0
- data/app/services/rails_base/service_logging.rb +23 -0
- data/app/views/layouts/rails_base/application.html.erb +185 -0
- data/app/views/layouts/rails_base/mailer.html.erb +13 -0
- data/app/views/layouts/rails_base/mailer.text.erb +1 -0
- data/app/views/new.html.erb +4 -0
- data/app/views/rails_base/admin/history.html.erb +26 -0
- data/app/views/rails_base/admin/index.html.erb +149 -0
- data/app/views/rails_base/admin/show_config.html.erb +18 -0
- data/app/views/rails_base/devise/confirmations/new.html.erb +16 -0
- data/app/views/rails_base/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/rails_base/devise/mailer/email_changed.html.erb +7 -0
- data/app/views/rails_base/devise/mailer/password_change.html.erb +3 -0
- data/app/views/rails_base/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/rails_base/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/rails_base/devise/passwords/edit.html.erb +25 -0
- data/app/views/rails_base/devise/passwords/new.html.erb +27 -0
- data/app/views/rails_base/devise/registrations/edit.html.erb +43 -0
- data/app/views/rails_base/devise/registrations/new.html.erb +123 -0
- data/app/views/rails_base/devise/sessions/new.html.erb +4 -0
- data/app/views/rails_base/devise/shared/_error_messages.html.erb +15 -0
- data/app/views/rails_base/devise/shared/_links.html.erb +25 -0
- data/app/views/rails_base/devise/unlocks/new.html.erb +16 -0
- data/app/views/rails_base/email_verification_mailer/email_verification.html.erb +25 -0
- data/app/views/rails_base/email_verification_mailer/event.html.erb +20 -0
- data/app/views/rails_base/email_verification_mailer/forgot_password.html.erb +22 -0
- data/app/views/rails_base/errors/internal_error.html.erb +1 -0
- data/app/views/rails_base/errors/not_found.html.erb +1 -0
- data/app/views/rails_base/errors/unacceptable.html.erb +1 -0
- data/app/views/rails_base/event_mailer/event.html.erb +10 -0
- data/app/views/rails_base/mfa_auth/mfa_code.html.erb +10 -0
- data/app/views/rails_base/secondary_authentication/after_email_login_session_new.html.erb +3 -0
- data/app/views/rails_base/secondary_authentication/forgot_password.html.erb +9 -0
- data/app/views/rails_base/secondary_authentication/remove_me.html.erb +1 -0
- data/app/views/rails_base/secondary_authentication/static.html.erb +5 -0
- data/app/views/rails_base/shared/_admin_actions_modal.html.erb +65 -0
- data/app/views/rails_base/shared/_admin_config_class.html.erb +52 -0
- data/app/views/rails_base/shared/_admin_history.html.erb +86 -0
- data/app/views/rails_base/shared/_admin_modify_email.html.erb +78 -0
- data/app/views/rails_base/shared/_admin_modify_name.html.erb +107 -0
- data/app/views/rails_base/shared/_admin_modify_phone.html.erb +87 -0
- data/app/views/rails_base/shared/_admin_modify_text.html.erb +35 -0
- data/app/views/rails_base/shared/_admin_risky_change.html.erb +57 -0
- data/app/views/rails_base/shared/_admin_risky_mfa.html.erb +74 -0
- data/app/views/rails_base/shared/_admin_selector_dropdown.html.erb +70 -0
- data/app/views/rails_base/shared/_admin_toggle_button.html.erb +72 -0
- data/app/views/rails_base/shared/_admin_warning_alert.html.erb +7 -0
- data/app/views/rails_base/shared/_appearance_mode_selector.html.erb +183 -0
- data/app/views/rails_base/shared/_custom_form_validation_javascript.html.erb +129 -0
- data/app/views/rails_base/shared/_enable_mfa_auth_modal.html.erb +105 -0
- data/app/views/rails_base/shared/_error_pages.html.erb +123 -0
- data/app/views/rails_base/shared/_logged_in_header.html.erb +123 -0
- data/app/views/rails_base/shared/_logged_out_header.html.erb +14 -0
- data/app/views/rails_base/shared/_mfa_input_layout.html.erb +5 -0
- data/app/views/rails_base/shared/_mfa_input_layout_default.html.erb +97 -0
- data/app/views/rails_base/shared/_mfa_input_layout_fallback.html.erb +55 -0
- data/app/views/rails_base/shared/_modify_mfa_auth_modal.html.erb +20 -0
- data/app/views/rails_base/shared/_password_confirm_javascript.html.erb +71 -0
- data/app/views/rails_base/shared/_reset_password_form.html.erb +111 -0
- data/app/views/rails_base/shared/_session_create_form.html.erb +32 -0
- data/app/views/rails_base/shared/_session_timeout_modal.html.erb +76 -0
- data/app/views/rails_base/switch_user/_widget.html.erb +5 -0
- data/app/views/rails_base/user_settings/_confirm_destroy_user.html.erb +42 -0
- data/app/views/rails_base/user_settings/_destroy_user.html.erb +106 -0
- data/app/views/rails_base/user_settings/_modify_name.html.erb +71 -0
- data/app/views/rails_base/user_settings/_modify_password.html.erb +101 -0
- data/app/views/rails_base/user_settings/_modify_password_update_password.html.erb +2 -0
- data/app/views/rails_base/user_settings/index.html.erb +54 -0
- data/config/initializers/01_rails_config.rb +19 -0
- data/config/initializers/admin_action_helper.rb +88 -0
- data/config/initializers/browser.rb +4 -0
- data/config/initializers/default_logged_in_headers.rb +23 -0
- data/config/initializers/devise.rb +314 -0
- data/config/initializers/encryption.rb +2 -0
- data/config/initializers/switch_user.rb +58 -0
- data/config/initializers/switch_user_helper.rb +29 -0
- data/config/locales/devise.en.yml +65 -0
- data/config/locales/en.yml +58 -0
- data/config/routes.rb +114 -0
- data/db/migrate/20210212175453_devise_create_rails_base_users.rb +56 -0
- data/db/migrate/20210212190537_create_rails_base_short_lived_data.rb +19 -0
- data/db/migrate/20210212192645_create_rails_base_secrets.rb +11 -0
- data/db/migrate/20210406015744_create_rails_base_admin_actions.rb +17 -0
- data/db/seeds.rb +23 -0
- data/lib/link_decision_helper.rb +71 -0
- data/lib/rails_base.rb +50 -0
- data/lib/rails_base/admin/action_cache.rb +99 -0
- data/lib/rails_base/admin/action_helper.rb +134 -0
- data/lib/rails_base/admin/default_index_tile.rb +176 -0
- data/lib/rails_base/admin/index_tile.rb +186 -0
- data/lib/rails_base/config.rb +52 -0
- data/lib/rails_base/configuration/active_job.rb +38 -0
- data/lib/rails_base/configuration/admin.rb +231 -0
- data/lib/rails_base/configuration/app.rb +52 -0
- data/lib/rails_base/configuration/appearance.rb +131 -0
- data/lib/rails_base/configuration/authentication.rb +37 -0
- data/lib/rails_base/configuration/base.rb +209 -0
- data/lib/rails_base/configuration/display/background_color.rb +25 -0
- data/lib/rails_base/configuration/display/btn_danger.rb +25 -0
- data/lib/rails_base/configuration/display/btn_dark.rb +25 -0
- data/lib/rails_base/configuration/display/btn_info.rb +25 -0
- data/lib/rails_base/configuration/display/btn_light.rb +25 -0
- data/lib/rails_base/configuration/display/btn_primary.rb +25 -0
- data/lib/rails_base/configuration/display/btn_secondary.rb +25 -0
- data/lib/rails_base/configuration/display/btn_success.rb +25 -0
- data/lib/rails_base/configuration/display/btn_warning.rb +25 -0
- data/lib/rails_base/configuration/display/footer.rb +54 -0
- data/lib/rails_base/configuration/display/navbar.rb +25 -0
- data/lib/rails_base/configuration/display/table_body.rb +25 -0
- data/lib/rails_base/configuration/display/table_header.rb +25 -0
- data/lib/rails_base/configuration/display/text.rb +26 -0
- data/lib/rails_base/configuration/exceptions_app.rb +25 -0
- data/lib/rails_base/configuration/login_behavior.rb +17 -0
- data/lib/rails_base/configuration/mailer.rb +116 -0
- data/lib/rails_base/configuration/mfa.rb +84 -0
- data/lib/rails_base/configuration/owner.rb +17 -0
- data/lib/rails_base/configuration/redis.rb +29 -0
- data/lib/rails_base/configuration/user.rb +43 -0
- data/lib/rails_base/engine.rb +51 -0
- data/lib/rails_base/version.rb +10 -0
- data/lib/tasks/rails_base_tasks.rake +4 -0
- data/lib/twilio_helper.rb +26 -0
- data/lib/velocity_limiter.rb +91 -0
- metadata +619 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'switch_user'
|
4
|
+
|
5
|
+
SwitchUser.setup do |config|
|
6
|
+
# provider may be :devise, :authlogic, :clearance, :restful_authentication, :sorcery, or :session
|
7
|
+
config.provider = :devise
|
8
|
+
|
9
|
+
# available_users is a hash,
|
10
|
+
# key is the model name of user (:user, :admin, or any name you use),
|
11
|
+
# value is a block that return the users that can be switched.
|
12
|
+
config.available_users = { user: -> { User.all } }
|
13
|
+
|
14
|
+
# available_users_identifiers is a hash,
|
15
|
+
# keys in this hash should match a key in the available_users hash
|
16
|
+
# value is the name of the identifying column to find by,
|
17
|
+
# defaults to id
|
18
|
+
# this hash is to allow you to specify a different column to
|
19
|
+
# expose for instance a username on a User model instead of id
|
20
|
+
config.available_users_identifiers = { user: :id }
|
21
|
+
|
22
|
+
# available_users_names is a hash,
|
23
|
+
# keys in this hash should match a key in the available_users hash
|
24
|
+
# value is the column name which will be displayed in select box
|
25
|
+
config.available_users_names = { user: :full_name }
|
26
|
+
|
27
|
+
# controller_guard is a block,
|
28
|
+
# if it returns true, the request will continue,
|
29
|
+
# else the request will be refused and returns "Permission Denied"
|
30
|
+
# if you switch from "admin" to user, the current_user param is "admin"
|
31
|
+
# config.controller_guard = ->(current_user, request, original_user) { current_user && current_user.admin? || original_user && original_user.super_admin? }
|
32
|
+
# RailsBase handles authentication/gaurding for controlller and viewer
|
33
|
+
config.controller_guard = ->(_current_user, _request) { true }
|
34
|
+
|
35
|
+
# view_guard is a block,
|
36
|
+
# if it returns true, the switch user select box will be shown,
|
37
|
+
# else the select box will not be shown
|
38
|
+
# if you switch from admin to "user", the current_user param is "user"
|
39
|
+
# RailsBase handles authentication/gaurding for controlller and viewer
|
40
|
+
config.view_guard = ->(current_user, request) { true }
|
41
|
+
|
42
|
+
# redirect_path is a block, it returns which page will be redirected
|
43
|
+
# after switching a user.
|
44
|
+
config.redirect_path = ->(_request, _params) { RailsBase.url_routes.authenticated_root_path }
|
45
|
+
|
46
|
+
# helper_with_guest is a boolean value, if it set to false
|
47
|
+
# the guest item in the helper won't be shown
|
48
|
+
config.helper_with_guest = false
|
49
|
+
|
50
|
+
# false = login from one scope to another and you are logged in only in both scopes
|
51
|
+
# true = you are logged only into one scope at a time
|
52
|
+
config.login_exclusive = true
|
53
|
+
|
54
|
+
# switch_back allows you to switch back to a previously selected user. See
|
55
|
+
# README for more details.
|
56
|
+
# we will implement our own switch back using encrpytion on session
|
57
|
+
config.switch_back = false
|
58
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'switch_user'
|
2
|
+
require SwitchUser::Engine.root.join('app', 'helpers', 'switch_user_helper.rb')
|
3
|
+
|
4
|
+
module SwitchUserHelper
|
5
|
+
def switch_user_custom(options = {})
|
6
|
+
return unless available?
|
7
|
+
|
8
|
+
selected_user = nil
|
9
|
+
|
10
|
+
grouped_options_container =
|
11
|
+
{}.tap do |h|
|
12
|
+
SwitchUser.all_users.each do |record|
|
13
|
+
scope = record.is_a?(SwitchUser::GuestRecord) ? :Guest : record.scope.to_s.capitalize
|
14
|
+
h[scope] ||= []
|
15
|
+
h[scope] << [record.label, record.scope_id]
|
16
|
+
|
17
|
+
next unless selected_user.nil?
|
18
|
+
next if record.is_a?(SwitchUser::GuestRecord)
|
19
|
+
|
20
|
+
selected_user = record.scope_id if provider.current_user?(record.user, record.scope)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
option_tags = grouped_options_for_select(grouped_options_container.to_a, selected_user)
|
25
|
+
|
26
|
+
render partial: 'rails_base/switch_user/widget',
|
27
|
+
locals: { option_tags: option_tags, classes: options[:class], styles: options[:style] }
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Additional translations at https://github.com/heartcombo/devise/wiki/I18n
|
2
|
+
|
3
|
+
en:
|
4
|
+
devise:
|
5
|
+
confirmations:
|
6
|
+
confirmed: "Your email address has been successfully confirmed."
|
7
|
+
send_instructions: "You will receive an email with instructions for how to confirm your email address in a few minutes."
|
8
|
+
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes."
|
9
|
+
failure:
|
10
|
+
already_authenticated: "You are already signed in."
|
11
|
+
inactive: "Your account is not activated yet."
|
12
|
+
invalid: "Invalid %{authentication_keys} or password."
|
13
|
+
locked: "Your account is locked."
|
14
|
+
last_attempt: "You have one more attempt before your account is locked."
|
15
|
+
not_found_in_database: "Invalid %{authentication_keys} or password."
|
16
|
+
timeout: "Your session expired. Please sign in again to continue."
|
17
|
+
unauthenticated: "You need to sign in or sign up before continuing."
|
18
|
+
unconfirmed: "You have to confirm your email address before continuing."
|
19
|
+
mailer:
|
20
|
+
confirmation_instructions:
|
21
|
+
subject: "Confirmation instructions"
|
22
|
+
reset_password_instructions:
|
23
|
+
subject: "Reset password instructions"
|
24
|
+
unlock_instructions:
|
25
|
+
subject: "Unlock instructions"
|
26
|
+
email_changed:
|
27
|
+
subject: "Email Changed"
|
28
|
+
password_change:
|
29
|
+
subject: "Password Changed"
|
30
|
+
omniauth_callbacks:
|
31
|
+
failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
|
32
|
+
success: "Successfully authenticated from %{kind} account."
|
33
|
+
passwords:
|
34
|
+
no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
|
35
|
+
send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
|
36
|
+
send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
|
37
|
+
updated: "Your password has been changed successfully. You are now signed in."
|
38
|
+
updated_not_active: "Your password has been changed successfully."
|
39
|
+
registrations:
|
40
|
+
destroyed: "Bye! Your account has been successfully cancelled. We hope to see you again soon."
|
41
|
+
signed_up: "Welcome! You have signed up successfully."
|
42
|
+
signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
|
43
|
+
signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
|
44
|
+
signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please follow the link to activate your account."
|
45
|
+
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address."
|
46
|
+
updated: "Your account has been updated successfully."
|
47
|
+
updated_but_not_signed_in: "Your account has been updated successfully, but since your password was changed, you need to sign in again"
|
48
|
+
sessions:
|
49
|
+
signed_in: "Signed in successfully."
|
50
|
+
signed_out: "Signed out successfully."
|
51
|
+
already_signed_out: "Signed out successfully."
|
52
|
+
unlocks:
|
53
|
+
send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
|
54
|
+
send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
|
55
|
+
unlocked: "Your account has been unlocked successfully. Please sign in to continue."
|
56
|
+
errors:
|
57
|
+
messages:
|
58
|
+
already_confirmed: "was already confirmed, please try signing in"
|
59
|
+
confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
|
60
|
+
expired: "has expired, please request a new one"
|
61
|
+
not_found: "not found"
|
62
|
+
not_locked: "was not locked"
|
63
|
+
not_saved:
|
64
|
+
one: "1 error prohibited this %{resource} from being saved:"
|
65
|
+
other: "%{count} errors prohibited this %{resource} from being saved:"
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Files in the config/locales directory are used for internationalization
|
2
|
+
# and are automatically loaded by Rails. If you want to use locales other
|
3
|
+
# than English, add the necessary files in this directory.
|
4
|
+
#
|
5
|
+
# To use the locales, use `I18n.t`:
|
6
|
+
#
|
7
|
+
# I18n.t 'hello'
|
8
|
+
#
|
9
|
+
# In views, this is aliased to just `t`:
|
10
|
+
#
|
11
|
+
# <%= t('hello') %>
|
12
|
+
#
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
14
|
+
#
|
15
|
+
# I18n.locale = :es
|
16
|
+
#
|
17
|
+
# This would use the information in config/locales/es.yml.
|
18
|
+
#
|
19
|
+
# The following keys must be escaped otherwise they will not be retrieved by
|
20
|
+
# the default I18n backend:
|
21
|
+
#
|
22
|
+
# true, false, on, off, yes, no
|
23
|
+
#
|
24
|
+
# Instead, surround them with single quotes.
|
25
|
+
#
|
26
|
+
# en:
|
27
|
+
# 'true': 'foo'
|
28
|
+
#
|
29
|
+
# To learn more, please read the Rails Internationalization guide
|
30
|
+
# available at http://guides.rubyonrails.org/i18n.html.
|
31
|
+
|
32
|
+
en:
|
33
|
+
request_response:
|
34
|
+
teapot:
|
35
|
+
valid: 'You are not a teapot'
|
36
|
+
fail: Unable to complete request
|
37
|
+
user_setting:
|
38
|
+
destroy_user:
|
39
|
+
soft: 'You have succesfully disabled your user. Sign up again to reset your data'
|
40
|
+
hard: 'You have succesfully destroyed your user and associated data'
|
41
|
+
authentication:
|
42
|
+
after_email_login_session_create: Welcome. You have succesfully logged in
|
43
|
+
after_email_login_session_new: Email has been verified. Please Log in again to gain access
|
44
|
+
resend_email: 'Verification Email resent to %{email}'
|
45
|
+
confirm_phone_registration:
|
46
|
+
fail: "Unable to complete request. %{message}"
|
47
|
+
valid: You have succesfully enabled 2fa.
|
48
|
+
remove_phone_mfa: You have Disabled 2fa. 2fa will no longer be applied during log in. You can re-enable any time
|
49
|
+
forgot_password:
|
50
|
+
2fa: 2 Factor Authentication is required for this account
|
51
|
+
base: Please enter your new password
|
52
|
+
forgot_password_with_mfa:
|
53
|
+
expired_datum: 'Unauthorized. Incorrect Data parameter'
|
54
|
+
valid_mfa: 'Successful MFA code. Please reset your password'
|
55
|
+
reset_password: Password succesfully changed. Please login
|
56
|
+
sso_login:
|
57
|
+
fail: 'Unable to Authenticate User - '
|
58
|
+
valid: Succesfully logged in from SSO link
|
data/config/routes.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
##################################
|
3
|
+
# Start of error handling routes #
|
4
|
+
##################################
|
5
|
+
|
6
|
+
get '/404', to: 'rails_base/errors#not_found', as: :error_404
|
7
|
+
get '/422', to: 'rails_base/errors#unacceptable', as: :error_422
|
8
|
+
get '/500', to: 'rails_base/errors#internal_error', as: :error_500
|
9
|
+
|
10
|
+
################################
|
11
|
+
# End of error handling routes #
|
12
|
+
################################
|
13
|
+
|
14
|
+
################################
|
15
|
+
# Start of UserSettings routes #
|
16
|
+
################################
|
17
|
+
|
18
|
+
get 'user/settings', to: 'rails_base/user_settings#index', as: :user_settings
|
19
|
+
post 'user/settings/edit/name', to: 'rails_base/user_settings#edit_name', as: :user_edit_name
|
20
|
+
post 'user/settings/edit/password', to: 'rails_base/user_settings#edit_password', as: :edit_password
|
21
|
+
post 'user/settings/confirm/password/:reason', to: 'rails_base/user_settings#confirm_password', as: :confirm_current_password
|
22
|
+
post 'user/settings/destroy', to: 'rails_base/user_settings#destroy_user', as: :destroy_user
|
23
|
+
|
24
|
+
##############################
|
25
|
+
# End of UserSettings routes #
|
26
|
+
##############################
|
27
|
+
|
28
|
+
##################################
|
29
|
+
# Start of Authentication routes #
|
30
|
+
##################################
|
31
|
+
|
32
|
+
# START ROOT PATH AUTHENTICATED -- This is devise magic methods
|
33
|
+
unless (Rails.application.routes.url_helpers.authenticated_root_path rescue false)
|
34
|
+
authenticated do
|
35
|
+
root to: 'rails_base/user_settings#index', as: :authenticated_root
|
36
|
+
end
|
37
|
+
end
|
38
|
+
# END ROOT PATH AUTHENTICATED
|
39
|
+
|
40
|
+
devise_for :users, controllers:
|
41
|
+
{
|
42
|
+
sessions: 'rails_base/users/sessions',
|
43
|
+
registrations: 'rails_base/users/registrations',
|
44
|
+
passwords: 'rails_base/users/passwords'
|
45
|
+
}
|
46
|
+
|
47
|
+
devise_scope :user do
|
48
|
+
delete '/signout', to: 'devise/sessions#destroy', as: :signout
|
49
|
+
get 'heartbeat', to: 'rails_base/users/sessions#hearbeat_without_auth', as: :heartbeat_without_auth
|
50
|
+
post 'heartbeat', to: 'rails_base/users/sessions#hearbeat_with_auth', as: :heartbeat_with_auth
|
51
|
+
|
52
|
+
# START ROOT PATH UNAUTHENTICATED
|
53
|
+
unless (Rails.application.routes.url_helpers.unauthenticated_root_path rescue false)
|
54
|
+
unauthenticated do
|
55
|
+
root to: 'rails_base/users/sessions#new', as: :unauthenticated_root
|
56
|
+
end
|
57
|
+
end
|
58
|
+
# END ROOT PATH UNAUTHENTICATED
|
59
|
+
end
|
60
|
+
|
61
|
+
get 'auth/validate/:data', to: 'rails_base/secondary_authentication#sso_login', as: :sso_login
|
62
|
+
get 'auth/email/wait', to: 'rails_base/secondary_authentication#static', as: :auth_static
|
63
|
+
get 'auth/email/:data', to: 'rails_base/secondary_authentication#email_verification', as: :email_verification
|
64
|
+
get 'auth/login', to: 'rails_base/secondary_authentication#after_email_login_session_new', as: :login_after_email
|
65
|
+
post 'auth/login', to: 'rails_base/secondary_authentication#after_email_login_session_create', as: :login_after_email_session_create
|
66
|
+
post 'auth/resend_email', to: 'rails_base/secondary_authentication#resend_email', as: :resend_email_verification
|
67
|
+
delete 'auth/phone/mfa', to: 'rails_base/secondary_authentication#remove_phone_mfa', as: :remove_phone_registration_mfa
|
68
|
+
get 'auth/password/forgot/:data', to: 'rails_base/secondary_authentication#forgot_password', as: :forgot_password_auth
|
69
|
+
post 'auth/password/forgot/:data', to: 'rails_base/secondary_authentication#forgot_password_with_mfa', as: :forgot_password_with_mfa_auth
|
70
|
+
post 'auth/password/reset/:data', to: 'rails_base/secondary_authentication#reset_password', as: :reset_password_auth
|
71
|
+
|
72
|
+
constraints(->(_req) { RailsBase.config.mfa.enable? }) do
|
73
|
+
get 'mfa_verify', to: 'rails_base/mfa_auth#mfa_code', as: :mfa_code
|
74
|
+
post 'mfa_verify', to: 'rails_base/mfa_auth#mfa_code_verify', as: :mfa_code_verify
|
75
|
+
post 'resend_mfa', to: 'rails_base/mfa_auth#resend_mfa', as: :resend_mfa
|
76
|
+
|
77
|
+
post 'auth/phone', to: 'rails_base/secondary_authentication#phone_registration', as: :phone_registration
|
78
|
+
post 'auth/phone/mfa', to: 'rails_base/secondary_authentication#confirm_phone_registration', as: :phone_registration_mfa_code
|
79
|
+
end
|
80
|
+
|
81
|
+
################################
|
82
|
+
# END of Authentication routes #
|
83
|
+
################################
|
84
|
+
|
85
|
+
#########################
|
86
|
+
# Start of Admin routes #
|
87
|
+
#########################
|
88
|
+
# override url and location for switch_user gem
|
89
|
+
constraints(->(_req) { RailsBase.config.admin.enable? }) do
|
90
|
+
post 'admin/impersonate/:scope_identifier', to: 'rails_base/switch_user#set_current_user', as: :switch_user
|
91
|
+
|
92
|
+
post 'admin/ack', to: 'rails_base/admin#ack', as: :admin_ack
|
93
|
+
post 'admin/impersonate', to: 'rails_base/admin#switch_back', as: :admin_stop_impersonation
|
94
|
+
post 'admin/update', to: 'rails_base/admin#update_attribute', as: :admin_upate_attribute
|
95
|
+
post 'admin/update/name', to: 'rails_base/admin#update_name', as: :admin_upate_name
|
96
|
+
post 'admin/update/email', to: 'rails_base/admin#update_email', as: :admin_upate_email
|
97
|
+
post 'admin/update/phone', to: 'rails_base/admin#update_phone', as: :admin_upate_phone
|
98
|
+
post 'admin/validate_intent/send', to: 'rails_base/admin#send_2fa', as: :admin_validate_intent
|
99
|
+
post 'admin/validate_intent/verify', to: 'rails_base/admin#verify_2fa', as: :admin_verify_intent
|
100
|
+
|
101
|
+
get 'admin', to: 'rails_base/admin#index', as: :admin_base
|
102
|
+
get 'admin/config', to: 'rails_base/admin#show_config', as: :admin_config
|
103
|
+
get 'admin/history', to: 'rails_base/admin#history', as: :admin_history
|
104
|
+
post 'admin/history', to: 'rails_base/admin#history_paginate', as: :admin_history_page
|
105
|
+
|
106
|
+
post 'admin/sso/:id', to: 'rails_base/admin#sso_send', as: :admin_sso_send
|
107
|
+
end
|
108
|
+
# route is part of admin control, but does not need admin enabled
|
109
|
+
get 'auth/sso/:data', to: 'rails_base/admin#sso_retrieve', as: :sso_retrieve
|
110
|
+
|
111
|
+
#######################
|
112
|
+
# End of Admin routes #
|
113
|
+
#######################
|
114
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DeviseCreateRailsBaseUsers < ActiveRecord::Migration[5.2]
|
4
|
+
def change
|
5
|
+
create_table :users do |t|
|
6
|
+
t.string :first_name, null: false, default: ""
|
7
|
+
t.string :last_name, null: false, default: ""
|
8
|
+
|
9
|
+
t.string :phone_number
|
10
|
+
t.timestamp :last_mfa_login
|
11
|
+
t.boolean :email_validated, default: false
|
12
|
+
t.boolean :mfa_enabled, default: false, null: false
|
13
|
+
t.boolean :active, default: true, null: false
|
14
|
+
t.string :admin
|
15
|
+
|
16
|
+
t.string :last_known_timezone
|
17
|
+
t.timestamp :last_known_timezone_update
|
18
|
+
|
19
|
+
## Database authenticatable
|
20
|
+
t.string :email, null: false, default: ""
|
21
|
+
t.string :encrypted_password, null: false, default: ""
|
22
|
+
|
23
|
+
## Recoverable
|
24
|
+
t.string :reset_password_token
|
25
|
+
t.datetime :reset_password_sent_at
|
26
|
+
|
27
|
+
## Rememberable
|
28
|
+
t.datetime :remember_created_at
|
29
|
+
|
30
|
+
## Trackable
|
31
|
+
t.integer :sign_in_count, default: 0, null: false
|
32
|
+
t.datetime :current_sign_in_at
|
33
|
+
t.datetime :last_sign_in_at
|
34
|
+
t.string :current_sign_in_ip
|
35
|
+
t.string :last_sign_in_ip
|
36
|
+
|
37
|
+
## Confirmable
|
38
|
+
# t.string :confirmation_token
|
39
|
+
# t.datetime :confirmed_at
|
40
|
+
# t.datetime :confirmation_sent_at
|
41
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
42
|
+
|
43
|
+
## Lockable
|
44
|
+
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
45
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
46
|
+
# t.datetime :locked_at
|
47
|
+
|
48
|
+
t.timestamps
|
49
|
+
end
|
50
|
+
|
51
|
+
add_index :users, :email, unique: true
|
52
|
+
add_index :users, :phone_number, unique: true
|
53
|
+
add_index :users, :reset_password_token, unique: true
|
54
|
+
add_index :users, :active
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateRailsBaseShortLivedData < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :short_lived_data do |t|
|
4
|
+
|
5
|
+
t.integer :user_id, null: false
|
6
|
+
t.string :data, null: false
|
7
|
+
t.string :reason
|
8
|
+
t.datetime :death_time, null: false
|
9
|
+
t.string :extra
|
10
|
+
t.integer :exclusive_use_count, default: 0
|
11
|
+
t.integer :exclusive_use_count_max
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :short_lived_data, :data
|
17
|
+
add_index :short_lived_data, [:data, :reason]
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateRailsBaseAdminActions < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
create_table :admin_actions do |t|
|
4
|
+
t.bigint :admin_user_id, null: false
|
5
|
+
t.bigint :user_id
|
6
|
+
t.string :action , null: false
|
7
|
+
t.string :change_from
|
8
|
+
t.string :change_to
|
9
|
+
t.text :long_action
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :admin_actions, :admin_user_id
|
15
|
+
add_index :admin_actions, :user_id
|
16
|
+
end
|
17
|
+
end
|
data/db/seeds.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
params = {
|
3
|
+
email: "mattius.taylor@gmail.com",
|
4
|
+
first_name: 'Some',
|
5
|
+
last_name: 'Guy',
|
6
|
+
phone_number: '6508675309',
|
7
|
+
password: "password1",
|
8
|
+
password_confirmation: "password1"
|
9
|
+
}
|
10
|
+
|
11
|
+
User.create!(params)
|
12
|
+
|
13
|
+
|
14
|
+
params = {
|
15
|
+
email: "#{ENV['GMAIL_USER_NAME']}@gmail.com",
|
16
|
+
first_name: 'Some2',
|
17
|
+
last_name: 'Guy2',
|
18
|
+
phone_number: '6508675309',
|
19
|
+
password: "password2",
|
20
|
+
password_confirmation: "password2"
|
21
|
+
}
|
22
|
+
|
23
|
+
User.create!(params)
|