rodauth-rails 1.3.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/README.md +9 -102
  4. data/lib/generators/rodauth/install_generator.rb +9 -10
  5. data/lib/generators/rodauth/migration/{account_expiration.erb → active_record/account_expiration.erb} +0 -0
  6. data/lib/generators/rodauth/migration/{active_sessions.erb → active_record/active_sessions.erb} +0 -0
  7. data/lib/generators/rodauth/migration/{audit_logging.erb → active_record/audit_logging.erb} +0 -0
  8. data/lib/generators/rodauth/migration/{base.erb → active_record/base.erb} +0 -0
  9. data/lib/generators/rodauth/migration/{disallow_password_reuse.erb → active_record/disallow_password_reuse.erb} +1 -1
  10. data/lib/generators/rodauth/migration/{email_auth.erb → active_record/email_auth.erb} +0 -0
  11. data/lib/generators/rodauth/migration/{jwt_refresh.erb → active_record/jwt_refresh.erb} +0 -0
  12. data/lib/generators/rodauth/migration/{lockout.erb → active_record/lockout.erb} +0 -0
  13. data/lib/generators/rodauth/migration/{otp.erb → active_record/otp.erb} +0 -0
  14. data/lib/generators/rodauth/migration/{password_expiration.erb → active_record/password_expiration.erb} +0 -0
  15. data/lib/generators/rodauth/migration/{recovery_codes.erb → active_record/recovery_codes.erb} +0 -0
  16. data/lib/generators/rodauth/migration/{remember.erb → active_record/remember.erb} +0 -0
  17. data/lib/generators/rodauth/migration/{reset_password.erb → active_record/reset_password.erb} +0 -0
  18. data/lib/generators/rodauth/migration/{single_session.erb → active_record/single_session.erb} +0 -0
  19. data/lib/generators/rodauth/migration/{sms_codes.erb → active_record/sms_codes.erb} +0 -0
  20. data/lib/generators/rodauth/migration/{verify_account.erb → active_record/verify_account.erb} +0 -0
  21. data/lib/generators/rodauth/migration/{verify_login_change.erb → active_record/verify_login_change.erb} +0 -0
  22. data/lib/generators/rodauth/migration/{webauthn.erb → active_record/webauthn.erb} +0 -0
  23. data/lib/generators/rodauth/migration/sequel/account_expiration.erb +7 -0
  24. data/lib/generators/rodauth/migration/sequel/active_sessions.erb +8 -0
  25. data/lib/generators/rodauth/migration/sequel/audit_logging.erb +17 -0
  26. data/lib/generators/rodauth/migration/sequel/base.erb +25 -0
  27. data/lib/generators/rodauth/migration/sequel/disallow_password_reuse.erb +6 -0
  28. data/lib/generators/rodauth/migration/sequel/email_auth.erb +7 -0
  29. data/lib/generators/rodauth/migration/sequel/jwt_refresh.erb +8 -0
  30. data/lib/generators/rodauth/migration/sequel/lockout.erb +11 -0
  31. data/lib/generators/rodauth/migration/sequel/otp.erb +7 -0
  32. data/lib/generators/rodauth/migration/sequel/password_expiration.erb +5 -0
  33. data/lib/generators/rodauth/migration/sequel/recovery_codes.erb +6 -0
  34. data/lib/generators/rodauth/migration/sequel/remember.erb +6 -0
  35. data/lib/generators/rodauth/migration/sequel/reset_password.erb +7 -0
  36. data/lib/generators/rodauth/migration/sequel/single_session.erb +5 -0
  37. data/lib/generators/rodauth/migration/sequel/sms_codes.erb +8 -0
  38. data/lib/generators/rodauth/migration/sequel/verify_account.erb +7 -0
  39. data/lib/generators/rodauth/migration/sequel/verify_login_change.erb +7 -0
  40. data/lib/generators/rodauth/migration/sequel/webauthn.erb +13 -0
  41. data/lib/generators/rodauth/migration_generator.rb +89 -9
  42. data/lib/generators/rodauth/templates/app/mailers/rodauth_mailer.rb +24 -0
  43. data/lib/generators/rodauth/templates/app/models/account.rb +7 -0
  44. data/lib/generators/rodauth/templates/db/migrate/create_rodauth.rb +8 -0
  45. data/lib/rodauth/rails/app.rb +19 -7
  46. data/lib/rodauth/rails/controller_methods.rb +9 -0
  47. data/lib/rodauth/rails/feature/base.rb +10 -0
  48. data/lib/rodauth/rails/feature/instrumentation.rb +8 -0
  49. data/lib/rodauth/rails/middleware.rb +9 -0
  50. data/lib/rodauth/rails/model.rb +2 -97
  51. data/lib/rodauth/rails/version.rb +1 -1
  52. data/lib/rodauth/rails.rb +2 -1
  53. data/rodauth-rails.gemspec +3 -1
  54. metadata +68 -26
  55. data/lib/generators/rodauth/migration_helpers.rb +0 -77
  56. data/lib/rodauth/rails/app/flash.rb +0 -45
  57. data/lib/rodauth/rails/app/middleware.rb +0 -36
  58. data/lib/rodauth/rails/model/associations.rb +0 -195
@@ -1,14 +1,22 @@
1
1
  class RodauthMailer < ApplicationMailer
2
2
  def verify_account(account_id, key)
3
3
  @email_link = rodauth.verify_account_url(key: email_token(account_id, key))
4
+ <% if defined?(ActiveRecord::Railtie) -%>
4
5
  @account = Account.find(account_id)
6
+ <% else -%>
7
+ @account = Account.with_pk!(account_id)
8
+ <% end -%>
5
9
 
6
10
  mail to: @account.email, subject: rodauth.verify_account_email_subject
7
11
  end
8
12
 
9
13
  def reset_password(account_id, key)
10
14
  @email_link = rodauth.reset_password_url(key: email_token(account_id, key))
15
+ <% if defined?(ActiveRecord::Railtie) -%>
11
16
  @account = Account.find(account_id)
17
+ <% else -%>
18
+ @account = Account.with_pk!(account_id)
19
+ <% end -%>
12
20
 
13
21
  mail to: @account.email, subject: rodauth.reset_password_email_subject
14
22
  end
@@ -17,27 +25,43 @@ class RodauthMailer < ApplicationMailer
17
25
  @old_login = old_login
18
26
  @new_login = new_login
19
27
  @email_link = rodauth.verify_login_change_url(key: email_token(account_id, key))
28
+ <% if defined?(ActiveRecord::Railtie) -%>
20
29
  @account = Account.find(account_id)
30
+ <% else -%>
31
+ @account = Account.with_pk!(account_id)
32
+ <% end -%>
21
33
 
22
34
  mail to: new_login, subject: rodauth.verify_login_change_email_subject
23
35
  end
24
36
 
25
37
  def password_changed(account_id)
38
+ <% if defined?(ActiveRecord::Railtie) -%>
26
39
  @account = Account.find(account_id)
40
+ <% else -%>
41
+ @account = Account.with_pk!(account_id)
42
+ <% end -%>
27
43
 
28
44
  mail to: @account.email, subject: rodauth.password_changed_email_subject
29
45
  end
30
46
 
31
47
  # def email_auth(account_id, key)
32
48
  # @email_link = rodauth.email_auth_url(key: email_token(account_id, key))
49
+ <% if defined?(ActiveRecord::Railtie) -%>
33
50
  # @account = Account.find(account_id)
51
+ <% else -%>
52
+ # @account = Account.with_pk!(account_id)
53
+ <% end -%>
34
54
 
35
55
  # mail to: @account.email, subject: rodauth.email_auth_email_subject
36
56
  # end
37
57
 
38
58
  # def unlock_account(account_id, key)
39
59
  # @email_link = rodauth.unlock_account_url(key: email_token(account_id, key))
60
+ <% if defined?(ActiveRecord::Railtie) -%>
40
61
  # @account = Account.find(account_id)
62
+ <% else -%>
63
+ # @account = Account.with_pk!(account_id)
64
+ <% end -%>
41
65
 
42
66
  # mail to: @account.email, subject: rodauth.unlock_account_email_subject
43
67
  # end
@@ -1,3 +1,4 @@
1
+ <% if defined?(ActiveRecord::Railtie) -%>
1
2
  class Account < ApplicationRecord
2
3
  include Rodauth::Rails.model
3
4
  <% if ActiveRecord.version >= Gem::Version.new("7.0") -%>
@@ -6,3 +7,9 @@ class Account < ApplicationRecord
6
7
  enum status: { unverified: 1, verified: 2, closed: 3 }
7
8
  <% end -%>
8
9
  end
10
+ <% else -%>
11
+ class Account < Sequel::Model
12
+ plugin :enum
13
+ enum :status, unverified: 1, verified: 2, closed: 3
14
+ end
15
+ <% end -%>
@@ -1,5 +1,13 @@
1
+ <% if defined?(::ActiveRecord::Railtie) -%>
1
2
  class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
2
3
  def change
3
4
  <%= migration_content -%>
4
5
  end
5
6
  end
7
+ <% else -%>
8
+ Sequel.migration do
9
+ change do
10
+ <%= migration_content -%>
11
+ end
12
+ end
13
+ <% end -%>
@@ -5,17 +5,21 @@ module Rodauth
5
5
  module Rails
6
6
  # The superclass for creating a Rodauth middleware.
7
7
  class App < Roda
8
- require "rodauth/rails/app/middleware"
9
- plugin Middleware
8
+ plugin :middleware, forward_response_headers: true do |middleware|
9
+ middleware.class_eval do
10
+ def self.inspect
11
+ "#{superclass}::Middleware"
12
+ end
13
+
14
+ def inspect
15
+ "#<#{self.class.inspect} request=#{request.inspect} response=#{response.inspect}>"
16
+ end
17
+ end
18
+ end
10
19
 
11
20
  plugin :hooks
12
21
  plugin :render, layout: false
13
22
 
14
- unless Rodauth::Rails.api_only?
15
- require "rodauth/rails/app/flash"
16
- plugin Flash
17
- end
18
-
19
23
  def self.configure(*args, **options, &block)
20
24
  auth_class = args.shift if args[0].is_a?(Class)
21
25
  name = args.shift if args[0].is_a?(Symbol)
@@ -35,6 +39,14 @@ module Rodauth
35
39
  end
36
40
  end
37
41
 
42
+ after do
43
+ rails_request.commit_flash
44
+ end unless ActionPack.version < Gem::Version.new("5.0")
45
+
46
+ def flash
47
+ rails_request.flash
48
+ end
49
+
38
50
  def rails_routes
39
51
  ::Rails.application.routes.url_helpers
40
52
  end
@@ -18,6 +18,15 @@ module Rodauth
18
18
 
19
19
  private
20
20
 
21
+ # Adds response status to instrumentation payload for logging,
22
+ # when calling a halting rodauth method inside a controller.
23
+ def append_info_to_payload(payload)
24
+ super
25
+ if request.env["rodauth.rails.status"]
26
+ payload[:status] = request.env.delete("rodauth.rails.status")
27
+ end
28
+ end
29
+
21
30
  def rodauth_response
22
31
  res = catch(:halt) { return yield }
23
32
 
@@ -54,6 +54,16 @@ module Rodauth
54
54
 
55
55
  private
56
56
 
57
+ unless ActionPack.version < Gem::Version.new("5.0")
58
+ # When calling a Rodauth method that redirects inside the Rails
59
+ # router, Roda's after hook that commits the flash would never get
60
+ # called, so we make sure to commit the flash beforehand.
61
+ def redirect(*)
62
+ rails_request.commit_flash
63
+ super
64
+ end
65
+ end
66
+
57
67
  def instantiate_rails_account
58
68
  if defined?(ActiveRecord::Base) && rails_account_model < ActiveRecord::Base
59
69
  rails_account_model.instantiate(account.stringify_keys)
@@ -10,6 +10,14 @@ module Rodauth
10
10
 
11
11
  def redirect(*)
12
12
  rails_instrument_redirection { super }
13
+ ensure
14
+ request.env["rodauth.rails.status"] = response.status
15
+ end
16
+
17
+ def return_response(*)
18
+ super
19
+ ensure
20
+ request.env["rodauth.rails.status"] = response.status
13
21
  end
14
22
 
15
23
  def rails_render(*)
@@ -9,6 +9,8 @@ module Rodauth
9
9
  end
10
10
 
11
11
  def call(env)
12
+ return @app.call(env) if asset_request?(env)
13
+
12
14
  app = Rodauth::Rails.app.new(@app)
13
15
 
14
16
  # allow the Rails app to call Rodauth methods that throw :halt
@@ -16,6 +18,13 @@ module Rodauth
16
18
  app.call(env)
17
19
  end
18
20
  end
21
+
22
+ # Check whether it's a request to an asset managed by Sprockets or Propshaft.
23
+ def asset_request?(env)
24
+ return false unless ::Rails.application.config.respond_to?(:assets)
25
+
26
+ env["PATH_INFO"] =~ %r(\A/{0,2}#{::Rails.application.config.assets.prefix})
27
+ end
19
28
  end
20
29
  end
21
30
  end
@@ -1,101 +1,6 @@
1
1
  module Rodauth
2
2
  module Rails
3
- class Model < Module
4
- require "rodauth/rails/model/associations"
5
-
6
- def initialize(auth_class, association_options: {})
7
- @auth_class = auth_class
8
- @association_options = association_options
9
-
10
- define_methods
11
- end
12
-
13
- def included(model)
14
- fail Rodauth::Rails::Error, "must be an Active Record model" unless model < ActiveRecord::Base
15
-
16
- define_associations(model)
17
- end
18
-
19
- private
20
-
21
- def define_methods
22
- rodauth = @auth_class.allocate.freeze
23
-
24
- attr_reader :password
25
-
26
- define_method(:password=) do |password|
27
- @password = password
28
- password_hash = rodauth.send(:password_hash, password) if password
29
- set_password_hash(password_hash)
30
- end
31
-
32
- define_method(:set_password_hash) do |password_hash|
33
- if rodauth.account_password_hash_column
34
- public_send(:"#{rodauth.account_password_hash_column}=", password_hash)
35
- else
36
- if password_hash
37
- record = self.password_hash || build_password_hash
38
- record.public_send(:"#{rodauth.password_hash_column}=", password_hash)
39
- else
40
- self.password_hash&.mark_for_destruction
41
- end
42
- end
43
- end
44
- end
45
-
46
- def define_associations(model)
47
- define_password_hash_association(model) unless rodauth.account_password_hash_column
48
-
49
- feature_associations.each do |association|
50
- define_association(model, **association)
51
- end
52
- end
53
-
54
- def define_password_hash_association(model)
55
- password_hash_id_column = rodauth.password_hash_id_column
56
- scope = -> { select(password_hash_id_column) } if rodauth.send(:use_database_authentication_functions?)
57
-
58
- define_association model,
59
- type: :has_one,
60
- name: :password_hash,
61
- table: rodauth.password_hash_table,
62
- foreign_key: password_hash_id_column,
63
- scope: scope,
64
- autosave: true
65
- end
66
-
67
- def define_association(model, type:, name:, table:, foreign_key:, scope: nil, **options)
68
- associated_model = Class.new(model.superclass)
69
- associated_model.table_name = table
70
- associated_model.belongs_to :account,
71
- class_name: model.name,
72
- foreign_key: foreign_key,
73
- inverse_of: name
74
-
75
- model.const_set(name.to_s.singularize.camelize, associated_model)
76
-
77
- model.public_send type, name, scope,
78
- class_name: associated_model.name,
79
- foreign_key: foreign_key,
80
- dependent: type == :has_many ? :delete_all : :delete,
81
- inverse_of: :account,
82
- **options,
83
- **association_options(name)
84
- end
85
-
86
- def feature_associations
87
- Rodauth::Rails::Model::Associations.call(rodauth)
88
- end
89
-
90
- def association_options(name)
91
- options = @association_options
92
- options = options.call(name) if options.respond_to?(:call)
93
- options || {}
94
- end
95
-
96
- def rodauth
97
- @auth_class.allocate
98
- end
99
- end
3
+ Model = Rodauth::Model
4
+ deprecate_constant :Model
100
5
  end
101
6
  end
@@ -1,5 +1,5 @@
1
1
  module Rodauth
2
2
  module Rails
3
- VERSION = "1.3.0"
3
+ VERSION = "1.4.1"
4
4
  end
5
5
  end
data/lib/rodauth/rails.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "rodauth/rails/version"
2
2
  require "rodauth/rails/railtie"
3
+ require "rodauth/model"
3
4
 
4
5
  module Rodauth
5
6
  module Rails
@@ -43,7 +44,7 @@ module Rodauth
43
44
  end
44
45
 
45
46
  def model(name = nil, **options)
46
- Rodauth::Rails::Model.new(app.rodauth!(name), **options)
47
+ Rodauth::Model.new(app.rodauth!(name), **options)
47
48
  end
48
49
 
49
50
  # routing constraint that requires authentication
@@ -17,8 +17,10 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ["lib"]
18
18
 
19
19
  spec.add_dependency "railties", ">= 4.2", "< 8"
20
- spec.add_dependency "rodauth", "~> 2.19"
20
+ spec.add_dependency "rodauth", "~> 2.23"
21
+ spec.add_dependency "roda", "~> 3.55"
21
22
  spec.add_dependency "sequel-activerecord_connection", "~> 1.1"
23
+ spec.add_dependency "rodauth-model", "~> 0.1"
22
24
  spec.add_dependency "tilt"
23
25
  spec.add_dependency "bcrypt"
24
26
 
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.3.0
4
+ version: 1.4.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-04-01 00:00:00.000000000 Z
11
+ date: 2022-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -36,14 +36,28 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '2.19'
39
+ version: '2.23'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '2.19'
46
+ version: '2.23'
47
+ - !ruby/object:Gem::Dependency
48
+ name: roda
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.55'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.55'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: sequel-activerecord_connection
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +72,20 @@ dependencies:
58
72
  - - "~>"
59
73
  - !ruby/object:Gem::Version
60
74
  version: '1.1'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rodauth-model
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0.1'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.1'
61
89
  - !ruby/object:Gem::Dependency
62
90
  name: tilt
63
91
  requirement: !ruby/object:Gem::Requirement
@@ -153,26 +181,43 @@ files:
153
181
  - LICENSE.txt
154
182
  - README.md
155
183
  - lib/generators/rodauth/install_generator.rb
156
- - lib/generators/rodauth/migration/account_expiration.erb
157
- - lib/generators/rodauth/migration/active_sessions.erb
158
- - lib/generators/rodauth/migration/audit_logging.erb
159
- - lib/generators/rodauth/migration/base.erb
160
- - lib/generators/rodauth/migration/disallow_password_reuse.erb
161
- - lib/generators/rodauth/migration/email_auth.erb
162
- - lib/generators/rodauth/migration/jwt_refresh.erb
163
- - lib/generators/rodauth/migration/lockout.erb
164
- - lib/generators/rodauth/migration/otp.erb
165
- - lib/generators/rodauth/migration/password_expiration.erb
166
- - lib/generators/rodauth/migration/recovery_codes.erb
167
- - lib/generators/rodauth/migration/remember.erb
168
- - lib/generators/rodauth/migration/reset_password.erb
169
- - lib/generators/rodauth/migration/single_session.erb
170
- - lib/generators/rodauth/migration/sms_codes.erb
171
- - lib/generators/rodauth/migration/verify_account.erb
172
- - lib/generators/rodauth/migration/verify_login_change.erb
173
- - lib/generators/rodauth/migration/webauthn.erb
184
+ - lib/generators/rodauth/migration/active_record/account_expiration.erb
185
+ - lib/generators/rodauth/migration/active_record/active_sessions.erb
186
+ - lib/generators/rodauth/migration/active_record/audit_logging.erb
187
+ - lib/generators/rodauth/migration/active_record/base.erb
188
+ - lib/generators/rodauth/migration/active_record/disallow_password_reuse.erb
189
+ - lib/generators/rodauth/migration/active_record/email_auth.erb
190
+ - lib/generators/rodauth/migration/active_record/jwt_refresh.erb
191
+ - lib/generators/rodauth/migration/active_record/lockout.erb
192
+ - lib/generators/rodauth/migration/active_record/otp.erb
193
+ - lib/generators/rodauth/migration/active_record/password_expiration.erb
194
+ - lib/generators/rodauth/migration/active_record/recovery_codes.erb
195
+ - lib/generators/rodauth/migration/active_record/remember.erb
196
+ - lib/generators/rodauth/migration/active_record/reset_password.erb
197
+ - lib/generators/rodauth/migration/active_record/single_session.erb
198
+ - lib/generators/rodauth/migration/active_record/sms_codes.erb
199
+ - lib/generators/rodauth/migration/active_record/verify_account.erb
200
+ - lib/generators/rodauth/migration/active_record/verify_login_change.erb
201
+ - lib/generators/rodauth/migration/active_record/webauthn.erb
202
+ - lib/generators/rodauth/migration/sequel/account_expiration.erb
203
+ - lib/generators/rodauth/migration/sequel/active_sessions.erb
204
+ - lib/generators/rodauth/migration/sequel/audit_logging.erb
205
+ - lib/generators/rodauth/migration/sequel/base.erb
206
+ - lib/generators/rodauth/migration/sequel/disallow_password_reuse.erb
207
+ - lib/generators/rodauth/migration/sequel/email_auth.erb
208
+ - lib/generators/rodauth/migration/sequel/jwt_refresh.erb
209
+ - lib/generators/rodauth/migration/sequel/lockout.erb
210
+ - lib/generators/rodauth/migration/sequel/otp.erb
211
+ - lib/generators/rodauth/migration/sequel/password_expiration.erb
212
+ - lib/generators/rodauth/migration/sequel/recovery_codes.erb
213
+ - lib/generators/rodauth/migration/sequel/remember.erb
214
+ - lib/generators/rodauth/migration/sequel/reset_password.erb
215
+ - lib/generators/rodauth/migration/sequel/single_session.erb
216
+ - lib/generators/rodauth/migration/sequel/sms_codes.erb
217
+ - lib/generators/rodauth/migration/sequel/verify_account.erb
218
+ - lib/generators/rodauth/migration/sequel/verify_login_change.erb
219
+ - lib/generators/rodauth/migration/sequel/webauthn.erb
174
220
  - lib/generators/rodauth/migration_generator.rb
175
- - lib/generators/rodauth/migration_helpers.rb
176
221
  - lib/generators/rodauth/templates/INSTRUCTIONS
177
222
  - lib/generators/rodauth/templates/app/controllers/rodauth_controller.rb
178
223
  - lib/generators/rodauth/templates/app/mailers/rodauth_mailer.rb
@@ -230,8 +275,6 @@ files:
230
275
  - lib/rodauth-rails.rb
231
276
  - lib/rodauth/rails.rb
232
277
  - lib/rodauth/rails/app.rb
233
- - lib/rodauth/rails/app/flash.rb
234
- - lib/rodauth/rails/app/middleware.rb
235
278
  - lib/rodauth/rails/auth.rb
236
279
  - lib/rodauth/rails/controller_methods.rb
237
280
  - lib/rodauth/rails/feature.rb
@@ -244,7 +287,6 @@ files:
244
287
  - lib/rodauth/rails/feature/render.rb
245
288
  - lib/rodauth/rails/middleware.rb
246
289
  - lib/rodauth/rails/model.rb
247
- - lib/rodauth/rails/model/associations.rb
248
290
  - lib/rodauth/rails/railtie.rb
249
291
  - lib/rodauth/rails/tasks.rake
250
292
  - lib/rodauth/rails/test.rb
@@ -1,77 +0,0 @@
1
- require "erb"
2
-
3
- module Rodauth
4
- module Rails
5
- module Generators
6
- module MigrationHelpers
7
- attr_reader :migration_class_name
8
-
9
- def migration_template(source, destination = File.basename(source))
10
- @migration_class_name = destination.chomp(".rb").camelize
11
-
12
- super source, File.join(db_migrate_path, destination)
13
- end
14
-
15
- private
16
-
17
- def migration_content
18
- migration_features
19
- .select { |feature| File.exist?("#{__dir__}/migration/#{feature}.erb") }
20
- .map { |feature| File.read("#{__dir__}/migration/#{feature}.erb") }
21
- .map { |content| erb_eval(content) }
22
- .join("\n")
23
- .indent(4)
24
- end
25
-
26
- def activerecord_adapter
27
- if ActiveRecord::Base.respond_to?(:connection_db_config)
28
- ActiveRecord::Base.connection_db_config.adapter
29
- else
30
- ActiveRecord::Base.connection_config.fetch(:adapter)
31
- end
32
- end
33
-
34
- def migration_version
35
- return unless ActiveRecord.version >= Gem::Version.new("5.0")
36
-
37
- "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
38
- end
39
-
40
- def db_migrate_path
41
- return "db/migrate" unless ActiveRecord.version >= Gem::Version.new("5.0")
42
-
43
- super
44
- end
45
-
46
- def primary_key_type(key = :id)
47
- generators = ::Rails.application.config.generators
48
- column_type = generators.options[:active_record][:primary_key_type]
49
-
50
- return unless column_type
51
-
52
- if key
53
- ", #{key}: :#{column_type}"
54
- else
55
- column_type
56
- end
57
- end
58
-
59
- def erb_eval(content)
60
- if ERB.version[/\d+\.\d+\.\d+/].to_s >= "2.2.0"
61
- ERB.new(content, trim_mode: "-").result(binding)
62
- else
63
- ERB.new(content, 0, "-").result(binding)
64
- end
65
- end
66
-
67
- def current_timestamp
68
- if ActiveRecord.version >= Gem::Version.new("5.0")
69
- %(-> { "CURRENT_TIMESTAMP" })
70
- else
71
- %(OpenStruct.new(quoted_id: "CURRENT_TIMESTAMP"))
72
- end
73
- end
74
- end
75
- end
76
- end
77
- end
@@ -1,45 +0,0 @@
1
- module Rodauth
2
- module Rails
3
- class App
4
- # Roda plugin that sets up Rails flash integration.
5
- module Flash
6
- def self.load_dependencies(app)
7
- app.plugin :hooks
8
- end
9
-
10
- def self.configure(app)
11
- app.after { request.commit_flash }
12
- end
13
-
14
- module InstanceMethods
15
- def flash
16
- request.flash
17
- end
18
- end
19
-
20
- module RequestMethods
21
- # If the redirect would bubble up outside of the Roda app, the after
22
- # hook would never get called, so we make sure to commit the flash.
23
- def redirect(*)
24
- commit_flash
25
- super
26
- end
27
-
28
- def flash
29
- scope.rails_request.flash
30
- end
31
-
32
- if ActionPack.version >= Gem::Version.new("5.0")
33
- def commit_flash
34
- scope.rails_request.commit_flash
35
- end
36
- else
37
- def commit_flash
38
- # ActionPack 4.2 automatically commits flash
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,36 +0,0 @@
1
- module Rodauth
2
- module Rails
3
- class App
4
- # Roda plugin that extends middleware plugin by propagating response headers.
5
- module Middleware
6
- def self.configure(app)
7
- handle_result = -> (env, res) do
8
- if headers = env.delete("rodauth.rails.headers")
9
- res[1] = headers.merge(res[1])
10
- end
11
- end
12
-
13
- app.plugin :middleware, handle_result: handle_result do |middleware|
14
- middleware.plugin :hooks
15
-
16
- middleware.after do
17
- if response.empty? && response.headers.any?
18
- env["rodauth.rails.headers"] = response.headers
19
- end
20
- end
21
-
22
- middleware.class_eval do
23
- def self.inspect
24
- "#{superclass}::Middleware"
25
- end
26
-
27
- def inspect
28
- "#<#{self.class.inspect} request=#{request.inspect} response=#{response.inspect}>"
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end