rodauth-rails 0.2.1 → 0.4.2
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 +34 -0
- data/README.md +60 -45
- data/lib/generators/rodauth/install_generator.rb +29 -25
- data/lib/generators/rodauth/templates/{lib → app/lib}/rodauth_app.rb +22 -2
- data/lib/generators/rodauth/templates/config/initializers/sequel.rb +4 -6
- data/lib/generators/rodauth/templates/db/migrate/create_rodauth.rb +14 -5
- data/lib/generators/rodauth/views_generator.rb +20 -13
- data/lib/rodauth/rails.rb +1 -1
- data/lib/rodauth/rails/app.rb +5 -4
- data/lib/rodauth/rails/app/flash.rb +1 -1
- data/lib/rodauth/rails/feature.rb +8 -4
- data/lib/rodauth/rails/railtie.rb +5 -0
- data/lib/rodauth/rails/version.rb +5 -0
- data/rodauth-rails.gemspec +5 -3
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 230b201ad8b9f7c27a9ca00db1a27b4166b7ca0d202f32651fc15ff663bb860e
|
4
|
+
data.tar.gz: b6b7205916994f829f8eb74c76d8b6172c52339b157f464afd2cd9bfa96f3f25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc5645e124796a66c59c51b3b1ab2f1a3b9d7168b53f0703543e42187bb29470d09d3b1103e543dad66ba9a7f940bd469383d767c7acf8fc1d1c8ac7675848e9
|
7
|
+
data.tar.gz: 89cfd6289466b276240ffbb1111fef0b4274ae2479f5a1dbdaaa193333093508ddc692f47e7a8d57ffeafe70a7d25039371a7ebd88646d962f63f577039afc9c
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
# 0.4.2 (2020-11-08)
|
2
|
+
|
3
|
+
* Drop support for Ruby 2.2 (@janko)
|
4
|
+
|
5
|
+
* Bump `sequel-activerecord_connection` dependency to 1.1+ (@janko)
|
6
|
+
|
7
|
+
* Set default bcrypt hash cost to `1` in tests (@janko)
|
8
|
+
|
9
|
+
* Call `AR::Base.connection_db_config` on Rails 6.1+ in `rodauth:install` generator (@janko)
|
10
|
+
|
11
|
+
## 0.4.1 (2020-11-02)
|
12
|
+
|
13
|
+
* Don't generate `RodauthController` in API-only mode (@janko)
|
14
|
+
|
15
|
+
* Pass `test: false` to Sequel in the `sequel.rb` initializer (@janko)
|
16
|
+
|
17
|
+
## 0.4.0 (2020-11-02)
|
18
|
+
|
19
|
+
* Support Rails API-only mode (@janko)
|
20
|
+
|
21
|
+
* Make `rodauth:install` create `rodauth_app.rb` in `app/lib/` directory (@janko)
|
22
|
+
|
23
|
+
## 0.3.1 (2020-10-25)
|
24
|
+
|
25
|
+
* Depend on sequel-activerecord_connection 1.0+ (@janko)
|
26
|
+
|
27
|
+
## 0.3.0 (2020-09-18)
|
28
|
+
|
29
|
+
* Handle custom configured database migration paths in install generator (@janko)
|
30
|
+
|
31
|
+
* Allow specifying features as plain arguments in `rodauth:views` generator (@janko)
|
32
|
+
|
33
|
+
* Add some missing foreign key constraints in generated migration file (@janko)
|
34
|
+
|
1
35
|
## 0.2.1 (2020-07-26)
|
2
36
|
|
3
37
|
* Fix incorrect JDBC connect syntax in `sequel.rb` template on JRuby (@janko)
|
data/README.md
CHANGED
@@ -13,7 +13,12 @@ Provides Rails integration for the [Rodauth] authentication framework.
|
|
13
13
|
Add the gem to your Gemfile:
|
14
14
|
|
15
15
|
```rb
|
16
|
-
gem "rodauth-rails", "~> 0.
|
16
|
+
gem "rodauth-rails", "~> 0.4"
|
17
|
+
|
18
|
+
# gem "jwt", require: false # for JWT feature
|
19
|
+
# gem "rotp", require: false # for OTP feature
|
20
|
+
# gem "rqrcode", require: false # for OTP feature
|
21
|
+
# gem "webauthn", require: false # for WebAuthn feature
|
17
22
|
```
|
18
23
|
|
19
24
|
Then run `bundle install`.
|
@@ -29,7 +34,7 @@ The generator will create the following files:
|
|
29
34
|
* Rodauth migration at `db/migrate/*_create_rodauth.rb`
|
30
35
|
* Rodauth initializer at `config/initializers/rodauth.rb`
|
31
36
|
* Sequel initializer at `config/initializers/sequel.rb` for ActiveRecord integration
|
32
|
-
* Rodauth app at `lib/rodauth_app.rb`
|
37
|
+
* Rodauth app at `app/lib/rodauth_app.rb`
|
33
38
|
* Rodauth controller at `app/controllers/rodauth_controller.rb`
|
34
39
|
* Account model at `app/models/account.rb`
|
35
40
|
|
@@ -82,20 +87,18 @@ ActiveRecord connection.
|
|
82
87
|
# config/initializers/sequel.rb
|
83
88
|
require "sequel/core"
|
84
89
|
|
85
|
-
# initialize
|
86
|
-
DB = Sequel.postgres(
|
87
|
-
# have Sequel use ActiveRecord's connection for database interaction
|
88
|
-
DB.extension :activerecord_connection
|
90
|
+
# initialize Sequel and have it reuse Active Record's database connection
|
91
|
+
DB = Sequel.postgres(extensions: :activerecord_connection)
|
89
92
|
```
|
90
93
|
|
91
94
|
### Rodauth app
|
92
95
|
|
93
|
-
Your Rodauth app is created in the `lib/` directory,
|
94
|
-
set of authentication features enabled, as well as extensive examples
|
95
|
-
you can configure authentication behaviour.
|
96
|
+
Your Rodauth app is created in the `app/lib/` directory, and comes with a
|
97
|
+
default set of authentication features enabled, as well as extensive examples
|
98
|
+
on ways you can configure authentication behaviour.
|
96
99
|
|
97
100
|
```rb
|
98
|
-
# lib/rodauth_app.rb
|
101
|
+
# app/lib/rodauth_app.rb
|
99
102
|
class RodauthApp < Rodauth::Rails::App
|
100
103
|
configure do
|
101
104
|
# authentication configuration
|
@@ -107,19 +110,6 @@ class RodauthApp < Rodauth::Rails::App
|
|
107
110
|
end
|
108
111
|
```
|
109
112
|
|
110
|
-
Note that Rails doesn't autoload files in the `lib/` directory by default, so
|
111
|
-
make sure to add `lib/` to your `config.autoload_paths`:
|
112
|
-
|
113
|
-
```rb
|
114
|
-
# config/application.rb
|
115
|
-
module YourApp
|
116
|
-
class Application < Rails::Application
|
117
|
-
# ...
|
118
|
-
config.autoload_paths += %W[#{config.root}/lib]
|
119
|
-
end
|
120
|
-
end
|
121
|
-
```
|
122
|
-
|
123
113
|
### Controller
|
124
114
|
|
125
115
|
Your Rodauth app will by default use `RodauthController` for view rendering
|
@@ -162,17 +152,24 @@ These links are fully functional, feel free to visit them and interact with the
|
|
162
152
|
pages. The templates that ship with Rodauth aim to provide a complete
|
163
153
|
authentication experience, and the forms use [Bootstrap] markup.
|
164
154
|
|
165
|
-
Let's also
|
166
|
-
|
155
|
+
Let's also load the account record for authenticated requests and expose it via
|
156
|
+
`#current_account`:
|
167
157
|
|
168
158
|
```rb
|
169
159
|
# app/controllers/application_controller.rb
|
170
160
|
class ApplicationController < ActionController::Base
|
161
|
+
before_action :load_account, if: -> { rodauth.authenticated? }
|
162
|
+
|
171
163
|
private
|
172
164
|
|
173
|
-
def
|
174
|
-
@current_account
|
165
|
+
def load_account
|
166
|
+
@current_account = Account.find(rodauth.session_value)
|
167
|
+
rescue ActiveRecord::RecordNotFound
|
168
|
+
rodauth.logout
|
169
|
+
rodauth.login_required
|
175
170
|
end
|
171
|
+
|
172
|
+
attr_reader :current_account
|
176
173
|
helper_method :current_account
|
177
174
|
end
|
178
175
|
```
|
@@ -187,7 +184,7 @@ our app. We can do this in our Rodauth app's routing block, which helps keep
|
|
187
184
|
the authentication logic encapsulated:
|
188
185
|
|
189
186
|
```rb
|
190
|
-
# lib/rodauth_app.rb
|
187
|
+
# app/lib/rodauth_app.rb
|
191
188
|
class RodauthApp < Rodauth::Rails::App
|
192
189
|
# ...
|
193
190
|
route do |r|
|
@@ -258,7 +255,7 @@ You can pass a list of Rodauth features to the generator to create views for
|
|
258
255
|
these features (this will not remove any existing views):
|
259
256
|
|
260
257
|
```sh
|
261
|
-
$ rails generate rodauth:views
|
258
|
+
$ rails generate rodauth:views login create_account lockout otp
|
262
259
|
```
|
263
260
|
|
264
261
|
Or you can generate views for all features:
|
@@ -307,7 +304,7 @@ Rodauth may send emails as part of the authentication flow. Most email settings
|
|
307
304
|
can be customized:
|
308
305
|
|
309
306
|
```rb
|
310
|
-
# lib/rodauth_app.rb
|
307
|
+
# app/lib/rodauth_app.rb
|
311
308
|
class RodauthApp < Rodauth::Rails::App
|
312
309
|
# ...
|
313
310
|
configure do
|
@@ -352,7 +349,7 @@ your mailer. If you've enabled additional authentication features, make sure to
|
|
352
349
|
override their `send_*_email` methods as well.
|
353
350
|
|
354
351
|
```rb
|
355
|
-
# lib/rodauth_app.rb
|
352
|
+
# app/lib/rodauth_app.rb
|
356
353
|
class RodauthApp < Rodauth::Rails::App
|
357
354
|
# ...
|
358
355
|
configure do
|
@@ -388,6 +385,37 @@ class RodauthApp < Rodauth::Rails::App
|
|
388
385
|
end
|
389
386
|
```
|
390
387
|
|
388
|
+
### JSON API
|
389
|
+
|
390
|
+
JSON API support in Rodauth is provided by the [JWT feature]. First you'll need
|
391
|
+
to add the [JWT gem] to your Gemfile:
|
392
|
+
|
393
|
+
```rb
|
394
|
+
gem "jwt"
|
395
|
+
```
|
396
|
+
|
397
|
+
The following configuration will enable the Rodauth endpoints to be accessed
|
398
|
+
via JSON requests (in addition to HTML requests):
|
399
|
+
|
400
|
+
```rb
|
401
|
+
# app/lib/rodauth_app.rb
|
402
|
+
class RodauthApp < Rodauth::Rails::App
|
403
|
+
configure(json: true) do
|
404
|
+
# ...
|
405
|
+
enable :jwt
|
406
|
+
jwt_secret "...your secret key..."
|
407
|
+
# ...
|
408
|
+
end
|
409
|
+
end
|
410
|
+
```
|
411
|
+
|
412
|
+
If you want the endpoints to be only accessible via JSON requests, or if your
|
413
|
+
Rails app is in API-only mode, instead of `json: true` pass `json: :only` to
|
414
|
+
the configure method.
|
415
|
+
|
416
|
+
Make sure to store the `jwt_secret` in a secure place, such as Rails
|
417
|
+
credentials or environment variables.
|
418
|
+
|
391
419
|
## How it works
|
392
420
|
|
393
421
|
### Middleware
|
@@ -493,20 +521,6 @@ Rodauth::Rails.configure do |config|
|
|
493
521
|
end
|
494
522
|
```
|
495
523
|
|
496
|
-
## Working with JWT
|
497
|
-
|
498
|
-
To use Rodauth's [JWT feature], you'll need to load Roda's JSON support:
|
499
|
-
|
500
|
-
```rb
|
501
|
-
# lib/rodauth_app.rb
|
502
|
-
class RodauthApp < Rodauth::Rails::App
|
503
|
-
configure(json: true) do
|
504
|
-
enable :jwt
|
505
|
-
# your configuration
|
506
|
-
end
|
507
|
-
end
|
508
|
-
```
|
509
|
-
|
510
524
|
## Testing
|
511
525
|
|
512
526
|
If you're writing system tests, it's generally better to go through the actual
|
@@ -629,6 +643,7 @@ conduct](https://github.com/janko/rodauth-rails/blob/master/CODE_OF_CONDUCT.md).
|
|
629
643
|
[rendering views outside of controllers]: https://blog.bigbinary.com/2016/01/08/rendering-views-outside-of-controllers-in-rails-5.html
|
630
644
|
[feature documentation]: http://rodauth.jeremyevans.net/documentation.html
|
631
645
|
[JWT feature]: http://rodauth.jeremyevans.net/rdoc/files/doc/jwt_rdoc.html
|
646
|
+
[JWT gem]: https://github.com/jwt/ruby-jwt
|
632
647
|
[Bootstrap]: https://getbootstrap.com/
|
633
648
|
[Roda]: http://roda.jeremyevans.net/
|
634
649
|
[HMAC]: http://rodauth.jeremyevans.net/rdoc/files/README_rdoc.html#label-HMAC
|
@@ -1,12 +1,13 @@
|
|
1
1
|
require "rails/generators/base"
|
2
|
-
require "rails/generators/migration"
|
3
|
-
|
2
|
+
require "rails/generators/active_record/migration"
|
3
|
+
|
4
|
+
require "securerandom"
|
4
5
|
|
5
6
|
module Rodauth
|
6
7
|
module Rails
|
7
8
|
module Generators
|
8
9
|
class InstallGenerator < ::Rails::Generators::Base
|
9
|
-
include ::
|
10
|
+
include ::ActiveRecord::Generators::Migration
|
10
11
|
|
11
12
|
source_root "#{__dir__}/templates"
|
12
13
|
namespace "rodauth:install"
|
@@ -14,7 +15,7 @@ module Rodauth
|
|
14
15
|
def create_rodauth_migration
|
15
16
|
return unless defined?(ActiveRecord::Base)
|
16
17
|
|
17
|
-
migration_template "db/migrate/create_rodauth.rb", "
|
18
|
+
migration_template "db/migrate/create_rodauth.rb", File.join(db_migrate_path, "create_rodauth.rb")
|
18
19
|
end
|
19
20
|
|
20
21
|
def create_rodauth_initializer
|
@@ -30,10 +31,12 @@ module Rodauth
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def create_rodauth_app
|
33
|
-
template "lib/rodauth_app.rb"
|
34
|
+
template "app/lib/rodauth_app.rb"
|
34
35
|
end
|
35
36
|
|
36
37
|
def create_rodauth_controller
|
38
|
+
return if api_only?
|
39
|
+
|
37
40
|
template "app/controllers/rodauth_controller.rb"
|
38
41
|
end
|
39
42
|
|
@@ -45,37 +48,38 @@ module Rodauth
|
|
45
48
|
|
46
49
|
private
|
47
50
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
def db_migrate_path
|
52
|
+
return "db/migrate" unless ActiveRecord.version >= Gem::Version.new("5.0")
|
53
|
+
|
54
|
+
super
|
51
55
|
end
|
52
56
|
|
53
57
|
def migration_version
|
54
|
-
if ActiveRecord.version >= Gem::Version.new("5.0
|
58
|
+
if ActiveRecord.version >= Gem::Version.new("5.0")
|
55
59
|
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
56
60
|
end
|
57
61
|
end
|
58
62
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
when "sqlite3" then "sqlite"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
else
|
68
|
-
def sequel_adapter
|
69
|
-
case activerecord_adapter
|
70
|
-
when "postgresql" then "postgres"
|
71
|
-
when "mysql2" then "mysql2"
|
72
|
-
when "sqlite3" then "sqlite"
|
73
|
-
end
|
63
|
+
def sequel_adapter
|
64
|
+
case activerecord_adapter
|
65
|
+
when "postgresql" then "postgres#{"ql" if RUBY_ENGINE == "jruby"}"
|
66
|
+
when "mysql2" then "mysql#{"2" unless RUBY_ENGINE == "jruby"}"
|
67
|
+
when "sqlite3" then "sqlite"
|
74
68
|
end
|
75
69
|
end
|
76
70
|
|
77
71
|
def activerecord_adapter
|
78
|
-
ActiveRecord::Base.
|
72
|
+
if ActiveRecord::Base.respond_to?(:connection_db_config)
|
73
|
+
ActiveRecord::Base.connection_db_config.adapter
|
74
|
+
else
|
75
|
+
ActiveRecord::Base.connection_config.fetch(:adapter)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def api_only?
|
80
|
+
return false if ::Rails.gem_version < Gem::Version.new("5.0")
|
81
|
+
|
82
|
+
::Rails.application.config.api_only
|
79
83
|
end
|
80
84
|
end
|
81
85
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class RodauthApp < Rodauth::Rails::App
|
2
|
-
configure do
|
2
|
+
configure<%= " json: :only" if api_only? %> do
|
3
3
|
# List of authentication features that are loaded.
|
4
4
|
enable :create_account, :verify_account, :verify_account_grace_period,
|
5
|
-
:login, :
|
5
|
+
:login, :logout, <%= api_only? ? ":jwt" : ":remember" %>,
|
6
6
|
:reset_password, :change_password, :change_password_notify,
|
7
7
|
:change_login, :verify_login_change,
|
8
8
|
:close_account
|
@@ -11,9 +11,11 @@ class RodauthApp < Rodauth::Rails::App
|
|
11
11
|
# http://rodauth.jeremyevans.net/documentation.html
|
12
12
|
|
13
13
|
# ==> General
|
14
|
+
<% unless api_only? -%>
|
14
15
|
# Specify the controller used for view rendering and CSRF verification.
|
15
16
|
rails_controller { RodauthController }
|
16
17
|
|
18
|
+
<% end -%>
|
17
19
|
# Store account status in a text column.
|
18
20
|
account_status_column :status
|
19
21
|
account_unverified_status_value "unverified"
|
@@ -38,6 +40,18 @@ class RodauthApp < Rodauth::Rails::App
|
|
38
40
|
|
39
41
|
# Redirect to the app from login and registration pages if already logged in.
|
40
42
|
# already_logged_in { redirect login_redirect }
|
43
|
+
<% if api_only? -%>
|
44
|
+
|
45
|
+
# ==> JWT
|
46
|
+
# Set JWT secret, which is used to cryptographically protect the token.
|
47
|
+
jwt_secret "<%= SecureRandom.hex(64) %>"
|
48
|
+
|
49
|
+
# Don't require login confirmation param.
|
50
|
+
require_login_confirmation? false
|
51
|
+
|
52
|
+
# Don't require password confirmation param.
|
53
|
+
require_password_confirmation? false
|
54
|
+
<% end -%>
|
41
55
|
|
42
56
|
# ==> Emails
|
43
57
|
# Uncomment the lines below once you've imported mailer views.
|
@@ -75,10 +89,12 @@ class RodauthApp < Rodauth::Rails::App
|
|
75
89
|
# reset_password_email_body { "Click here to reset your password: #{reset_password_email_link}" }
|
76
90
|
|
77
91
|
# ==> Flash
|
92
|
+
<% unless api_only? -%>
|
78
93
|
# Match flash keys with ones already used in the Rails app.
|
79
94
|
# flash_notice_key :success # default is :notice
|
80
95
|
# flash_error_key :error # default is :alert
|
81
96
|
|
97
|
+
<% end -%>
|
82
98
|
# Override default flash messages.
|
83
99
|
# create_account_notice_flash "Your account has been created. Please verify your account by visiting the confirmation link sent to your email address."
|
84
100
|
# require_login_error_flash "Login is required for accessing this page"
|
@@ -93,6 +109,7 @@ class RodauthApp < Rodauth::Rails::App
|
|
93
109
|
|
94
110
|
# Change minimum number of password characters required when creating an account.
|
95
111
|
# password_minimum_length 8
|
112
|
+
<% unless api_only? -%>
|
96
113
|
|
97
114
|
# ==> Remember Feature
|
98
115
|
# Remember all logged in users.
|
@@ -103,6 +120,7 @@ class RodauthApp < Rodauth::Rails::App
|
|
103
120
|
|
104
121
|
# Extend user's remember period when remembered via a cookie
|
105
122
|
extend_remember_deadline? true
|
123
|
+
<% end -%>
|
106
124
|
|
107
125
|
# ==> Hooks
|
108
126
|
# Validate custom fields in the create account form.
|
@@ -147,8 +165,10 @@ class RodauthApp < Rodauth::Rails::App
|
|
147
165
|
# end
|
148
166
|
|
149
167
|
route do |r|
|
168
|
+
<% unless api_only? -%>
|
150
169
|
rodauth.load_memory # autologin remembered users
|
151
170
|
|
171
|
+
<% end -%>
|
152
172
|
r.rodauth # route rodauth requests
|
153
173
|
|
154
174
|
# ==> Authenticating Requests
|
@@ -1,10 +1,8 @@
|
|
1
1
|
require "sequel/core"
|
2
2
|
|
3
|
-
# initialize
|
4
|
-
|
5
|
-
DB = Sequel.connect("jdbc:<%= sequel_adapter %>://",
|
3
|
+
# initialize Sequel and have it reuse Active Record's database connection
|
4
|
+
<% if RUBY_ENGINE == "jruby" -%>
|
5
|
+
DB = Sequel.connect("jdbc:<%= sequel_adapter %>://", extensions: :activerecord_connection)
|
6
6
|
<% else -%>
|
7
|
-
DB = Sequel.<%= sequel_adapter %>(
|
7
|
+
DB = Sequel.<%= sequel_adapter %>(extensions: :activerecord_connection)
|
8
8
|
<% end -%>
|
9
|
-
# have Sequel use ActiveRecord's connection for database interaction
|
10
|
-
DB.extension :activerecord_connection
|
@@ -44,16 +44,25 @@ class CreateRodauth < ActiveRecord::Migration<%= migration_version %>
|
|
44
44
|
t.datetime :deadline, null: false
|
45
45
|
end
|
46
46
|
|
47
|
+
<% unless api_only? -%>
|
47
48
|
# Used by the remember me feature
|
48
49
|
create_table :account_remember_keys do |t|
|
49
50
|
t.foreign_key :accounts, column: :id
|
50
51
|
t.string :key, null: false
|
51
52
|
t.datetime :deadline, null: false
|
52
53
|
end
|
54
|
+
<% else -%>
|
55
|
+
# # Used by the remember me feature
|
56
|
+
# create_table :account_remember_keys do |t|
|
57
|
+
# t.foreign_key :accounts, column: :id
|
58
|
+
# t.string :key, null: false
|
59
|
+
# t.datetime :deadline, null: false
|
60
|
+
# end
|
61
|
+
<% end -%>
|
53
62
|
|
54
63
|
# # Used by the audit logging feature
|
55
64
|
# create_table :account_authentication_audit_logs do |t|
|
56
|
-
# t.references :account, null: false
|
65
|
+
# t.references :account, foreign_key: true, null: false
|
57
66
|
# t.datetime :at, null: false, default: -> { "CURRENT_TIMESTAMP" }
|
58
67
|
# t.text :message, null: false
|
59
68
|
<% case activerecord_adapter -%>
|
@@ -70,7 +79,7 @@ class CreateRodauth < ActiveRecord::Migration<%= migration_version %>
|
|
70
79
|
|
71
80
|
# # Used by the jwt refresh feature
|
72
81
|
# create_table :account_jwt_refresh_keys do |t|
|
73
|
-
# t.references :account, null: false
|
82
|
+
# t.references :account, foreign_key: true, null: false
|
74
83
|
# t.string :key, null: false
|
75
84
|
# t.datetime :deadline, null: false
|
76
85
|
# t.index :account_id, name: "account_jwt_rk_account_id_idx"
|
@@ -78,7 +87,7 @@ class CreateRodauth < ActiveRecord::Migration<%= migration_version %>
|
|
78
87
|
|
79
88
|
# # Used by the disallow_password_reuse feature
|
80
89
|
# create_table :account_previous_password_hashes do |t|
|
81
|
-
# t.references :account
|
90
|
+
# t.references :account, foreign_key: true
|
82
91
|
# t.string :password_hash, null: false
|
83
92
|
# end
|
84
93
|
|
@@ -124,7 +133,7 @@ class CreateRodauth < ActiveRecord::Migration<%= migration_version %>
|
|
124
133
|
|
125
134
|
# # Used by the active sessions feature
|
126
135
|
# create_table :account_active_session_keys, primary_key: [:account_id, :session_id] do |t|
|
127
|
-
# t.references :account
|
136
|
+
# t.references :account, foreign_key: true
|
128
137
|
# t.string :session_id
|
129
138
|
# t.datetime :created_at, null: false, default: -> { "CURRENT_TIMESTAMP" }
|
130
139
|
# t.datetime :last_use, null: false, default: -> { "CURRENT_TIMESTAMP" }
|
@@ -136,7 +145,7 @@ class CreateRodauth < ActiveRecord::Migration<%= migration_version %>
|
|
136
145
|
# t.string :webauthn_id, null: false
|
137
146
|
# end
|
138
147
|
# create_table :account_webauthn_keys, primary_key: [:account_id, :webauthn_id] do |t|
|
139
|
-
# t.references :account
|
148
|
+
# t.references :account, foreign_key: true
|
140
149
|
# t.string :webauthn_id
|
141
150
|
# t.string :public_key, null: false
|
142
151
|
# t.integer :sign_count, null: false
|
@@ -7,6 +7,21 @@ module Rodauth
|
|
7
7
|
source_root "#{__dir__}/templates"
|
8
8
|
namespace "rodauth:views"
|
9
9
|
|
10
|
+
argument :features, optional: true, type: :array,
|
11
|
+
desc: "Rodauth features to generate views for (login, create_account, reset_password, verify_account etc.)",
|
12
|
+
default: %w[login logout create_account verify_account reset_password change_password change_login verify_login_change close_account]
|
13
|
+
|
14
|
+
class_option :features, type: :array,
|
15
|
+
desc: "[DEPRECATED] Rodauth features to generate views for (login, create_account, reset_password, verify_account etc.)"
|
16
|
+
|
17
|
+
class_option :all, aliases: "-a", type: :boolean,
|
18
|
+
desc: "Generates views for all Rodauth features",
|
19
|
+
default: false
|
20
|
+
|
21
|
+
class_option :directory, aliases: "-d", type: :string,
|
22
|
+
desc: "The directory under app/views/* into which to create views",
|
23
|
+
default: "rodauth"
|
24
|
+
|
10
25
|
VIEWS = {
|
11
26
|
login: %w[
|
12
27
|
_field _field_error _login_field _login_display _password_field
|
@@ -83,20 +98,12 @@ module Rodauth
|
|
83
98
|
webauthn: :two_factor_base,
|
84
99
|
}
|
85
100
|
|
86
|
-
class_option :features, type: :array,
|
87
|
-
desc: "Rodauth features to generate views for (login, create_account, reset_password, verify_account etc.)",
|
88
|
-
default: %w[login logout create_account verify_account reset_password change_password change_login verify_login_change close_account]
|
89
|
-
|
90
|
-
class_option :all, aliases: "-a", type: :boolean,
|
91
|
-
desc: "Generates views for all Rodauth features",
|
92
|
-
default: false
|
93
|
-
|
94
|
-
class_option :directory, aliases: "-d", type: :string,
|
95
|
-
desc: "The directory under app/views/* into which to create views",
|
96
|
-
default: "rodauth"
|
97
|
-
|
98
101
|
def create_views
|
99
|
-
|
102
|
+
if options[:all]
|
103
|
+
features = VIEWS.keys
|
104
|
+
else
|
105
|
+
features = (options[:features] || self.features).map(&:to_sym)
|
106
|
+
end
|
100
107
|
|
101
108
|
views = features.inject([]) do |list, feature|
|
102
109
|
list |= VIEWS[feature] || []
|
data/lib/rodauth/rails.rb
CHANGED
data/lib/rodauth/rails/app.rb
CHANGED
@@ -4,15 +4,16 @@ module Rodauth
|
|
4
4
|
module Rails
|
5
5
|
# The superclass for creating a Rodauth middleware.
|
6
6
|
class App < Roda
|
7
|
-
require "rodauth/rails/app/flash"
|
8
|
-
|
9
7
|
plugin :middleware
|
10
8
|
plugin :hooks
|
11
9
|
plugin :render, layout: false
|
12
10
|
|
13
|
-
plugin Flash
|
14
|
-
|
15
11
|
def self.configure(name = nil, **options, &block)
|
12
|
+
unless options[:json] == :only
|
13
|
+
require "rodauth/rails/app/flash"
|
14
|
+
plugin Flash
|
15
|
+
end
|
16
|
+
|
16
17
|
plugin :rodauth, name: name, csrf: false, flash: false, **options do
|
17
18
|
# load the Rails integration
|
18
19
|
enable :rails
|
@@ -62,9 +62,13 @@ module Rodauth
|
|
62
62
|
|
63
63
|
# Calls the Rails renderer, returning nil if a template is missing.
|
64
64
|
def rails_render(*args)
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
return if only_json?
|
66
|
+
|
67
|
+
begin
|
68
|
+
rails_controller_instance.render_to_string(*args)
|
69
|
+
rescue ActionView::MissingTemplate
|
70
|
+
nil
|
71
|
+
end
|
68
72
|
end
|
69
73
|
|
70
74
|
# Hidden tag with Rails CSRF token inserted into Rodauth templates.
|
@@ -92,7 +96,7 @@ module Rodauth
|
|
92
96
|
request = ActionDispatch::Request.new(scope.env)
|
93
97
|
instance = rails_controller.new
|
94
98
|
|
95
|
-
if ActionPack.version >= Gem::Version.new("5.0
|
99
|
+
if ActionPack.version >= Gem::Version.new("5.0")
|
96
100
|
instance.set_request! request
|
97
101
|
instance.set_response! rails_controller.make_response!(request)
|
98
102
|
else
|
data/rodauth-rails.gemspec
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require_relative "lib/rodauth/rails/version"
|
2
|
+
|
1
3
|
Gem::Specification.new do |spec|
|
2
4
|
spec.name = "rodauth-rails"
|
3
|
-
spec.version =
|
5
|
+
spec.version = Rodauth::Rails::VERSION
|
4
6
|
spec.authors = ["Janko Marohnić"]
|
5
7
|
spec.email = ["janko.marohnic@gmail.com"]
|
6
8
|
|
@@ -9,14 +11,14 @@ Gem::Specification.new do |spec|
|
|
9
11
|
spec.homepage = "https://github.com/janko/rodauth-rails"
|
10
12
|
spec.license = "MIT"
|
11
13
|
|
12
|
-
spec.required_ruby_version = ">= 2.
|
14
|
+
spec.required_ruby_version = ">= 2.3"
|
13
15
|
|
14
16
|
spec.files = Dir["README.md", "LICENSE.txt", "CHANGELOG.md", "lib/**/*", "*.gemspec"]
|
15
17
|
spec.require_paths = ["lib"]
|
16
18
|
|
17
19
|
spec.add_dependency "railties", ">= 4.2", "< 7"
|
18
20
|
spec.add_dependency "rodauth", "~> 2.1"
|
19
|
-
spec.add_dependency "sequel-activerecord_connection", "~>
|
21
|
+
spec.add_dependency "sequel-activerecord_connection", "~> 1.1"
|
20
22
|
spec.add_dependency "tilt"
|
21
23
|
spec.add_dependency "bcrypt"
|
22
24
|
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: 0.2
|
4
|
+
version: 0.4.2
|
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
|
+
date: 2020-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '1.1'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '1.1'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: tilt
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/generators/rodauth/install_generator.rb
|
100
100
|
- lib/generators/rodauth/mailer_generator.rb
|
101
101
|
- lib/generators/rodauth/templates/app/controllers/rodauth_controller.rb
|
102
|
+
- lib/generators/rodauth/templates/app/lib/rodauth_app.rb
|
102
103
|
- lib/generators/rodauth/templates/app/mailers/rodauth_mailer.rb
|
103
104
|
- lib/generators/rodauth/templates/app/models/account.rb
|
104
105
|
- lib/generators/rodauth/templates/app/views/rodauth/_email_auth_request_form.html.erb
|
@@ -164,7 +165,6 @@ files:
|
|
164
165
|
- lib/generators/rodauth/templates/config/initializers/rodauth.rb
|
165
166
|
- lib/generators/rodauth/templates/config/initializers/sequel.rb
|
166
167
|
- lib/generators/rodauth/templates/db/migrate/create_rodauth.rb
|
167
|
-
- lib/generators/rodauth/templates/lib/rodauth_app.rb
|
168
168
|
- lib/generators/rodauth/views_generator.rb
|
169
169
|
- lib/rodauth-rails.rb
|
170
170
|
- lib/rodauth/features/rails.rb
|
@@ -175,6 +175,7 @@ files:
|
|
175
175
|
- lib/rodauth/rails/feature.rb
|
176
176
|
- lib/rodauth/rails/middleware.rb
|
177
177
|
- lib/rodauth/rails/railtie.rb
|
178
|
+
- lib/rodauth/rails/version.rb
|
178
179
|
- rodauth-rails.gemspec
|
179
180
|
homepage: https://github.com/janko/rodauth-rails
|
180
181
|
licenses:
|
@@ -188,14 +189,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
188
189
|
requirements:
|
189
190
|
- - ">="
|
190
191
|
- !ruby/object:Gem::Version
|
191
|
-
version: 2.
|
192
|
+
version: '2.3'
|
192
193
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
194
|
requirements:
|
194
195
|
- - ">="
|
195
196
|
- !ruby/object:Gem::Version
|
196
197
|
version: '0'
|
197
198
|
requirements: []
|
198
|
-
rubygems_version: 3.1.
|
199
|
+
rubygems_version: 3.1.4
|
199
200
|
signing_key:
|
200
201
|
specification_version: 4
|
201
202
|
summary: Provides Rails integration for Rodauth.
|