rodauth-rails 1.5.5 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +4 -4
- data/lib/generators/rodauth/install_generator.rb +2 -0
- data/lib/generators/rodauth/migration/active_record/account_expiration.erb +2 -1
- data/lib/generators/rodauth/migration/active_record/email_auth.erb +2 -2
- data/lib/generators/rodauth/migration/active_record/lockout.erb +4 -2
- data/lib/generators/rodauth/migration/active_record/otp.erb +2 -1
- data/lib/generators/rodauth/migration/active_record/password_expiration.erb +2 -1
- data/lib/generators/rodauth/migration/active_record/recovery_codes.erb +1 -1
- data/lib/generators/rodauth/migration/active_record/remember.erb +2 -1
- data/lib/generators/rodauth/migration/active_record/reset_password.erb +2 -1
- data/lib/generators/rodauth/migration/active_record/single_session.erb +2 -1
- data/lib/generators/rodauth/migration/active_record/sms_codes.erb +2 -1
- data/lib/generators/rodauth/migration/active_record/verify_account.erb +2 -1
- data/lib/generators/rodauth/migration/active_record/verify_login_change.erb +2 -1
- data/lib/generators/rodauth/migration/active_record/webauthn.erb +2 -1
- data/lib/generators/rodauth/migration_generator.rb +10 -4
- data/lib/generators/rodauth/templates/app/mailers/rodauth_mailer.rb +6 -6
- data/lib/generators/rodauth/templates/app/misc/rodauth_app.rb +2 -2
- data/lib/generators/rodauth/templates/app/misc/rodauth_main.rb +2 -0
- data/lib/rodauth/rails/controller_methods.rb +1 -1
- data/lib/rodauth/rails/feature/internal_request.rb +4 -2
- data/lib/rodauth/rails/feature.rb +2 -2
- data/lib/rodauth/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 879be6e1bbb5238e3f469002e1152d727948f970d2cda658b6ed0348a26f4b46
|
4
|
+
data.tar.gz: 79042f44b03bb8ab7f2225b79697b3399f79de272dc1c414de5ddc91b788b1cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cb9d96c3e60c64a3f8367dd122f3eff3448f0c9a147510173a8d781483d7de6a88c264a717db14864e26a830a153c09bcbf6bad4865be97d3be248fcd0265d0
|
7
|
+
data.tar.gz: 422b0db632d1e0317d0f38c10d60405f2e53daf083919b460fcb29157e238ac0c2e6249660e09dc4a7f452718629d604c7a1211e073d32e4884a0b6ab4fea32a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 1.6.0 (2022-09-14)
|
2
|
+
|
3
|
+
* Avoid creating IDENTITY columns for primary foreign keys on SQL Server with Active Record (@janko)
|
4
|
+
|
5
|
+
* Make configuration name argument required in generated `RodauthMailer` (@janko)
|
6
|
+
|
7
|
+
* Make the Rails integration work without Action Mailer loaded (@janko)
|
8
|
+
|
9
|
+
* Don't redirect to login page when account is missing in `current_account` method (@janko)
|
10
|
+
|
1
11
|
## 1.5.5 (2022-08-04)
|
2
12
|
|
3
13
|
* 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.
|
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.
|
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.
|
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.
|
954
|
+
`rodauth.require_account` in a `before_action` filter).
|
955
955
|
|
956
956
|
### Roda app
|
957
957
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# Used by the account expiration feature
|
2
|
-
create_table :account_activity_times
|
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
|
3
|
-
t
|
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
|
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
|
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
|
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
|
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,5 +1,6 @@
|
|
1
1
|
# Used by the remember me feature
|
2
|
-
create_table :account_remember_keys
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
-
|
107
|
+
:integer
|
102
108
|
end
|
103
109
|
end
|
104
110
|
|
@@ -1,19 +1,19 @@
|
|
1
1
|
class RodauthMailer < ApplicationMailer
|
2
|
-
def verify_account(name
|
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
|
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
|
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
|
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
|
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
|
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.
|
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.
|
21
|
+
# rodauth.require_account
|
22
22
|
# end
|
23
23
|
|
24
24
|
# ==> Secondary configurations
|
@@ -56,6 +56,7 @@ 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
|
@@ -81,6 +82,7 @@ class RodauthMain < Rodauth::Rails::Auth
|
|
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.
|
@@ -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
|
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.
|
4
|
+
version: 1.6.0
|
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-
|
11
|
+
date: 2022-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|