Class: RailsSimpleAuth::Configuration
- Inherits:
-
Object
- Object
- RailsSimpleAuth::Configuration
- Defined in:
- lib/rails_simple_auth/configuration.rb
Instance Attribute Summary collapse
-
#after_confirmation_callback ⇒ Object
Returns the value of attribute after_confirmation_callback.
-
#after_confirmation_path ⇒ Object
Returns the value of attribute after_confirmation_path.
-
#after_sign_in_callback ⇒ Object
Returns the value of attribute after_sign_in_callback.
-
#after_sign_in_path ⇒ Object
Returns the value of attribute after_sign_in_path.
-
#after_sign_out_callback ⇒ Object
Returns the value of attribute after_sign_out_callback.
-
#after_sign_out_path ⇒ Object
Returns the value of attribute after_sign_out_path.
-
#after_sign_up_callback ⇒ Object
Returns the value of attribute after_sign_up_callback.
-
#after_sign_up_path ⇒ Object
Returns the value of attribute after_sign_up_path.
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#confirmation_expiry ⇒ Object
Returns the value of attribute confirmation_expiry.
-
#email_confirmation_enabled ⇒ Object
Returns the value of attribute email_confirmation_enabled.
-
#layout ⇒ Object
Returns the value of attribute layout.
-
#magic_link_enabled ⇒ Object
Returns the value of attribute magic_link_enabled.
-
#magic_link_expiry ⇒ Object
Returns the value of attribute magic_link_expiry.
-
#mailer_class ⇒ Object
Returns the value of attribute mailer_class.
-
#mailer_sender ⇒ Object
Returns the value of attribute mailer_sender.
-
#oauth_enabled ⇒ Object
Returns the value of attribute oauth_enabled.
-
#oauth_link_existing_accounts ⇒ Object
Returns the value of attribute oauth_link_existing_accounts.
-
#oauth_provider_names ⇒ Object
Returns the value of attribute oauth_provider_names.
-
#oauth_providers ⇒ Object
Returns the value of attribute oauth_providers.
-
#password_minimum_length ⇒ Object
Returns the value of attribute password_minimum_length.
-
#password_reset_expiry ⇒ Object
Returns the value of attribute password_reset_expiry.
-
#rate_limits ⇒ Object
Returns the value of attribute rate_limits.
-
#session_class_name ⇒ Object
Returns the value of attribute session_class_name.
-
#session_expiry ⇒ Object
Returns the value of attribute session_expiry.
-
#temporary_user_cleanup_days ⇒ Object
Returns the value of attribute temporary_user_cleanup_days.
-
#temporary_users_enabled ⇒ Object
Returns the value of attribute temporary_users_enabled.
-
#user_class_name ⇒ Object
Returns the value of attribute user_class_name.
Instance Method Summary collapse
-
#enable_oauth(*providers) ⇒ Object
Enable OAuth providers with optional display names Usage: enable_oauth(:google_oauth2, :github) # Uses default display names enable_oauth(google_oauth2: “Google”, github: “GitHub”) # Custom display names.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #mailer ⇒ Object
-
#oauth_provider_display_name(provider) ⇒ Object
Get display name for an OAuth provider Falls back to titleized provider name if no custom name is configured.
- #oauth_provider_enabled?(provider) ⇒ Boolean
- #rate_limit_for(action) ⇒ Object
- #session_class ⇒ Object
- #user_class ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rails_simple_auth/configuration.rb', line 18 def initialize @magic_link_enabled = true @email_confirmation_enabled = true @oauth_enabled = false @oauth_providers = [] @oauth_provider_names = {} @oauth_link_existing_accounts = true # Allow OAuth to link to existing email accounts @magic_link_expiry = 15.minutes @password_reset_expiry = 15.minutes @confirmation_expiry = 24.hours @session_expiry = 30.days @rate_limits = { sign_in: { limit: 5, period: 15.minutes }, sign_up: { limit: 5, period: 1.hour }, magic_link: { limit: 3, period: 10.minutes }, password_reset: { limit: 3, period: 1.hour }, confirmation: { limit: 3, period: 1.hour } } @after_sign_in_path = :root_path @after_sign_out_path = :new_session_path @after_sign_up_path = :root_path @after_confirmation_path = :new_session_path @layout = 'rails_simple_auth' @app_name = nil @mailer_sender = 'noreply@example.com' @mailer_class = 'RailsSimpleAuth::AuthMailer' @user_class_name = 'User' @session_class_name = 'RailsSimpleAuth::Session' @password_minimum_length = 8 @after_sign_in_callback = nil @after_sign_out_callback = nil @after_sign_up_callback = nil @after_confirmation_callback = nil @temporary_users_enabled = false @temporary_user_cleanup_days = 7 end |
Instance Attribute Details
#after_confirmation_callback ⇒ Object
Returns the value of attribute after_confirmation_callback.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def after_confirmation_callback @after_confirmation_callback end |
#after_confirmation_path ⇒ Object
Returns the value of attribute after_confirmation_path.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def after_confirmation_path @after_confirmation_path end |
#after_sign_in_callback ⇒ Object
Returns the value of attribute after_sign_in_callback.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def after_sign_in_callback @after_sign_in_callback end |
#after_sign_in_path ⇒ Object
Returns the value of attribute after_sign_in_path.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def after_sign_in_path @after_sign_in_path end |
#after_sign_out_callback ⇒ Object
Returns the value of attribute after_sign_out_callback.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def after_sign_out_callback @after_sign_out_callback end |
#after_sign_out_path ⇒ Object
Returns the value of attribute after_sign_out_path.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def after_sign_out_path @after_sign_out_path end |
#after_sign_up_callback ⇒ Object
Returns the value of attribute after_sign_up_callback.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def after_sign_up_callback @after_sign_up_callback end |
#after_sign_up_path ⇒ Object
Returns the value of attribute after_sign_up_path.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def after_sign_up_path @after_sign_up_path end |
#app_name ⇒ Object
Returns the value of attribute app_name.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def app_name @app_name end |
#confirmation_expiry ⇒ Object
Returns the value of attribute confirmation_expiry.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def confirmation_expiry @confirmation_expiry end |
#email_confirmation_enabled ⇒ Object
Returns the value of attribute email_confirmation_enabled.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def email_confirmation_enabled @email_confirmation_enabled end |
#layout ⇒ Object
Returns the value of attribute layout.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def layout @layout end |
#magic_link_enabled ⇒ Object
Returns the value of attribute magic_link_enabled.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def magic_link_enabled @magic_link_enabled end |
#magic_link_expiry ⇒ Object
Returns the value of attribute magic_link_expiry.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def magic_link_expiry @magic_link_expiry end |
#mailer_class ⇒ Object
Returns the value of attribute mailer_class.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def mailer_class @mailer_class end |
#mailer_sender ⇒ Object
Returns the value of attribute mailer_sender.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def mailer_sender @mailer_sender end |
#oauth_enabled ⇒ Object
Returns the value of attribute oauth_enabled.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def oauth_enabled @oauth_enabled end |
#oauth_link_existing_accounts ⇒ Object
Returns the value of attribute oauth_link_existing_accounts.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def oauth_link_existing_accounts @oauth_link_existing_accounts end |
#oauth_provider_names ⇒ Object
Returns the value of attribute oauth_provider_names.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def oauth_provider_names @oauth_provider_names end |
#oauth_providers ⇒ Object
Returns the value of attribute oauth_providers.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def oauth_providers @oauth_providers end |
#password_minimum_length ⇒ Object
Returns the value of attribute password_minimum_length.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def password_minimum_length @password_minimum_length end |
#password_reset_expiry ⇒ Object
Returns the value of attribute password_reset_expiry.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def password_reset_expiry @password_reset_expiry end |
#rate_limits ⇒ Object
Returns the value of attribute rate_limits.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def rate_limits @rate_limits end |
#session_class_name ⇒ Object
Returns the value of attribute session_class_name.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def session_class_name @session_class_name end |
#session_expiry ⇒ Object
Returns the value of attribute session_expiry.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def session_expiry @session_expiry end |
#temporary_user_cleanup_days ⇒ Object
Returns the value of attribute temporary_user_cleanup_days.
16 17 18 |
# File 'lib/rails_simple_auth/configuration.rb', line 16 def temporary_user_cleanup_days @temporary_user_cleanup_days end |
#temporary_users_enabled ⇒ Object
Returns the value of attribute temporary_users_enabled.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def temporary_users_enabled @temporary_users_enabled end |
#user_class_name ⇒ Object
Returns the value of attribute user_class_name.
5 6 7 |
# File 'lib/rails_simple_auth/configuration.rb', line 5 def user_class_name @user_class_name end |
Instance Method Details
#enable_oauth(*providers) ⇒ Object
Enable OAuth providers with optional display names Usage:
enable_oauth(:google_oauth2, :github) # Uses default display names
enable_oauth(google_oauth2: "Google", github: "GitHub") # Custom display names
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rails_simple_auth/configuration.rb', line 95 def enable_oauth(*providers) self.oauth_enabled = true if providers.length == 1 && providers.first.is_a?(Hash) # Hash format: { google_oauth2: "Google", github: "GitHub" } provider_hash = providers.first self.oauth_providers = provider_hash.keys.map(&:to_sym) self.oauth_provider_names = provider_hash.transform_keys(&:to_sym) else # Symbol format: :google_oauth2, :github (backward compatible) self.oauth_providers = providers.map(&:to_sym) self.oauth_provider_names = {} end end |
#mailer ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/rails_simple_auth/configuration.rb', line 82 def mailer mailer_class.constantize rescue NameError => e raise ConfigurationError, "Mailer class '#{mailer_class}' not found. " \ "Ensure it's defined and the name is correct in the initializer. " \ "Original error: #{e.}" end |
#oauth_provider_display_name(provider) ⇒ Object
Get display name for an OAuth provider Falls back to titleized provider name if no custom name is configured
116 117 118 119 |
# File 'lib/rails_simple_auth/configuration.rb', line 116 def oauth_provider_display_name(provider) provider_sym = provider.to_sym oauth_provider_names[provider_sym] || provider.to_s.gsub(/_oauth2$/, '').titleize end |
#oauth_provider_enabled?(provider) ⇒ Boolean
110 111 112 |
# File 'lib/rails_simple_auth/configuration.rb', line 110 def oauth_provider_enabled?(provider) oauth_enabled && oauth_providers.include?(provider.to_sym) end |
#rate_limit_for(action) ⇒ Object
121 122 123 |
# File 'lib/rails_simple_auth/configuration.rb', line 121 def rate_limit_for(action) rate_limits&.dig(action.to_sym) end |
#session_class ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/rails_simple_auth/configuration.rb', line 73 def session_class session_class_name.constantize rescue NameError => e raise ConfigurationError, "Session class '#{session_class_name}' not found. " \ "Ensure it's defined and the name is correct in the initializer. " \ "Original error: #{e.}" end |
#user_class ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/rails_simple_auth/configuration.rb', line 64 def user_class user_class_name.constantize rescue NameError => e raise ConfigurationError, "User class '#{user_class_name}' not found. " \ "Ensure it's defined and the name is correct in the initializer. " \ "Original error: #{e.}" end |