rodauth-rails 1.5.5 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +4 -4
  4. data/lib/generators/rodauth/install_generator.rb +2 -0
  5. data/lib/generators/rodauth/migration/active_record/account_expiration.erb +2 -1
  6. data/lib/generators/rodauth/migration/active_record/email_auth.erb +2 -2
  7. data/lib/generators/rodauth/migration/active_record/lockout.erb +4 -2
  8. data/lib/generators/rodauth/migration/active_record/otp.erb +2 -1
  9. data/lib/generators/rodauth/migration/active_record/password_expiration.erb +2 -1
  10. data/lib/generators/rodauth/migration/active_record/recovery_codes.erb +1 -1
  11. data/lib/generators/rodauth/migration/active_record/remember.erb +2 -1
  12. data/lib/generators/rodauth/migration/active_record/reset_password.erb +2 -1
  13. data/lib/generators/rodauth/migration/active_record/single_session.erb +2 -1
  14. data/lib/generators/rodauth/migration/active_record/sms_codes.erb +2 -1
  15. data/lib/generators/rodauth/migration/active_record/verify_account.erb +2 -1
  16. data/lib/generators/rodauth/migration/active_record/verify_login_change.erb +2 -1
  17. data/lib/generators/rodauth/migration/active_record/webauthn.erb +2 -1
  18. data/lib/generators/rodauth/migration_generator.rb +10 -4
  19. data/lib/generators/rodauth/templates/app/mailers/rodauth_mailer.rb +6 -6
  20. data/lib/generators/rodauth/templates/app/misc/rodauth_app.rb +2 -2
  21. data/lib/generators/rodauth/templates/app/misc/rodauth_main.rb +8 -6
  22. data/lib/rodauth/rails/controller_methods.rb +1 -1
  23. data/lib/rodauth/rails/feature/internal_request.rb +4 -2
  24. data/lib/rodauth/rails/feature.rb +2 -2
  25. data/lib/rodauth/rails/version.rb +1 -1
  26. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9640fa912cb535846cd94b3df3361e9763f2267107205287783885e587e774b
4
- data.tar.gz: d135e8e958f0210b22fe694ba2a77e6d4fde74df339b8ec06440ac0f83771c90
3
+ metadata.gz: 5ff93d3c4aca14c931fdf919c2eae17371105b3c4ca6cf584d699892cb705c7b
4
+ data.tar.gz: 6bb909fe804de850bd1db16c4b0c0099f8755e1f17e874ab8973cfb1563cc88e
5
5
  SHA512:
6
- metadata.gz: 1067a2467e0f7dacbfe3a703d6f1e4ad561c9dc7a72fbe3942a20b43b8892211c2509ec3b71c47ba30bf16bea0f7163f8ecb82a5aceaabb23f01a5705d256d12
7
- data.tar.gz: ce2464227d1c0a5e5bc3452f05c392787b61fd6b3c530a89c99047c69a4bcceabf08778aaa169c57fa39dbae80efdb455b334881f04b069099fab7b666dc1cfe
6
+ metadata.gz: d49446ff0285df582268de3c4dc03eef155d3dea86a3887442412ed7a84469bb4af99781e0771c98edc895ea5c5b614ab549a3042c472108a24567676592fe2e
7
+ data.tar.gz: c40379f9ec9c15152018fb7e6b0be8cf880ff4b59726615ccb3954ee7bfe529122258fc1f838e4b67581b8cfeff285ff2ad60dcfbb06fc0773eefa3c3ab9ba54
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 1.6.1 (2022-09-19)
2
+
3
+ * Fix argument error when calling `RodauthMailer` in default configuration (@janko)
4
+
5
+ ## 1.6.0 (2022-09-14)
6
+
7
+ * Avoid creating IDENTITY columns for primary foreign keys on SQL Server with Active Record (@janko)
8
+
9
+ * Make configuration name argument required in generated `RodauthMailer` (@janko)
10
+
11
+ * Make the Rails integration work without Action Mailer loaded (@janko)
12
+
13
+ * Don't redirect to login page when account is missing in `current_account` method (@janko)
14
+
1
15
  ## 1.5.5 (2022-08-04)
2
16
 
3
17
  * Don't raise `ArgumentError` when calling `#current_account` without being logged in (@benkoshy)
data/README.md CHANGED
@@ -194,7 +194,7 @@ class RodauthApp < Rodauth::Rails::App
194
194
 
195
195
  # require authentication for /dashboard/* and /account/* routes
196
196
  if r.path.start_with?("/dashboard") || r.path.start_with?("/account")
197
- rodauth.require_authentication # redirect to login page if not authenticated
197
+ rodauth.require_account # redirect to login page if not authenticated
198
198
  end
199
199
  end
200
200
  end
@@ -208,7 +208,7 @@ class ApplicationController < ActionController::Base
208
208
  private
209
209
 
210
210
  def authenticate
211
- rodauth.require_authentication # redirect to login page if not authenticated
211
+ rodauth.require_account # redirect to login page if not authenticated
212
212
  end
213
213
  end
214
214
  ```
@@ -727,7 +727,7 @@ For controller tests, you can log in accounts by modifying the session:
727
727
  ```rb
728
728
  # app/controllers/articles_controller.rb
729
729
  class ArticlesController < ApplicationController
730
- before_action -> { rodauth.require_authentication }
730
+ before_action -> { rodauth.require_account }
731
731
 
732
732
  def index
733
733
  # ...
@@ -951,7 +951,7 @@ end
951
951
 
952
952
  In addition to Zeitwerk compatibility, this extra layer catches Rodauth redirects
953
953
  that happen on the controller level (e.g. when calling
954
- `rodauth.require_authentication` in a `before_action` filter).
954
+ `rodauth.require_account` in a `before_action` filter).
955
955
 
956
956
  ### Roda app
957
957
 
@@ -63,6 +63,8 @@ module Rodauth
63
63
  end
64
64
 
65
65
  def create_mailer
66
+ return unless defined?(ActionMailer)
67
+
66
68
  template "app/mailers/rodauth_mailer.rb"
67
69
 
68
70
  MAILER_VIEWS.each do |view|
@@ -1,5 +1,6 @@
1
1
  # Used by the account expiration feature
2
- create_table :account_activity_times<%= primary_key_type %> do |t|
2
+ create_table :account_activity_times, id: false do |t|
3
+ t.<%= primary_key_type(nil) %> :id, primary_key: true
3
4
  t.foreign_key :accounts, column: :id
4
5
  t.datetime :last_activity_at, null: false
5
6
  t.datetime :last_login_at, null: false
@@ -1,6 +1,6 @@
1
1
  # Used by the email auth feature
2
- create_table :account_email_auth_keys<%= primary_key_type %> do |t|
3
- t.foreign_key :accounts, column: :id
2
+ create_table :account_email_auth_keys, id: false do |t|
3
+ t.<%= primary_key_type(nil) %> :id, primary_key: true
4
4
  t.string :key, null: false
5
5
  t.datetime :deadline, null: false
6
6
  t.datetime :email_last_sent, null: false, default: <%= current_timestamp %>
@@ -1,9 +1,11 @@
1
1
  # Used by the lockout feature
2
- create_table :account_login_failures<%= primary_key_type %> do |t|
2
+ create_table :account_login_failures, id: false do |t|
3
+ t.<%= primary_key_type(nil) %> :id, primary_key: true
3
4
  t.foreign_key :accounts, column: :id
4
5
  t.integer :number, null: false, default: 1
5
6
  end
6
- create_table :account_lockouts<%= primary_key_type %> do |t|
7
+ create_table :account_lockouts, id: false do |t|
8
+ t.<%= primary_key_type(nil) %> :id, primary_key: true
7
9
  t.foreign_key :accounts, column: :id
8
10
  t.string :key, null: false
9
11
  t.datetime :deadline, null: false
@@ -1,5 +1,6 @@
1
1
  # Used by the otp feature
2
- create_table :account_otp_keys<%= primary_key_type %> do |t|
2
+ create_table :account_otp_keys, id: false do |t|
3
+ t.<%= primary_key_type(nil) %> :id, primary_key: true
3
4
  t.foreign_key :accounts, column: :id
4
5
  t.string :key, null: false
5
6
  t.integer :num_failures, null: false, default: 0
@@ -1,5 +1,6 @@
1
1
  # Used by the password expiration feature
2
- create_table :account_password_change_times<%= primary_key_type %> do |t|
2
+ create_table :account_password_change_times, id: false do |t|
3
+ t.<%= primary_key_type(nil) %> :id, primary_key: true
3
4
  t.foreign_key :accounts, column: :id
4
5
  t.datetime :changed_at, null: false, default: <%= current_timestamp %>
5
6
  end
@@ -1,6 +1,6 @@
1
1
  # Used by the recovery codes feature
2
2
  create_table :account_recovery_codes, primary_key: [:id, :code] do |t|
3
- t.column :id, :<%= primary_key_type(nil) || :bigint %>
3
+ t.<%= primary_key_type(nil) %> :id
4
4
  t.foreign_key :accounts, column: :id
5
5
  t.string :code
6
6
  end
@@ -1,5 +1,6 @@
1
1
  # Used by the remember me feature
2
- create_table :account_remember_keys<%= primary_key_type %> do |t|
2
+ create_table :account_remember_keys, id: false do |t|
3
+ t.<%= primary_key_type(nil) %> :id, primary_key: true
3
4
  t.foreign_key :accounts, column: :id
4
5
  t.string :key, null: false
5
6
  t.datetime :deadline, null: false
@@ -1,5 +1,6 @@
1
1
  # Used by the password reset feature
2
- create_table :account_password_reset_keys<%= primary_key_type %> do |t|
2
+ create_table :account_password_reset_keys, id: false do |t|
3
+ t.<%= primary_key_type(nil) %> :id, primary_key: true
3
4
  t.foreign_key :accounts, column: :id
4
5
  t.string :key, null: false
5
6
  t.datetime :deadline, null: false
@@ -1,5 +1,6 @@
1
1
  # Used by the single session feature
2
- create_table :account_session_keys<%= primary_key_type %> do |t|
2
+ create_table :account_session_keys, id: false do |t|
3
+ t.<%= primary_key_type(nil) %> :id, primary_key: true
3
4
  t.foreign_key :accounts, column: :id
4
5
  t.string :key, null: false
5
6
  end
@@ -1,5 +1,6 @@
1
1
  # Used by the sms codes feature
2
- create_table :account_sms_codes<%= primary_key_type %> do |t|
2
+ create_table :account_sms_codes, id: false do |t|
3
+ t.<%= primary_key_type(nil) %> :id, primary_key: true
3
4
  t.foreign_key :accounts, column: :id
4
5
  t.string :phone_number, null: false
5
6
  t.integer :num_failures
@@ -1,5 +1,6 @@
1
1
  # Used by the account verification feature
2
- create_table :account_verification_keys<%= primary_key_type %> do |t|
2
+ create_table :account_verification_keys, id: false do |t|
3
+ t.<%= primary_key_type(nil) %> :id, primary_key: true
3
4
  t.foreign_key :accounts, column: :id
4
5
  t.string :key, null: false
5
6
  t.datetime :requested_at, null: false, default: <%= current_timestamp %>
@@ -1,5 +1,6 @@
1
1
  # Used by the verify login change feature
2
- create_table :account_login_change_keys<%= primary_key_type %> do |t|
2
+ create_table :account_login_change_keys, id: false do |t|
3
+ t.<%= primary_key_type(nil) %> :id, primary_key: true
3
4
  t.foreign_key :accounts, column: :id
4
5
  t.string :key, null: false
5
6
  t.string :login, null: false
@@ -1,5 +1,6 @@
1
1
  # Used by the webauthn feature
2
- create_table :account_webauthn_user_ids<%= primary_key_type %> do |t|
2
+ create_table :account_webauthn_user_ids, id: false do |t|
3
+ t.<%= primary_key_type(nil) %> :id, primary_key: true
3
4
  t.foreign_key :accounts, column: :id
4
5
  t.string :webauthn_id, null: false
5
6
  end
@@ -93,12 +93,18 @@ module Rodauth
93
93
  generators = ::Rails.application.config.generators
94
94
  column_type = generators.options[:active_record][:primary_key_type]
95
95
 
96
- return unless column_type
97
-
98
96
  if key
99
- ", #{key}: :#{column_type}"
97
+ ", #{key}: :#{column_type}" if column_type
98
+ else
99
+ column_type || default_primary_key_type
100
+ end
101
+ end
102
+
103
+ def default_primary_key_type
104
+ if ActiveRecord.version >= Gem::Version.new("5.1") && activerecord_adapter != "sqlite3"
105
+ :bigint
100
106
  else
101
- column_type
107
+ :integer
102
108
  end
103
109
  end
104
110
 
@@ -1,19 +1,19 @@
1
1
  class RodauthMailer < ApplicationMailer
2
- def verify_account(name = nil, account_id, key)
2
+ def verify_account(name, account_id, key)
3
3
  @email_link = email_link(name, :verify_account, account_id, key)
4
4
  @account = find_account(name, account_id)
5
5
 
6
6
  mail to: @account.email, subject: rodauth(name).verify_account_email_subject
7
7
  end
8
8
 
9
- def reset_password(name = nil, account_id, key)
9
+ def reset_password(name, account_id, key)
10
10
  @email_link = email_link(name, :reset_password, account_id, key)
11
11
  @account = find_account(name, account_id)
12
12
 
13
13
  mail to: @account.email, subject: rodauth(name).reset_password_email_subject
14
14
  end
15
15
 
16
- def verify_login_change(name = nil, account_id, key)
16
+ def verify_login_change(name, account_id, key)
17
17
  @email_link = email_link(name, :verify_login_change, account_id, key)
18
18
  @account = find_account(name, account_id)
19
19
  @new_email = @account.login_change_key.login
@@ -21,20 +21,20 @@ class RodauthMailer < ApplicationMailer
21
21
  mail to: @new_email, subject: rodauth(name).verify_login_change_email_subject
22
22
  end
23
23
 
24
- def password_changed(name = nil, account_id)
24
+ def password_changed(name, account_id)
25
25
  @account = find_account(name, account_id)
26
26
 
27
27
  mail to: @account.email, subject: rodauth(name).password_changed_email_subject
28
28
  end
29
29
 
30
- # def email_auth(name = nil, account_id, key)
30
+ # def email_auth(name, account_id, key)
31
31
  # @email_link = email_link(name, :email_auth, account_id, key)
32
32
  # @account = find_account(name, account_id)
33
33
 
34
34
  # mail to: @account.email, subject: rodauth(name).email_auth_email_subject
35
35
  # end
36
36
 
37
- # def unlock_account(name = nil, account_id, key)
37
+ # def unlock_account(name, account_id, key)
38
38
  # @email_link = email_link(name, :unlock_account, account_id, key)
39
39
  # @account = find_account(name, account_id)
40
40
 
@@ -13,12 +13,12 @@ class RodauthApp < Rodauth::Rails::App
13
13
  r.rodauth # route rodauth requests
14
14
 
15
15
  # ==> Authenticating requests
16
- # Call `rodauth.require_authentication` for requests that you want to
16
+ # Call `rodauth.require_account` for requests that you want to
17
17
  # require authentication for. For example:
18
18
  #
19
19
  # # authenticate /dashboard/* and /account/* requests
20
20
  # if r.path.start_with?("/dashboard") || r.path.start_with?("/account")
21
- # rodauth.require_authentication
21
+ # rodauth.require_account
22
22
  # end
23
23
 
24
24
  # ==> Secondary configurations
@@ -56,31 +56,33 @@ class RodauthMain < Rodauth::Rails::Auth
56
56
  # Redirect to the app from login and registration pages if already logged in.
57
57
  # already_logged_in { redirect login_redirect }
58
58
 
59
+ <% if defined?(ActionMailer) -%>
59
60
  # ==> Emails
60
61
  # Use a custom mailer for delivering authentication emails.
61
62
  create_reset_password_email do
62
- RodauthMailer.reset_password(*self.class.configuration_name, account_id, reset_password_key_value)
63
+ RodauthMailer.reset_password(self.class.configuration_name, account_id, reset_password_key_value)
63
64
  end
64
65
  create_verify_account_email do
65
- RodauthMailer.verify_account(*self.class.configuration_name, account_id, verify_account_key_value)
66
+ RodauthMailer.verify_account(self.class.configuration_name, account_id, verify_account_key_value)
66
67
  end
67
68
  create_verify_login_change_email do |_login|
68
- RodauthMailer.verify_login_change(*self.class.configuration_name, account_id, verify_login_change_key_value)
69
+ RodauthMailer.verify_login_change(self.class.configuration_name, account_id, verify_login_change_key_value)
69
70
  end
70
71
  create_password_changed_email do
71
- RodauthMailer.password_changed(*self.class.configuration_name, account_id)
72
+ RodauthMailer.password_changed(self.class.configuration_name, account_id)
72
73
  end
73
74
  # create_email_auth_email do
74
- # RodauthMailer.email_auth(*self.class.configuration_name, account_id, email_auth_key_value)
75
+ # RodauthMailer.email_auth(self.class.configuration_name, account_id, email_auth_key_value)
75
76
  # end
76
77
  # create_unlock_account_email do
77
- # RodauthMailer.unlock_account(*self.class.configuration_name, account_id, unlock_account_key_value)
78
+ # RodauthMailer.unlock_account(self.class.configuration_name, account_id, unlock_account_key_value)
78
79
  # end
79
80
  send_email do |email|
80
81
  # queue email delivery on the mailer after the transaction commits
81
82
  db.after_commit { email.deliver_later }
82
83
  end
83
84
 
85
+ <% end -%>
84
86
  # ==> Flash
85
87
  <% unless json? || jwt? -%>
86
88
  # Match flash keys with ones already used in the Rails app.
@@ -9,7 +9,7 @@ module Rodauth
9
9
  end
10
10
 
11
11
  def current_account(name = nil)
12
- rodauth(name).rails_account || rodauth(name).login_required
12
+ rodauth(name).rails_account
13
13
  end
14
14
 
15
15
  def rodauth(name = nil)
@@ -3,13 +3,13 @@ module Rodauth
3
3
  module Feature
4
4
  module InternalRequest
5
5
  def domain
6
- return super unless missing_host?
6
+ return super unless missing_host? && rails_url_options
7
7
 
8
8
  rails_url_options.fetch(:host)
9
9
  end
10
10
 
11
11
  def base_url
12
- return super unless missing_host? && domain
12
+ return super unless missing_host? && domain && rails_url_options
13
13
 
14
14
  scheme = rails_url_options[:protocol] || "http"
15
15
  port = rails_url_options[:port]
@@ -43,6 +43,8 @@ module Rodauth
43
43
  end
44
44
 
45
45
  def rails_url_options
46
+ return nil unless defined?(ActionMailer)
47
+
46
48
  ::Rails.application.config.action_mailer.default_url_options or
47
49
  fail Error, "There is no information to set the URL host from. Please set config.action_mailer.default_url_options in your Rails application, or configure #domain and #base_url in your Rodauth configuration."
48
50
  end
@@ -8,7 +8,7 @@ module Rodauth
8
8
  require "rodauth/rails/feature/callbacks"
9
9
  require "rodauth/rails/feature/csrf"
10
10
  require "rodauth/rails/feature/render"
11
- require "rodauth/rails/feature/email"
11
+ require "rodauth/rails/feature/email" if defined?(ActionMailer)
12
12
  require "rodauth/rails/feature/instrumentation"
13
13
  require "rodauth/rails/feature/internal_request"
14
14
 
@@ -16,7 +16,7 @@ module Rodauth
16
16
  include Rodauth::Rails::Feature::Callbacks
17
17
  include Rodauth::Rails::Feature::Csrf
18
18
  include Rodauth::Rails::Feature::Render
19
- include Rodauth::Rails::Feature::Email
19
+ include Rodauth::Rails::Feature::Email if defined?(ActionMailer)
20
20
  include Rodauth::Rails::Feature::Instrumentation
21
21
  include Rodauth::Rails::Feature::InternalRequest
22
22
  end
@@ -1,5 +1,5 @@
1
1
  module Rodauth
2
2
  module Rails
3
- VERSION = "1.5.5"
3
+ VERSION = "1.6.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rodauth-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.5
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-04 00:00:00.000000000 Z
11
+ date: 2022-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties