rodauth-rails 0.6.0 → 0.6.1
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +20 -19
- data/lib/generators/rodauth/install_generator.rb +0 -2
- data/lib/generators/rodauth/templates/app/controllers/rodauth_controller.rb +2 -1
- data/lib/generators/rodauth/templates/app/lib/rodauth_app.rb +14 -20
- data/lib/rodauth/rails/app.rb +4 -2
- data/lib/rodauth/rails/app/flash.rb +50 -0
- data/lib/rodauth/rails/app/middleware.rb +26 -0
- data/lib/rodauth/rails/feature.rb +24 -13
- data/lib/rodauth/rails/version.rb +1 -1
- metadata +4 -3
- data/lib/rodauth/rails/flash.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9805b35cefee7e30cc6f7190e2ace9e7ea75c20f40651eb364edafea2f2382f7
|
4
|
+
data.tar.gz: 503b821866aaf2b6aa108265ed8015869a8c8a6a73e910aa3c38b35c5a542ac1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a3e69b6d62f20ee5bc5a13c89acd2974401830a4f0f8917cc7716c9a5ccaad021a20c0f3269a211336b648bd8eb65ae60094c90a039fa1d3968eaf322ec2e47
|
7
|
+
data.tar.gz: 567cf154e656f7062029e207d92149fa8cf2c87404d1ba72fef6327cb31f928d0bcf453a4a0d55f71740251cb74f8b6829b8c775373daec4fe638690cd702104
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.6.1 (2020-11-25)
|
2
|
+
|
3
|
+
* Generate the Rodauth controller for API-only Rails apps as well (@janko)
|
4
|
+
|
5
|
+
* Fix remember cookie deadline not extending in remember feature (@janko)
|
6
|
+
|
1
7
|
## 0.6.0 (2020-11-22)
|
2
8
|
|
3
9
|
* Add `Rodauth::Rails.rodauth` method for retrieving Rodauth instance outside of request context (@janko)
|
data/README.md
CHANGED
@@ -381,7 +381,7 @@ end
|
|
381
381
|
|
382
382
|
You can then uncomment the lines in your Rodauth configuration to have it call
|
383
383
|
your mailer. If you've enabled additional authentication features that send
|
384
|
-
emails, make sure to override their `
|
384
|
+
emails, make sure to override their `create_*_email` methods as well.
|
385
385
|
|
386
386
|
```rb
|
387
387
|
# app/lib/rodauth_app.rb
|
@@ -389,37 +389,38 @@ class RodauthApp < Rodauth::Rails::App
|
|
389
389
|
# ...
|
390
390
|
configure do
|
391
391
|
# ...
|
392
|
-
|
393
|
-
|
392
|
+
create_reset_password_email do
|
393
|
+
RodauthMailer.reset_password(email_to, reset_password_email_link)
|
394
394
|
end
|
395
|
-
|
396
|
-
|
395
|
+
create_verify_account_email do
|
396
|
+
RodauthMailer.verify_account(email_to, verify_account_email_link)
|
397
397
|
end
|
398
|
-
|
399
|
-
|
398
|
+
create_verify_login_change_email do |login|
|
399
|
+
RodauthMailer.verify_login_change(login, verify_login_change_old_login, verify_login_change_new_login, verify_login_change_email_link)
|
400
400
|
end
|
401
|
-
|
402
|
-
|
401
|
+
create_password_changed_email do
|
402
|
+
RodauthMailer.password_changed(email_to)
|
403
403
|
end
|
404
|
-
#
|
405
|
-
#
|
404
|
+
# create_email_auth_email do
|
405
|
+
# RodauthMailer.email_auth(email_to, email_auth_email_link)
|
406
406
|
# end
|
407
|
-
#
|
408
|
-
#
|
407
|
+
# create_unlock_account_email do
|
408
|
+
# RodauthMailer.unlock_account(email_to, unlock_account_email_link)
|
409
409
|
# end
|
410
|
-
|
410
|
+
send_email do |email|
|
411
411
|
# queue email delivery on the mailer after the transaction commits
|
412
|
-
|
413
|
-
db.after_commit do
|
414
|
-
RodauthMailer.public_send(type, *args).deliver_later
|
415
|
-
end
|
416
|
-
end
|
412
|
+
db.after_commit { email.deliver_later }
|
417
413
|
end
|
418
414
|
# ...
|
419
415
|
end
|
420
416
|
end
|
421
417
|
```
|
422
418
|
|
419
|
+
This approach can be used even if you're using a 3rd-party service for
|
420
|
+
transactional emails, where emails are sent via API requests instead of
|
421
|
+
SMTP. Whatever the `create_*_email` block returns will be passed to
|
422
|
+
`send_email`, so you can be creative.
|
423
|
+
|
423
424
|
### Migrations
|
424
425
|
|
425
426
|
The install generator will create a migration for tables used by the Rodauth
|
@@ -15,11 +15,9 @@ class RodauthApp < Rodauth::Rails::App
|
|
15
15
|
# Defaults to Rails `secret_key_base`, but you can use your own secret key.
|
16
16
|
# hmac_secret "<%= SecureRandom.hex(64) %>"
|
17
17
|
|
18
|
-
<% unless api_only? -%>
|
19
18
|
# Specify the controller used for view rendering and CSRF verification.
|
20
19
|
rails_controller { RodauthController }
|
21
20
|
|
22
|
-
<% end -%>
|
23
21
|
# Store account status in a text column.
|
24
22
|
account_status_column :status
|
25
23
|
account_unverified_status_value "unverified"
|
@@ -59,31 +57,27 @@ class RodauthApp < Rodauth::Rails::App
|
|
59
57
|
|
60
58
|
# ==> Emails
|
61
59
|
# Uncomment the lines below once you've imported mailer views.
|
62
|
-
#
|
63
|
-
#
|
60
|
+
# create_reset_password_email do
|
61
|
+
# RodauthMailer.reset_password(email_to, reset_password_email_link)
|
64
62
|
# end
|
65
|
-
#
|
66
|
-
#
|
63
|
+
# create_verify_account_email do
|
64
|
+
# RodauthMailer.verify_account(email_to, verify_account_email_link)
|
67
65
|
# end
|
68
|
-
#
|
69
|
-
#
|
66
|
+
# create_verify_login_change_email do |login|
|
67
|
+
# RodauthMailer.verify_login_change(login, verify_login_change_old_login, verify_login_change_new_login, verify_login_change_email_link)
|
70
68
|
# end
|
71
|
-
#
|
72
|
-
#
|
69
|
+
# create_password_changed_email do
|
70
|
+
# RodauthMailer.password_changed(email_to)
|
73
71
|
# end
|
74
|
-
# #
|
75
|
-
# #
|
72
|
+
# # create_email_auth_email do
|
73
|
+
# # RodauthMailer.email_auth(email_to, email_auth_email_link)
|
76
74
|
# # end
|
77
|
-
# #
|
78
|
-
# #
|
75
|
+
# # create_unlock_account_email do
|
76
|
+
# # RodauthMailer.unlock_account(email_to, unlock_account_email_link)
|
79
77
|
# # end
|
80
|
-
#
|
78
|
+
# send_email do |email|
|
81
79
|
# # queue email delivery on the mailer after the transaction commits
|
82
|
-
#
|
83
|
-
# db.after_commit do
|
84
|
-
# RodauthMailer.public_send(type, *args).deliver_later
|
85
|
-
# end
|
86
|
-
# end
|
80
|
+
# db.after_commit { email.deliver_later }
|
87
81
|
# end
|
88
82
|
|
89
83
|
# In the meantime you can tweak settings for emails created by Rodauth
|
data/lib/rodauth/rails/app.rb
CHANGED
@@ -4,13 +4,15 @@ module Rodauth
|
|
4
4
|
module Rails
|
5
5
|
# The superclass for creating a Rodauth middleware.
|
6
6
|
class App < Roda
|
7
|
-
|
7
|
+
require "rodauth/rails/app/middleware"
|
8
|
+
plugin Middleware
|
9
|
+
|
8
10
|
plugin :hooks
|
9
11
|
plugin :render, layout: false
|
10
12
|
|
11
13
|
def self.configure(name = nil, **options, &block)
|
12
14
|
unless options[:json] == :only
|
13
|
-
require "rodauth/rails/flash"
|
15
|
+
require "rodauth/rails/app/flash"
|
14
16
|
plugin Flash
|
15
17
|
end
|
16
18
|
|
@@ -0,0 +1,50 @@
|
|
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.before { request.flash } # load flash
|
12
|
+
app.after { request.commit_flash } # save flash
|
13
|
+
end
|
14
|
+
|
15
|
+
module InstanceMethods
|
16
|
+
def flash
|
17
|
+
request.flash
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module RequestMethods
|
22
|
+
# If the redirect would bubble up outside of the Roda app, the after
|
23
|
+
# hook would never get called, so we make sure to commit the flash.
|
24
|
+
def redirect(*)
|
25
|
+
commit_flash
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
def flash
|
30
|
+
rails_request.flash
|
31
|
+
end
|
32
|
+
|
33
|
+
def commit_flash
|
34
|
+
if ActionPack.version >= Gem::Version.new("5.0")
|
35
|
+
rails_request.commit_flash
|
36
|
+
else
|
37
|
+
# ActionPack 4.2 automatically commits flash
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def rails_request
|
44
|
+
ActionDispatch::Request.new(env)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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.load_dependencies(app)
|
7
|
+
app.plugin :hooks
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure(app)
|
11
|
+
app.after do
|
12
|
+
if response.empty? && response.headers.any?
|
13
|
+
env["rodauth.rails.headers"] = response.headers
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
app.plugin :middleware, handle_result: -> (env, res) do
|
18
|
+
if headers = env.delete("rodauth.rails.headers")
|
19
|
+
res[1] = headers.merge(res[1])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -145,23 +145,34 @@ module Rodauth
|
|
145
145
|
|
146
146
|
# Instances of the configured controller with current request's env hash.
|
147
147
|
def _rails_controller_instance
|
148
|
-
|
149
|
-
|
148
|
+
controller = rails_controller.new
|
149
|
+
rails_request = ActionDispatch::Request.new(scope.env)
|
150
150
|
|
151
|
-
|
152
|
-
instance.set_request! request
|
153
|
-
instance.set_response! rails_controller.make_response!(request)
|
154
|
-
else
|
155
|
-
instance.send(:set_response!, request)
|
156
|
-
instance.instance_variable_set(:@_request, request)
|
157
|
-
end
|
151
|
+
prepare_rails_controller(controller, rails_request)
|
158
152
|
|
159
|
-
|
153
|
+
controller
|
160
154
|
end
|
161
155
|
|
162
|
-
|
163
|
-
|
164
|
-
|
156
|
+
if ActionPack.version >= Gem::Version.new("5.0")
|
157
|
+
# Controller class to use for view rendering, CSRF protection, and
|
158
|
+
# running any registered action callbacks and rescue_from handlers.
|
159
|
+
def rails_controller
|
160
|
+
only_json? ? ActionController::API : ActionController::Base
|
161
|
+
end
|
162
|
+
|
163
|
+
def prepare_rails_controller(controller, rails_request)
|
164
|
+
controller.set_request! rails_request
|
165
|
+
controller.set_response! rails_controller.make_response!(rails_request)
|
166
|
+
end
|
167
|
+
else
|
168
|
+
def rails_controller
|
169
|
+
ActionController::Base
|
170
|
+
end
|
171
|
+
|
172
|
+
def prepare_rails_controller(controller, rails_request)
|
173
|
+
controller.send(:set_response!, rails_request)
|
174
|
+
controller.instance_variable_set(:@_request, rails_request)
|
175
|
+
end
|
165
176
|
end
|
166
177
|
|
167
178
|
# ActionMailer subclass for correct email delivering.
|
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: 0.6.
|
4
|
+
version: 0.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: 2020-11-
|
11
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -190,9 +190,10 @@ files:
|
|
190
190
|
- lib/rodauth/features/rails.rb
|
191
191
|
- lib/rodauth/rails.rb
|
192
192
|
- lib/rodauth/rails/app.rb
|
193
|
+
- lib/rodauth/rails/app/flash.rb
|
194
|
+
- lib/rodauth/rails/app/middleware.rb
|
193
195
|
- lib/rodauth/rails/controller_methods.rb
|
194
196
|
- lib/rodauth/rails/feature.rb
|
195
|
-
- lib/rodauth/rails/flash.rb
|
196
197
|
- lib/rodauth/rails/middleware.rb
|
197
198
|
- lib/rodauth/rails/railtie.rb
|
198
199
|
- lib/rodauth/rails/tasks.rake
|
data/lib/rodauth/rails/flash.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
module Rodauth
|
2
|
-
module Rails
|
3
|
-
# Roda plugin that sets up Rails flash integration.
|
4
|
-
module Flash
|
5
|
-
def self.load_dependencies(app)
|
6
|
-
app.plugin :hooks
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.configure(app)
|
10
|
-
app.before { request.flash } # load flash
|
11
|
-
app.after { request.commit_flash } # save 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
|
-
rails_request.flash
|
30
|
-
end
|
31
|
-
|
32
|
-
def commit_flash
|
33
|
-
if ActionPack.version >= Gem::Version.new("5.0")
|
34
|
-
rails_request.commit_flash
|
35
|
-
else
|
36
|
-
# ActionPack 4.2 automatically commits flash
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def rails_request
|
43
|
-
ActionDispatch::Request.new(env)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|