rodauth-rails 1.5.4 → 1.5.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c63496f359a15bb061b6b419a609cbe63c24991e156731721d9f077ecf9deac4
4
- data.tar.gz: 68212d9c722391c8c79f8bf8c48f8a05a39410ea0d97396876a6c2f5e92f103a
3
+ metadata.gz: b9640fa912cb535846cd94b3df3361e9763f2267107205287783885e587e774b
4
+ data.tar.gz: d135e8e958f0210b22fe694ba2a77e6d4fde74df339b8ec06440ac0f83771c90
5
5
  SHA512:
6
- metadata.gz: 3632843dbd0214b73fa23134a0f2b42ec3b8f1c33430af1c776c685956ccf50e475840993299bff9863491456a369ad42b7e688e3ed03b783e51f4585d6be621
7
- data.tar.gz: 6c123e024a51d3c2ba6b224b64c1f21d3b46363523d5b498e93fbe659052489660a61a3dd83da5080a07067d9052a82450da17a7bf156e9c905b2aa81ca861f6
6
+ metadata.gz: 1067a2467e0f7dacbfe3a703d6f1e4ad561c9dc7a72fbe3942a20b43b8892211c2509ec3b71c47ba30bf16bea0f7163f8ecb82a5aceaabb23f01a5705d256d12
7
+ data.tar.gz: ce2464227d1c0a5e5bc3452f05c392787b61fd6b3c530a89c99047c69a4bcceabf08778aaa169c57fa39dbae80efdb455b334881f04b069099fab7b666dc1cfe
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.5.5 (2022-08-04)
2
+
3
+ * Don't raise `ArgumentError` when calling `#current_account` without being logged in (@benkoshy)
4
+
5
+ * Abort `rodauth:views` generator when unknown feature was specified (@janko)
6
+
7
+ * Abort `rodauth:migration` generator when unknown feature was specified (@janko)
8
+
1
9
  ## 1.5.4 (2022-07-21)
2
10
 
3
11
  * Generate account fixtures in `spec/fixtures` directory when using RSpec (@benkoshy)
data/README.md CHANGED
@@ -14,7 +14,7 @@ Provides Rails integration for the [Rodauth] authentication framework.
14
14
  🎥 Screencasts:
15
15
 
16
16
  * [Rails Authentication with Rodauth](https://www.youtube.com/watch?v=2hDpNikacf0)
17
- * [Multifactor Authentication via TOTP with Rodauth](https://www.youtube.com/watch?v=9ON-kgXpz2A)
17
+ * [Multifactor Authentication with Rodauth](https://www.youtube.com/watch?v=9ON-kgXpz2A&list=PLkGQXZLACDTGKsaRWstkHQdm2CUmT3SZ-) ([TOTP](https://youtu.be/9ON-kgXpz2A), [Recovery Codes](https://youtu.be/lkFCcE1Q5-w))
18
18
 
19
19
  📚 Articles:
20
20
 
@@ -1180,7 +1180,7 @@ License](https://opensource.org/licenses/MIT).
1180
1180
 
1181
1181
  Everyone interacting in the rodauth-rails project's codebases, issue trackers,
1182
1182
  chat rooms and mailing lists is expected to follow the [code of
1183
- conduct](https://github.com/janko/rodauth-rails/blob/master/CODE_OF_CONDUCT.md).
1183
+ conduct](CODE_OF_CONDUCT.md).
1184
1184
 
1185
1185
  [Rodauth]: https://github.com/jeremyevans/rodauth
1186
1186
  [Sequel]: https://github.com/jeremyevans/sequel
@@ -88,8 +88,8 @@ module Rodauth
88
88
  private
89
89
 
90
90
  def migration_features
91
- features = [:base, :reset_password, :verify_account, :verify_login_change]
92
- features << :remember unless jwt?
91
+ features = ["base", "reset_password", "verify_account", "verify_login_change"]
92
+ features << "remember" unless jwt?
93
93
  features
94
94
  end
95
95
 
@@ -17,7 +17,7 @@ module Rodauth
17
17
  desc: "Name of the generated migration file"
18
18
 
19
19
  def create_rodauth_migration
20
- return if features.empty?
20
+ validate_features or return
21
21
 
22
22
  migration_template "db/migrate/create_rodauth.rb", File.join(db_migrate_path, "#{migration_name}.rb")
23
23
  end
@@ -30,7 +30,6 @@ module Rodauth
30
30
 
31
31
  def migration_content
32
32
  features
33
- .select { |feature| File.exist?(migration_chunk(feature)) }
34
33
  .map { |feature| File.read(migration_chunk(feature)) }
35
34
  .map { |content| erb_eval(content) }
36
35
  .join("\n")
@@ -45,19 +44,37 @@ module Rodauth
45
44
  end
46
45
  end
47
46
 
47
+ def migration_chunk(feature)
48
+ "#{MIGRATION_DIR}/#{feature}.erb"
49
+ end
50
+
51
+ def validate_features
52
+ if features.empty?
53
+ say "No features specified!", :yellow
54
+ false
55
+ elsif (features - valid_features).any?
56
+ say "No available migration for feature(s): #{(features - valid_features).join(", ")}", :red
57
+ false
58
+ else
59
+ true
60
+ end
61
+ end
62
+
63
+ def valid_features
64
+ Dir["#{MIGRATION_DIR}/*.erb"].map { |filename| File.basename(filename, ".erb") }
65
+ end
66
+
48
67
  if defined?(::ActiveRecord::Railtie) # Active Record
49
68
  include ::ActiveRecord::Generators::Migration
50
69
 
70
+ MIGRATION_DIR = "#{__dir__}/migration/active_record"
71
+
51
72
  def db_migrate_path
52
73
  return "db/migrate" unless ActiveRecord.version >= Gem::Version.new("5.0")
53
74
 
54
75
  super
55
76
  end
56
77
 
57
- def migration_chunk(feature)
58
- "#{__dir__}/migration/active_record/#{feature}.erb"
59
- end
60
-
61
78
  def migration_version
62
79
  return unless ActiveRecord.version >= Gem::Version.new("5.0")
63
80
 
@@ -95,6 +112,8 @@ module Rodauth
95
112
  else # Sequel
96
113
  include ::Rails::Generators::Migration
97
114
 
115
+ MIGRATION_DIR = "#{__dir__}/migration/sequel"
116
+
98
117
  def self.next_migration_number(dirname)
99
118
  next_migration_number = current_migration_number(dirname) + 1
100
119
  [Time.now.utc.strftime('%Y%m%d%H%M%S'), format('%.14d', next_migration_number)].max
@@ -104,10 +123,6 @@ module Rodauth
104
123
  "db/migrate"
105
124
  end
106
125
 
107
- def migration_chunk(feature)
108
- "#{__dir__}/migration/sequel/#{feature}.erb"
109
- end
110
-
111
126
  def db
112
127
  db = ::Sequel::DATABASES.first if defined?(::Sequel)
113
128
  db or fail Rodauth::Rails::Error, "missing Sequel database connection"
@@ -46,10 +46,7 @@ module Rodauth
46
46
  }
47
47
 
48
48
  def create_views
49
- views = features.inject([]) do |list, feature|
50
- list |= VIEWS[feature] || []
51
- list |= VIEWS[DEPENDENCIES[feature]] || []
52
- end
49
+ validate_features or return
53
50
 
54
51
  views.each do |view|
55
52
  copy_file "app/views/rodauth/#{view}.html.erb", "app/views/#{directory}/#{view}.html.erb" do |content|
@@ -63,13 +60,29 @@ module Rodauth
63
60
 
64
61
  private
65
62
 
63
+ def views
64
+ features.inject([]) do |list, feature|
65
+ list |= VIEWS.fetch(feature)
66
+ list |= VIEWS[DEPENDENCIES[feature]] || []
67
+ end
68
+ end
69
+
70
+ def validate_features
71
+ if (features - VIEWS.keys).any?
72
+ say "No available view template for feature(s): #{(features - VIEWS.keys).join(", ")}", :error
73
+ false
74
+ else
75
+ true
76
+ end
77
+ end
78
+
66
79
  def features
67
80
  if options[:all]
68
81
  VIEWS.keys
69
82
  elsif selected_features
70
83
  selected_features.map(&:to_sym)
71
84
  else
72
- rodauth_configuration.features
85
+ rodauth_configuration.features & VIEWS.keys
73
86
  end
74
87
  end
75
88
 
@@ -9,10 +9,12 @@ module Rodauth
9
9
  end
10
10
 
11
11
  def rails_account
12
+ return unless logged_in?
13
+
12
14
  account_from_session unless account
13
15
 
14
16
  unless account
15
- clear_session if logged_in?
17
+ clear_session
16
18
  return
17
19
  end
18
20
 
@@ -1,5 +1,5 @@
1
1
  module Rodauth
2
2
  module Rails
3
- VERSION = "1.5.4"
3
+ VERSION = "1.5.5"
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.4
4
+ version: 1.5.5
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-07-21 00:00:00.000000000 Z
11
+ date: 2022-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties