passwordless 1.3.0 → 1.5.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: 2242a4b95f1a99d5be1b889539dc6dd9f1eda711ce616f3b090f12dd68337254
4
- data.tar.gz: afd9ea1fd2d3b3f15f10a4772d231c53adfd524e22de00d833a9183b34d69397
3
+ metadata.gz: 472a9d736665b6a1e1a71bf5175214f3acc414e0c918a33825c98a1d7ac02624
4
+ data.tar.gz: 9e12898751e19fc7104c62826eaf7c9ee4e17a14a12efc66419eab4850dae720
5
5
  SHA512:
6
- metadata.gz: 9b2ceb4c68972744e10ac6dd56e2e863b5e229bb31053b7159a16c020a2cfa55ffe1affcbef92ca52ee03de79d4d675cb5b3f4340e1c888e064e9ab246f3e455
7
- data.tar.gz: 7dd102d25dd4cbb60ab73d30732f78a6cd1d6757e345e3b304c9b1abe4394b6b1d883c1368bd7eaa12ecee986ecdfabf3d82cea081048694807388fc5a1bfd69
6
+ metadata.gz: 58b5bac3c0260d68a86fc7d9c3258457405a3670e0f8333959aa1ee54774ab68774728522d2e40c5d3b67a430f3b952af8903bb5d29b4ee12b6a291e3415fd17
7
+ data.tar.gz: 42252595f95f48896cd08ec1be77a28657553ae287cc52213bed5cc343c38121bf12c8aba1db8ea002237ea8b5c1d706a8fc8f10dc7b9522c72c80218e4d35a5
data/README.md CHANGED
@@ -70,7 +70,7 @@ class ApplicationController < ActionController::Base
70
70
  def require_user!
71
71
  return if current_user
72
72
  save_passwordless_redirect_location!(User) # <-- optional, see below
73
- redirect_to root_path, flash: { error: 'You are not worthy!' }
73
+ redirect_to root_path, alert: "You are not worthy!"
74
74
  end
75
75
  end
76
76
  ```
@@ -237,7 +237,7 @@ class ApplicationController < ActionController::Base
237
237
  def require_user!
238
238
  return if current_user
239
239
  save_passwordless_redirect_location!(User) # <-- this one!
240
- redirect_to root_path, flash: {error: 'You are not worthy!'}
240
+ redirect_to root_path, alert: "You are not worthy!"
241
241
  end
242
242
  end
243
243
  ```
@@ -105,11 +105,11 @@ module Passwordless
105
105
  protected
106
106
 
107
107
  def passwordless_sign_out_redirect_path
108
- Passwordless.config.sign_out_redirect_path
108
+ call_or_return(Passwordless.config.sign_out_redirect_path)
109
109
  end
110
110
 
111
111
  def passwordless_failure_redirect_path
112
- Passwordless.config.failure_redirect_path
112
+ call_or_return(Passwordless.config.failure_redirect_path)
113
113
  end
114
114
 
115
115
  def passwordless_query_redirect_path
@@ -119,11 +119,22 @@ module Passwordless
119
119
  nil
120
120
  end
121
121
 
122
- def passwordless_success_redirect_path
123
- return Passwordless.config.success_redirect_path unless Passwordless.config.redirect_back_after_sign_in
122
+ def passwordless_success_redirect_path(authenticatable)
123
+ success_redirect_path = Passwordless.config.success_redirect_path
124
124
 
125
- session_redirect_url = reset_passwordless_redirect_location!(authenticatable_class)
126
- passwordless_query_redirect_path || session_redirect_url || Passwordless.config.success_redirect_path
125
+ if success_redirect_path.respond_to?(:call)
126
+ success_redirect_path = call_or_return(
127
+ success_redirect_path,
128
+ *[authenticatable].first(success_redirect_path.arity)
129
+ )
130
+ end
131
+
132
+ if Passwordless.config.redirect_back_after_sign_in
133
+ session_redirect_url = reset_passwordless_redirect_location!(authenticatable_class)
134
+ return passwordless_query_redirect_path || session_redirect_url || success_redirect_path
135
+ end
136
+
137
+ success_redirect_path
127
138
  end
128
139
 
129
140
  private
@@ -138,7 +149,11 @@ module Passwordless
138
149
  def authenticate_and_sign_in(session, token)
139
150
  if session.authenticate(token)
140
151
  sign_in(session)
141
- redirect_to(passwordless_success_redirect_path, status: :see_other, **redirect_to_options)
152
+ redirect_to(
153
+ passwordless_success_redirect_path(session.authenticatable),
154
+ status: :see_other,
155
+ **redirect_to_options
156
+ )
142
157
  else
143
158
  flash[:error] = I18n.t("passwordless.sessions.errors.invalid_token")
144
159
  render(status: :forbidden, action: "show")
@@ -164,6 +179,14 @@ module Passwordless
164
179
  authenticatable_type.constantize
165
180
  end
166
181
 
182
+ def call_or_return(value, *args)
183
+ if value.respond_to?(:call)
184
+ instance_exec(*args, &value)
185
+ else
186
+ value
187
+ end
188
+ end
189
+
167
190
  def find_authenticatable
168
191
  if authenticatable_class.respond_to?(:fetch_resource_for_passwordless)
169
192
  authenticatable_class.fetch_resource_for_passwordless(normalized_email_param)
@@ -10,7 +10,7 @@ module Passwordless
10
10
  # @param session [Session] An instance of Passwordless::Session
11
11
  # @param token [String] The token in plaintext. Falls back to `session.token` hoping it
12
12
  # is still in memory (optional)
13
- def sign_in(session, token = nil)
13
+ def sign_in(session, token = nil, url_options = {})
14
14
  @token = token || session.token
15
15
 
16
16
  @magic_link = Passwordless.context.url_for(
@@ -18,6 +18,7 @@ module Passwordless
18
18
  action: "confirm",
19
19
  id: session.to_param,
20
20
  token: @token,
21
+ **url_options,
21
22
  **default_url_options
22
23
  )
23
24
 
@@ -75,6 +75,10 @@ if defined?(ActionDispatch::SystemTestCase)
75
75
  ActionDispatch::SystemTestCase.send(:include, ::Passwordless::TestHelpers::SystemTestCase)
76
76
  end
77
77
 
78
+ if defined?(ActionDispatch::IntegrationTest)
79
+ ActionDispatch::IntegrationTest.send(:include, ::Passwordless::TestHelpers::RequestTestCase)
80
+ end
81
+
78
82
  if defined?(RSpec)
79
83
  RSpec.configure do |config|
80
84
  config.include(::Passwordless::TestHelpers::ControllerTestCase, type: :controller)
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Passwordless
4
4
  # :nodoc:
5
- VERSION = "1.3.0"
5
+ VERSION = "1.5.0"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passwordless
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikkel Malmberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-24 00:00:00.000000000 Z
11
+ date: 2024-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
- rubygems_version: 3.5.5
94
+ rubygems_version: 3.5.6
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Add authentication to your app without all the ickyness of passwords.