Facebook
From Lousy Armadillo, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 154
  1. # frozen_string_literal: true
  2. #! config/initializers/devise.rb
  3.  
  4. #! Create custom failure for turbo
  5. class TurboFailureApp < Devise::FailureApp
  6.   def respond
  7.     if request_format == :turbo_stream
  8.       redirect
  9.     else
  10.       super
  11.     end
  12.   end
  13.  
  14.   def skip_format?
  15.     %w(html turbo_stream */*).include? request_format.to_s
  16.   end
  17. end
  18.  
  19. # Assuming you have not yet modified this file, each configuration option below
  20. # is set to its default value. Note that some are commented out while others
  21. # are not: uncommented lines are intended to protect your configuration from
  22. # breaking changes in upgrades (i.e., in the event that future versions of
  23. # Devise change the default values for those options).
  24. #
  25. # Use this hook to configure devise mailer, warden hooks and so forth.
  26. # Many of these configuration options can be set straight in your model.
  27. Devise.setup do |config|
  28.   # The secret key used by Devise. Devise uses this key to generate
  29.   # random tokens. Changing this key will render invalid all existing
  30.   # confirmation, reset password and unlock tokens in the database.
  31.   # Devise will use the `secret_key_base` as its `secret_key`
  32.   # by default. You can change it below and use your own secret key.
  33.   # config.secret_key = '7631b25364a858ca17e7181b0d1772aa59a6e283e18aafecb41ec5819ceb035d83dcf45e98aaffa5faf2b601fb062c128fcf0678f9c4f3eac2086f510063a7b3'
  34.  
  35.   # ==> Controller configuration
  36.   # Configure the parent class to the devise controllers.
  37.  
  38.   #! Change parent controller with custom controller
  39.   config.parent_controller = 'Users::DeviseController'
  40.  
  41.   # ==> Mailer Configuration
  42.   # Configure the e-mail address which will be shown in Devise::Mailer,
  43.   # note that it will be overwritten if you use your own mailer class
  44.   # with default "from" parameter.
  45.   config.mailer_sender = '[email protected]'
  46.  
  47.   # Configure the class responsible to send e-mails.
  48.   # config.mailer = 'Devise::Mailer'
  49.  
  50.   # Configure the parent class responsible to send e-mails.
  51.   # config.parent_mailer = 'ActionMailer::Base'
  52.  
  53.   # ==> ORM configuration
  54.   # Load and configure the ORM. Supports :active_record (default) and
  55.   # :mongoid (bson_ext recommended) by default. Other ORMs may be
  56.   # available as additional gems.
  57.   require 'devise/orm/active_record'
  58.  
  59.   # ==> Configuration for any authentication mechanism
  60.   # Configure which keys are used when authenticating a user. The default is
  61.   # just :email. You can configure it to use [:username, :subdomain], so for
  62.   # authenticating a user, both parameters are required. Remember that those
  63.   # parameters are used only when authenticating and not when retrieving from
  64.   # session. If you need permissions, you should implement that in a before filter.
  65.   # You can also supply a hash where the value is a boolean determining whether
  66.   # or not authentication should be aborted when the value is not present.
  67.   # config.authentication_keys = [:email]
  68.  
  69.   # Configure parameters from the request object used for authentication. Each entry
  70.   # given should be a request method and it will automatically be passed to the
  71.   # find_for_authentication method and considered in your model lookup. For instance,
  72.   # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
  73.   # The same considerations mentioned for authentication_keys also apply to request_keys.
  74.   # config.request_keys = []
  75.  
  76.   # Configure which authentication keys should be case-insensitive.
  77.   # These keys will be downcased upon creating or modifying a user and when used
  78.   # to authenticate or find a user. Default is :email.
  79.   config.case_insensitive_keys = [:email]
  80.  
  81.   # Configure which authentication keys should have whitespace stripped.
  82.   # These keys will have whitespace before and after removed upon creating or
  83.   # modifying a user and when used to authenticate or find a user. Default is :email.
  84.   config.strip_whitespace_keys = [:email]
  85.  
  86.   # Tell if authentication through request.params is enabled. True by default.
  87.   # It can be set to an array that will enable params authentication only for the
  88.   # given strategies, for example, `config.params_authenticatable = [:database]` will
  89.   # enable it only for database (email + password) authentication.
  90.   # config.params_authenticatable = true
  91.  
  92.   # Tell if authentication through HTTP Auth is enabled. False by default.
  93.   # It can be set to an array that will enable http authentication only for the
  94.   # given strategies, for example, `config.http_authenticatable = [:database]` will
  95.   # enable it only for database authentication.
  96.   # For API-only applications to support authentication "out-of-the-box", you will likely want to
  97.   # enable this with :database unless you are using a custom strategy.
  98.   # The supported strategies are:
  99.   # :database      = Support basic authentication with authentication key + password
  100.   # config.http_authenticatable = false
  101.  
  102.   # If 401 status code should be returned for AJAX requests. True by default.
  103.   # config.http_authenticatable_on_xhr = true
  104.  
  105.   # The realm used in Http Basic Authentication. 'Application' by default.
  106.   # config.http_authentication_realm = 'Application'
  107.  
  108.   # It will change confirmation, password recovery and other workflows
  109.   # to behave the same regardless if the e-mail provided was right or wrong.
  110.   # Does not affect registerable.
  111.   # config.paranoid = true
  112.  
  113.   # By default Devise will store the user in session. You can skip storage for
  114.   # particular strategies by setting this option.
  115.   # Notice that if you are skipping storage for all authentication paths, you
  116.   # may want to disable generating routes to Devise's sessions controller by
  117.   # passing skip: :sessions to `devise_for` in your config/routes.rb
  118.   config.skip_session_storage = [:http_auth]
  119.  
  120.   # By default, Devise cleans up the CSRF token on authentication to
  121.   # avoid CSRF token fixation attacks. This means that, when using AJAX
  122.   # requests for sign in and sign up, you need to get a new CSRF token
  123.   # from the server. You can disable this option at your own risk.
  124.   # config.clean_up_csrf_token_on_authentication = true
  125.  
  126.   # When false, Devise will not attempt to reload routes on eager load.
  127.   # This can reduce the time taken to boot the app but if your application
  128.   # requires the Devise mappings to be loaded during boot time the application
  129.   # won't boot properly.
  130.   # config.reload_routes = true
  131.  
  132.   # ==> Configuration for :database_authenticatable
  133.   # For bcrypt, this is the cost for hashing the password and defaults to 12. If
  134.   # using other algorithms, it sets how many times you want the password to be hashed.
  135.   # The number of stretches used for generating the hashed password are stored
  136.   # with the hashed password. This allows you to change the stretches without
  137.   # invalidating existing passwords.
  138.   #
  139.   # Limiting the stretches to just one in testing will increase the performance of
  140.   # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
  141.   # a value less than 10 in other environments. Note that, for bcrypt (the default
  142.   # algorithm), the cost increases exponentially with the number of stretches (e.g.
  143.   # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
  144.   config.stretches = Rails.env.test? ? 1 : 12
  145.  
  146.   # Set up a pepper to generate the hashed password.
  147.   # config.pepper = 'd3246b12f47134dbd11146093342c63b068f89d767fdb0df6af01afcd7d592d3e08fc9e4cf9b3453079067293f840da3bfd0bff77c0b3aa96cd8c616bec50457'
  148.  
  149.   # Send a notification to the original email when the user's email is changed.
  150.   # config.send_email_changed_notification = false
  151.  
  152.   # Send a notification email when the user's password is changed.
  153.   # config.send_password_change_notification = false
  154.  
  155.   # ==> Configuration for :confirmable
  156.   # A period that the user is allowed to access the website even without
  157.   # confirming their account. For instance, if set to 2.days, the user will be
  158.   # able to access the website for two days without confirming their account,
  159.   # access will be blocked just in the third day.
  160.   # You can also set it to nil, which will allow the user to access the website
  161.   # without confirming their account.
  162.   # Default is 0.days, meaning the user cannot access the website without
  163.   # confirming their account.
  164.   # config.allow_unconfirmed_access_for = 2.days
  165.  
  166.   # A period that the user is allowed to confirm their account before their
  167.   # token becomes invalid. For example, if set to 3.days, the user can confirm
  168.   # their account within 3 days after the mail was sent, but on the fourth day
  169.   # their account can't be confirmed with the token any more.
  170.   # Default is nil, meaning there is no restriction on how long a user can take
  171.   # before confirming their account.
  172.   # config.confirm_within = 3.days
  173.  
  174.   # If true, requires any email changes to be confirmed (exactly the same way as
  175.   # initial account confirmation) to be applied. Requires additional unconfirmed_email
  176.   # db field (see migrations). Until confirmed, new email is stored in
  177.   # unconfirmed_email column, and copied to email column on successful confirmation.
  178.   config.reconfirmable = true
  179.  
  180.   # Defines which key will be used when confirming an account
  181.   # config.confirmation_keys = [:email]
  182.  
  183.   # ==> Configuration for :rememberable
  184.   # The time the user will be remembered without asking for credentials again.
  185.   # config.remember_for = 2.weeks
  186.  
  187.   # Invalidates all the remember me tokens when the user signs out.
  188.   config.expire_all_remember_me_on_sign_out = true
  189.  
  190.   # If true, extends the user's remember period when remembered via cookie.
  191.   # config.extend_remember_period = false
  192.  
  193.   # Options to be passed to the created cookie. For instance, you can set
  194.   # secure: true in order to force SSL only cookies.
  195.   # config.rememberable_options = {}
  196.  
  197.   # ==> Configuration for :validatable
  198.   # Range for password length.
  199.   config.password_length = 6..128
  200.  
  201.   # Email regex used to validate email formats. It simply asserts that
  202.   # one (and only one) @ exists in the given string. This is mainly
  203.   # to give user feedback and not to assert the e-mail validity.
  204.   config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
  205.  
  206.   # ==> Configuration for :timeoutable
  207.   # The time you want to timeout the user session without activity. After this
  208.   # time the user will be asked for credentials again. Default is 30 minutes.
  209.   # config.timeout_in = 30.minutes
  210.  
  211.   # ==> Configuration for :lockable
  212.   # Defines which strategy will be used to lock an account.
  213.   # :failed_attempts = Locks an account after a number of failed attempts to sign in.
  214.   # :none            = No lock strategy. You should handle locking by yourself.
  215.   # config.lock_strategy = :failed_attempts
  216.  
  217.   # Defines which key will be used when locking and unlocking an account
  218.   # config.unlock_keys = [:email]
  219.  
  220.   # Defines which strategy will be used to unlock an account.
  221.   # :email = Sends an unlock link to the user email
  222.   # :time  = Re-enables login after a certain amount of time (see :unlock_in below)
  223.   # :both  = Enables both strategies
  224.   # :none  = No unlock strategy. You should handle unlocking by yourself.
  225.   # config.unlock_strategy = :both
  226.  
  227.   # Number of authentication tries before locking an account if lock_strategy
  228.   # is failed attempts.
  229.   # config.maximum_attempts = 20
  230.  
  231.   # Time interval to unlock the account if :time is enabled as unlock_strategy.
  232.   # config.unlock_in = 1.hour
  233.  
  234.   # Warn on the last attempt before the account is locked.
  235.   # config.last_attempt_warning = true
  236.  
  237.   # ==> Configuration for :recoverable
  238.   #
  239.   # Defines which key will be used when recovering the password for an account
  240.   # config.reset_password_keys = [:email]
  241.  
  242.   # Time interval you can reset your password with a reset password key.
  243.   # Don't put a too small interval or your users won't have the time to
  244.   # change their passwords.
  245.   config.reset_password_within = 6.hours
  246.  
  247.   # When set to false, does not sign a user in automatically after their password is
  248.   # reset. Defaults to true, so a user is signed in automatically after a reset.
  249.   # config.sign_in_after_reset_password = true
  250.  
  251.   # ==> Configuration for :encryptable
  252.   # Allow you to use another hashing or encryption algorithm besides bcrypt (default).
  253.   # You can use :sha1, :sha512 or algorithms from others authentication tools as
  254.   # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
  255.   # for default behavior) and :restful_authentication_sha1 (then you should set
  256.   # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
  257.   #
  258.   # Require the `devise-encryptable` gem when using anything other than bcrypt
  259.   # config.encryptor = :sha512
  260.  
  261.   # ==> Scopes configuration
  262.   # Turn scoped views on. Before rendering "sessions/new", it will first check for
  263.   # "users/sessions/new". It's turned off by default because it's slower if you
  264.   # are using only default views.
  265.   # config.scoped_views = false
  266.  
  267.   # Configure the default scope given to Warden. By default it's the first
  268.   # devise role declared in your routes (usually :user).
  269.   # config.default_scope = :user
  270.  
  271.   # Set this configuration to false if you want /users/sign_out to sign out
  272.   # only the current scope. By default, Devise signs out all scopes.
  273.   # config.sign_out_all_scopes = true
  274.  
  275.   # ==> Navigation configuration
  276.   # Lists the formats that should be treated as navigational. Formats like
  277.   # :html, should redirect to the sign in page when the user does not have
  278.   # access, but formats like :xml or :json, should return 401.
  279.   #
  280.   # If you have any extra navigational formats, like :iphone or :mobile, you
  281.   # should add them to the navigational formats lists.
  282.   #
  283.   # The "*/*" below is required to match Internet Explorer requests.
  284.  
  285.   #! Override navigational_formats
  286.   config.navigational_formats = ['*/*', :html, :turbo_stream]
  287.  
  288.   # The default HTTP method used to sign out a resource. Default is :delete.
  289.   config.sign_out_via = :get
  290.  
  291.   # ==> OmniAuth
  292.   # Add a new OmniAuth provider. Check the wiki for more information on setting
  293.   # up on your models and hooks.
  294.   # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
  295.  
  296.   # ==> Warden configuration
  297.   # If you want to use other strategies, that are not supported by Devise, or
  298.   # change the failure app, you can configure them inside the config.warden block.
  299.   #
  300.  
  301.   #! Set custom failure
  302.   config.warden do |manager|
  303.     manager.failure_app = TurboFailureApp
  304.   #   manager.intercept_401 = false
  305.   #   manager.default_strategies(scope: :user).unshift :some_external_strategy
  306.   end
  307.  
  308.   # ==> Mountable engine configurations
  309.   # When using Devise inside an engine, let's call it `MyEngine`, and this engine
  310.   # is mountable, there are some extra configurations to be taken into account.
  311.   # The following options are available, assuming the engine is mounted as:
  312.   #
  313.   #     mount MyEngine, at: '/my_engine'
  314.   #
  315.   # The router that invoked `devise_for`, in the example above, would be:
  316.   # config.router_name = :my_engine
  317.   #
  318.   # When using OmniAuth, Devise cannot automatically set OmniAuth path,
  319.   # so you need to do it manually. For the users scope, it would be:
  320.   # config.omniauth_path_prefix = '/my_engine/users/auth'
  321.  
  322.   # ==> Turbolinks configuration
  323.   # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly:
  324.   #
  325.   # ActiveSupport.on_load(:devise_failure_app) do
  326.   #   include Turbolinks::Controller
  327.   # end
  328.  
  329.   # ==> Configuration for :registerable
  330.  
  331.   # When set to false, does not sign a user in automatically after their password is
  332.   # changed. Defaults to true, so a user is signed in automatically after changing a password.
  333.   # config.sign_in_after_change_password = true
  334. end
  335.