rodauth-rails 0.2.1 → 0.3.0

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: 32eea791dff9c98b9e78d209ba375d08095f07ec1d0ba0e852e5af83602e2128
4
- data.tar.gz: f12a2c57d4f3dee31efd10c6ba8fd211af62d8636cda5118fcc949642ded1e29
3
+ metadata.gz: b6bb43d7d1d355de281ce5fe57e1e00a13943f29efe93d39dc98099aa100c78c
4
+ data.tar.gz: 43034ad43125b0bb56132b57dd27cacdc4e9833c285f98256e67a989da84321c
5
5
  SHA512:
6
- metadata.gz: c722443088524cfedbffa17336de213dbcb004fe0866cb418f9bdc27a4a3a4b3af0ccd954a991bdc4d5e100278bd4738fc2a17b58a43555ddc725dcc49cca21b
7
- data.tar.gz: a97951dd6653c70af6397633b6628450779497a80be7b7dd294fbd09c8f91b4d82fe722190911d7324af7a3ff2c4b9ff274dd55adde8c8983fbc513e5c81d12d
6
+ metadata.gz: fb66ec48409f5f15f1e0953a8ae8a715cec48811e1ba81ea25015128f360487425c0fd09574da22ece00277e9e488204bc9393212631ec4d3c235f16f3064aaa
7
+ data.tar.gz: 15cbe441d8ff403f3db98d41710a32d8cb819c1961e5f25187e93411b3ec5dad7b1a0c508e6efa54df8fc08cd169587c07948a4c8da2b70edb7a2751f4bd6b09
@@ -1,3 +1,11 @@
1
+ ## 0.3.0 (2020-09-18)
2
+
3
+ * Handle custom configured database migration paths in install generator (@janko)
4
+
5
+ * Allow specifying features as plain arguments in `rodauth:views` generator (@janko)
6
+
7
+ * Add some missing foreign key constraints in generated migration file (@janko)
8
+
1
9
  ## 0.2.1 (2020-07-26)
2
10
 
3
11
  * Fix incorrect JDBC connect syntax in `sequel.rb` template on JRuby (@janko)
data/README.md CHANGED
@@ -82,10 +82,8 @@ ActiveRecord connection.
82
82
  # config/initializers/sequel.rb
83
83
  require "sequel/core"
84
84
 
85
- # initialize the appropriate Sequel adapter without creating a connection
86
- DB = Sequel.postgres(test: false)
87
- # have Sequel use ActiveRecord's connection for database interaction
88
- DB.extension :activerecord_connection
85
+ # initialize Sequel and have it reuse Active Record's database connection
86
+ DB = Sequel.postgres(extensions: :activerecord_connection)
89
87
  ```
90
88
 
91
89
  ### Rodauth app
@@ -162,17 +160,24 @@ These links are fully functional, feel free to visit them and interact with the
162
160
  pages. The templates that ship with Rodauth aim to provide a complete
163
161
  authentication experience, and the forms use [Bootstrap] markup.
164
162
 
165
- Let's also add the `#current_account` method for retrieving the account of the
166
- the authenticated session:
163
+ Let's also load the account record for authenticated requests and expose it via
164
+ `#current_account`:
167
165
 
168
166
  ```rb
169
167
  # app/controllers/application_controller.rb
170
168
  class ApplicationController < ActionController::Base
169
+ before_action :load_account, if: -> { rodauth.authenticated? }
170
+
171
171
  private
172
172
 
173
- def current_account
174
- @current_account ||= Account.find(rodauth.session_value)
173
+ def load_account
174
+ @current_account = Account.find(rodauth.session_value)
175
+ rescue ActiveRecord::RecordNotFound
176
+ rodauth.logout
177
+ rodauth.login_required
175
178
  end
179
+
180
+ attr_reader :current_account
176
181
  helper_method :current_account
177
182
  end
178
183
  ```
@@ -258,7 +263,7 @@ You can pass a list of Rodauth features to the generator to create views for
258
263
  these features (this will not remove any existing views):
259
264
 
260
265
  ```sh
261
- $ rails generate rodauth:views --features login create_account lockout otp
266
+ $ rails generate rodauth:views login create_account lockout otp
262
267
  ```
263
268
 
264
269
  Or you can generate views for all features:
@@ -1,12 +1,11 @@
1
1
  require "rails/generators/base"
2
- require "rails/generators/migration"
3
- require "rails/generators/active_record"
2
+ require "rails/generators/active_record/migration"
4
3
 
5
4
  module Rodauth
6
5
  module Rails
7
6
  module Generators
8
7
  class InstallGenerator < ::Rails::Generators::Base
9
- include ::Rails::Generators::Migration
8
+ include ::ActiveRecord::Generators::Migration
10
9
 
11
10
  source_root "#{__dir__}/templates"
12
11
  namespace "rodauth:install"
@@ -14,7 +13,7 @@ module Rodauth
14
13
  def create_rodauth_migration
15
14
  return unless defined?(ActiveRecord::Base)
16
15
 
17
- migration_template "db/migrate/create_rodauth.rb", "db/migrate/create_rodauth.rb"
16
+ migration_template "db/migrate/create_rodauth.rb", File.join(db_migrate_path, "create_rodauth.rb")
18
17
  end
19
18
 
20
19
  def create_rodauth_initializer
@@ -45,38 +44,32 @@ module Rodauth
45
44
 
46
45
  private
47
46
 
48
- # required by #migration_template action
49
- def self.next_migration_number(dirname)
50
- ActiveRecord::Generators::Base.next_migration_number(dirname)
47
+ def db_migrate_path
48
+ return "db/migrate" unless activerecord_at_least?(5, 0)
49
+ super
51
50
  end
52
51
 
53
52
  def migration_version
54
- if ActiveRecord.version >= Gem::Version.new("5.0.0")
53
+ if activerecord_at_least?(5, 0)
55
54
  "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
56
55
  end
57
56
  end
58
57
 
59
- if RUBY_ENGINE == "jruby"
60
- def sequel_adapter
61
- case activerecord_adapter
62
- when "postgresql" then "postgresql"
63
- when "mysql2" then "mysql"
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
58
+ def sequel_adapter
59
+ case activerecord_adapter
60
+ when "postgresql" then "postgres#{"ql" if RUBY_ENGINE == "jruby"}"
61
+ when "mysql2" then "mysql#{"2" unless RUBY_ENGINE == "jruby"}"
62
+ when "sqlite3" then "sqlite"
74
63
  end
75
64
  end
76
65
 
77
66
  def activerecord_adapter
78
67
  ActiveRecord::Base.connection_config.fetch(:adapter)
79
68
  end
69
+
70
+ def activerecord_at_least?(major, minor)
71
+ ActiveRecord.version >= Gem::Version.new("#{major}.#{minor}")
72
+ end
80
73
  end
81
74
  end
82
75
  end
@@ -1,10 +1,8 @@
1
1
  require "sequel/core"
2
2
 
3
- # initialize the appropriate Sequel adapter without creating a connection
3
+ # initialize Sequel and have it reuse Active Record's database connection
4
4
  <%- if RUBY_ENGINE == "jruby" -%>
5
- DB = Sequel.connect("jdbc:<%= sequel_adapter %>://", test: false)
5
+ DB = Sequel.connect("jdbc:<%= sequel_adapter %>://", extensions: :activerecord_connection)
6
6
  <% else -%>
7
- DB = Sequel.<%= sequel_adapter %>(test: false)
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
@@ -53,7 +53,7 @@ class CreateRodauth < ActiveRecord::Migration<%= migration_version %>
53
53
 
54
54
  # # Used by the audit logging feature
55
55
  # create_table :account_authentication_audit_logs do |t|
56
- # t.references :account, null: false
56
+ # t.references :account, foreign_key: true, null: false
57
57
  # t.datetime :at, null: false, default: -> { "CURRENT_TIMESTAMP" }
58
58
  # t.text :message, null: false
59
59
  <% case activerecord_adapter -%>
@@ -70,7 +70,7 @@ class CreateRodauth < ActiveRecord::Migration<%= migration_version %>
70
70
 
71
71
  # # Used by the jwt refresh feature
72
72
  # create_table :account_jwt_refresh_keys do |t|
73
- # t.references :account, null: false
73
+ # t.references :account, foreign_key: true, null: false
74
74
  # t.string :key, null: false
75
75
  # t.datetime :deadline, null: false
76
76
  # t.index :account_id, name: "account_jwt_rk_account_id_idx"
@@ -78,7 +78,7 @@ class CreateRodauth < ActiveRecord::Migration<%= migration_version %>
78
78
 
79
79
  # # Used by the disallow_password_reuse feature
80
80
  # create_table :account_previous_password_hashes do |t|
81
- # t.references :account
81
+ # t.references :account, foreign_key: true
82
82
  # t.string :password_hash, null: false
83
83
  # end
84
84
 
@@ -124,7 +124,7 @@ class CreateRodauth < ActiveRecord::Migration<%= migration_version %>
124
124
 
125
125
  # # Used by the active sessions feature
126
126
  # create_table :account_active_session_keys, primary_key: [:account_id, :session_id] do |t|
127
- # t.references :account
127
+ # t.references :account, foreign_key: true
128
128
  # t.string :session_id
129
129
  # t.datetime :created_at, null: false, default: -> { "CURRENT_TIMESTAMP" }
130
130
  # t.datetime :last_use, null: false, default: -> { "CURRENT_TIMESTAMP" }
@@ -136,7 +136,7 @@ class CreateRodauth < ActiveRecord::Migration<%= migration_version %>
136
136
  # t.string :webauthn_id, null: false
137
137
  # end
138
138
  # create_table :account_webauthn_keys, primary_key: [:account_id, :webauthn_id] do |t|
139
- # t.references :account
139
+ # t.references :account, foreign_key: true
140
140
  # t.string :webauthn_id
141
141
  # t.string :public_key, null: false
142
142
  # 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
- features = options[:all] ? VIEWS.keys : options[:features].map(&:to_sym)
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] || []
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "rodauth-rails"
3
- spec.version = "0.2.1"
3
+ spec.version = "0.3.0"
4
4
  spec.authors = ["Janko Marohnić"]
5
5
  spec.email = ["janko.marohnic@gmail.com"]
6
6
 
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.1
4
+ version: 0.3.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: 2020-07-26 00:00:00.000000000 Z
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties