rails_jwt_auth 1.4.1 → 1.7.1
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/README.md +44 -22
- data/app/controllers/concerns/rails_jwt_auth/authenticable_helper.rb +8 -4
- data/app/controllers/concerns/rails_jwt_auth/params_helper.rb +3 -3
- data/app/controllers/rails_jwt_auth/confirmations_controller.rb +4 -1
- data/app/controllers/rails_jwt_auth/invitations_controller.rb +1 -0
- data/app/controllers/rails_jwt_auth/passwords_controller.rb +11 -2
- data/app/mailers/rails_jwt_auth/mailer.rb +17 -25
- data/app/models/concerns/rails_jwt_auth/authenticatable.rb +4 -2
- data/app/models/concerns/rails_jwt_auth/confirmable.rb +26 -12
- data/app/models/concerns/rails_jwt_auth/invitable.rb +2 -3
- data/app/models/concerns/rails_jwt_auth/lockable.rb +1 -2
- data/app/models/concerns/rails_jwt_auth/recoverable.rb +6 -5
- data/lib/rails_jwt_auth.rb +5 -0
- data/lib/rails_jwt_auth/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b624ce7e99bced2abcbe29c05955af2fa4ccf7b6d9badc74e5effdd2b98ac4e9
|
4
|
+
data.tar.gz: 427995dd79006f041e27de387ce9affa2294d2eedcefcf02eaf502c3f9d60630
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffda5aa2b329f926133837ba6fa254643c0637eaef292b3f63ec4305dedd34f3e1d238fa52033bfbbe4e9407d916af6ff4fefcee2f58923d08a1e906b7991be9
|
7
|
+
data.tar.gz: d0a639b9e6345feaaa3d28095cbed507e549fa8a1d61c4f125cb79a7ee895ba937c1bdd13324d4742e5f6b7594bd6d4dee146b314301bc4b026b721b0bd6ad07
|
data/README.md
CHANGED
@@ -59,7 +59,7 @@ rails g rails_jwt_auth:migrate
|
|
59
59
|
|
60
60
|
## Configuration
|
61
61
|
|
62
|
-
You can edit configuration options into `config/initializers/
|
62
|
+
You can edit configuration options into `config/initializers/rails_jwt_auth.rb` file created by generator.
|
63
63
|
|
64
64
|
| Option | Default value | Description |
|
65
65
|
| ------------------------------- | ----------------- | ---------------------------------------------------------------------- |
|
@@ -187,12 +187,31 @@ end
|
|
187
187
|
|
188
188
|
Return current signed-in user.
|
189
189
|
|
190
|
+
- **jwt_payload**
|
191
|
+
|
192
|
+
Return current jwt payload.
|
193
|
+
|
190
194
|
- **signed_in?**
|
191
195
|
|
192
196
|
Verify if a user is signed in.
|
193
197
|
|
194
198
|
## Default Controllers API
|
195
199
|
|
200
|
+
| Prefix | Verb | URI Pattern | Controller#Action |
|
201
|
+
| ------------ | ------ | ---------------------------- | ----------------------------------- |
|
202
|
+
| session | DELETE | /session(.:format) | rails_jwt_auth/sessions#destroy |
|
203
|
+
| | POST | /session(.:format) | rails_jwt_auth/sessions#create |
|
204
|
+
| registration | POST | /registration(.:format) | rails_jwt_auth/registrations#create |
|
205
|
+
|confirmations | POST | /confirmations(.:format) | rails_jwt_auth/confirmations#create |
|
206
|
+
| confirmation | PATCH | /confirmations/:id(.:format) | rails_jwt_auth/confirmations#update |
|
207
|
+
| | PUT | /confirmations/:id(.:format) | rails_jwt_auth/confirmations#update |
|
208
|
+
| passwords | POST | /passwords(.:format) | rails_jwt_auth/passwords#create |
|
209
|
+
| password | PATCH | /passwords/:id(.:format) | rails_jwt_auth/passwords#update |
|
210
|
+
| | PUT | /passwords/:id(.:format) | rails_jwt_auth/passwords#update |
|
211
|
+
| invitations | POST | /invitations(.:format) | rails_jwt_auth/invitations#create |
|
212
|
+
| invitation | PATCH | /invitations/:id(.:format) | rails_jwt_auth/invitations#update |
|
213
|
+
| | PUT | /invitations/:id(.:format) | rails_jwt_auth/invitations#update |
|
214
|
+
|
196
215
|
### Session
|
197
216
|
|
198
217
|
Session api is defined by `RailsJwtAuth::SessionsController`.
|
@@ -205,8 +224,8 @@ Session api is defined by `RailsJwtAuth::SessionsController`.
|
|
205
224
|
method: POST,
|
206
225
|
data: {
|
207
226
|
session: {
|
208
|
-
email:
|
209
|
-
password:
|
227
|
+
email: 'user@email.com',
|
228
|
+
password: '12345678'
|
210
229
|
}
|
211
230
|
}
|
212
231
|
}
|
@@ -234,8 +253,8 @@ Registration api is defined by `RailsJwtAuth::RegistrationsController`.
|
|
234
253
|
method: POST,
|
235
254
|
data: {
|
236
255
|
user: {
|
237
|
-
email:
|
238
|
-
password:
|
256
|
+
email: 'user@email.com',
|
257
|
+
password: '12345678'
|
239
258
|
}
|
240
259
|
}
|
241
260
|
}
|
@@ -245,15 +264,15 @@ Registration api is defined by `RailsJwtAuth::RegistrationsController`.
|
|
245
264
|
|
246
265
|
Confirmation api is defined by `RailsJwtAuth::ConfirmationsController`.
|
247
266
|
|
267
|
+
It is necessary to set a value for `confirmations_url` option into `config/initializers/rails_jwt_auth.rb`.
|
268
|
+
|
248
269
|
1. Confirm user:
|
249
270
|
|
250
271
|
```js
|
251
272
|
{
|
252
|
-
url: host/
|
273
|
+
url: host/confirmations/:token,
|
253
274
|
method: PUT
|
254
|
-
data: {
|
255
|
-
confirmation_token: "token"
|
256
|
-
}
|
275
|
+
data: {}
|
257
276
|
}
|
258
277
|
```
|
259
278
|
|
@@ -261,11 +280,11 @@ Confirmation api is defined by `RailsJwtAuth::ConfirmationsController`.
|
|
261
280
|
|
262
281
|
```js
|
263
282
|
{
|
264
|
-
url: host/
|
283
|
+
url: host/confirmations,
|
265
284
|
method: POST,
|
266
285
|
data: {
|
267
286
|
confirmation: {
|
268
|
-
email:
|
287
|
+
email: 'user@example.com'
|
269
288
|
}
|
270
289
|
}
|
271
290
|
}
|
@@ -279,11 +298,11 @@ Password api is defined by `RailsJwtAuth::PasswordsController`.
|
|
279
298
|
|
280
299
|
```js
|
281
300
|
{
|
282
|
-
url: host/
|
301
|
+
url: host/passwords,
|
283
302
|
method: POST,
|
284
303
|
data: {
|
285
304
|
password: {
|
286
|
-
email:
|
305
|
+
email: 'user@example.com'
|
287
306
|
}
|
288
307
|
}
|
289
308
|
}
|
@@ -293,10 +312,9 @@ Password api is defined by `RailsJwtAuth::PasswordsController`.
|
|
293
312
|
|
294
313
|
```js
|
295
314
|
{
|
296
|
-
url: host/
|
315
|
+
url: host/passwords/:token,
|
297
316
|
method: PUT,
|
298
317
|
data: {
|
299
|
-
reset_password_token: "token",
|
300
318
|
password: {
|
301
319
|
password: '1234',
|
302
320
|
password_confirmation: '1234'
|
@@ -317,7 +335,7 @@ Invitations api is provided by `RailsJwtAuth::InvitationsController`.
|
|
317
335
|
method: POST,
|
318
336
|
data: {
|
319
337
|
invitation: {
|
320
|
-
email:
|
338
|
+
email: 'user@example.com',
|
321
339
|
// More fields of your user
|
322
340
|
}
|
323
341
|
}
|
@@ -350,7 +368,8 @@ Unlock api is provided by `RailsJwtAuth::UnlocksController`.
|
|
350
368
|
```js
|
351
369
|
{
|
352
370
|
url: host/unlocks/:unlock_token,
|
353
|
-
method: PUT
|
371
|
+
method: PUT,
|
372
|
+
data: {}
|
354
373
|
}
|
355
374
|
```
|
356
375
|
|
@@ -426,7 +445,10 @@ class CurrentUserController < ApplicationController
|
|
426
445
|
|
427
446
|
def update
|
428
447
|
if update_params[:password]
|
429
|
-
|
448
|
+
# update password and remove other sessions tokens
|
449
|
+
current_user.update_with_password(
|
450
|
+
update_params.merge(auth_tokens: [jwt_payload['auth_token']])
|
451
|
+
)
|
430
452
|
else
|
431
453
|
current_user.update_attributes(update_params)
|
432
454
|
end
|
@@ -471,7 +493,7 @@ require 'rails_jwt_auth/spec_helpers'
|
|
471
493
|
...
|
472
494
|
RSpec.configure do |config|
|
473
495
|
...
|
474
|
-
config.include RailsJwtAuth::SpecHelpers, :
|
496
|
+
config.include RailsJwtAuth::SpecHelpers, type: :controller
|
475
497
|
end
|
476
498
|
```
|
477
499
|
|
@@ -479,11 +501,11 @@ And then we can just call sign_in(user) to sign in as a user:
|
|
479
501
|
|
480
502
|
```ruby
|
481
503
|
describe ExampleController
|
482
|
-
it
|
483
|
-
expect { get :index }.to raise_error(RailsJwtAuth::
|
504
|
+
it 'blocks unauthenticated access' do
|
505
|
+
expect { get :index }.to raise_error(RailsJwtAuth::NotAuthorized)
|
484
506
|
end
|
485
507
|
|
486
|
-
it
|
508
|
+
it 'allows authenticated access' do
|
487
509
|
sign_in user
|
488
510
|
get :index
|
489
511
|
expect(response).to be_success
|
@@ -6,18 +6,22 @@ module RailsJwtAuth
|
|
6
6
|
@current_user
|
7
7
|
end
|
8
8
|
|
9
|
+
def jwt_payload
|
10
|
+
@jwt_payload
|
11
|
+
end
|
12
|
+
|
9
13
|
def signed_in?
|
10
14
|
!current_user.nil?
|
11
15
|
end
|
12
16
|
|
13
17
|
def authenticate!
|
14
18
|
begin
|
15
|
-
|
19
|
+
@jwt_payload = RailsJwtAuth::JwtManager.decode_from_request(request).first
|
16
20
|
rescue JWT::ExpiredSignature, JWT::VerificationError, JWT::DecodeError
|
17
21
|
unauthorize!
|
18
22
|
end
|
19
23
|
|
20
|
-
if !@current_user = RailsJwtAuth.model.from_token_payload(
|
24
|
+
if !@current_user = RailsJwtAuth.model.from_token_payload(@jwt_payload)
|
21
25
|
unauthorize!
|
22
26
|
elsif @current_user.respond_to? :update_tracked_fields!
|
23
27
|
@current_user.update_tracked_fields!(request)
|
@@ -26,8 +30,8 @@ module RailsJwtAuth
|
|
26
30
|
|
27
31
|
def authenticate
|
28
32
|
begin
|
29
|
-
|
30
|
-
@current_user = RailsJwtAuth.model.from_token_payload(
|
33
|
+
@jwt_payload = RailsJwtAuth::JwtManager.decode_from_request(request).first
|
34
|
+
@current_user = RailsJwtAuth.model.from_token_payload(@jwt_payload)
|
31
35
|
rescue JWT::ExpiredSignature, JWT::VerificationError, JWT::DecodeError
|
32
36
|
@current_user = nil
|
33
37
|
end
|
@@ -9,7 +9,7 @@ module RailsJwtAuth
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def confirmation_create_params
|
12
|
-
params.require(:confirmation).permit(
|
12
|
+
params.require(:confirmation).permit(RailsJwtAuth.email_field_name)
|
13
13
|
end
|
14
14
|
|
15
15
|
def session_create_params
|
@@ -17,7 +17,7 @@ module RailsJwtAuth
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def password_create_params
|
20
|
-
params.require(:password).permit(
|
20
|
+
params.require(:password).permit(RailsJwtAuth.email_field_name)
|
21
21
|
end
|
22
22
|
|
23
23
|
def password_update_params
|
@@ -25,7 +25,7 @@ module RailsJwtAuth
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def invitation_create_params
|
28
|
-
params.require(:invitation).permit(
|
28
|
+
params.require(:invitation).permit(RailsJwtAuth.email_field_name)
|
29
29
|
end
|
30
30
|
|
31
31
|
def invitation_update_params
|
@@ -4,7 +4,10 @@ module RailsJwtAuth
|
|
4
4
|
include RenderHelper
|
5
5
|
|
6
6
|
def create
|
7
|
-
user = RailsJwtAuth.model.where(
|
7
|
+
user = RailsJwtAuth.model.where(
|
8
|
+
email: confirmation_create_params[RailsJwtAuth.email_field_name]
|
9
|
+
).first
|
10
|
+
|
8
11
|
return render_422(email: [{error: :not_found}]) unless user
|
9
12
|
|
10
13
|
user.send_confirmation_instructions ? render_204 : render_422(user.errors.details)
|
@@ -4,8 +4,17 @@ module RailsJwtAuth
|
|
4
4
|
include RenderHelper
|
5
5
|
|
6
6
|
def create
|
7
|
-
|
8
|
-
|
7
|
+
email_field = RailsJwtAuth.email_field_name
|
8
|
+
|
9
|
+
if password_create_params[email_field].blank?
|
10
|
+
return render_422(email_field => [{error: :blank}])
|
11
|
+
end
|
12
|
+
|
13
|
+
user = RailsJwtAuth.model.where(
|
14
|
+
email_field => password_create_params[email_field].to_s.strip.downcase
|
15
|
+
).first
|
16
|
+
|
17
|
+
return render_422(email_field => [{error: :not_found}]) unless user
|
9
18
|
|
10
19
|
user.send_reset_password_instructions ? render_204 : render_422(user.errors.details)
|
11
20
|
end
|
@@ -2,9 +2,13 @@ if defined?(ActionMailer)
|
|
2
2
|
class RailsJwtAuth::Mailer < ApplicationMailer
|
3
3
|
default from: RailsJwtAuth.mailer_sender
|
4
4
|
|
5
|
-
|
5
|
+
before_action do
|
6
|
+
@user = RailsJwtAuth.model.find(params[:user_id])
|
7
|
+
@subject = I18n.t("rails_jwt_auth.mailer.#{action_name}.subject")
|
8
|
+
end
|
9
|
+
|
10
|
+
def confirmation_instructions
|
6
11
|
raise RailsJwtAuth::NotConfirmationsUrl unless RailsJwtAuth.confirmations_url.present?
|
7
|
-
@user = user
|
8
12
|
|
9
13
|
@confirmations_url = add_param_to_url(
|
10
14
|
RailsJwtAuth.confirmations_url,
|
@@ -12,19 +16,15 @@ if defined?(ActionMailer)
|
|
12
16
|
@user.confirmation_token
|
13
17
|
)
|
14
18
|
|
15
|
-
|
16
|
-
mail(to: @user.unconfirmed_email || @user[RailsJwtAuth.email_field_name], subject: subject)
|
19
|
+
mail(to: @user.unconfirmed_email || @user[RailsJwtAuth.email_field_name], subject: @subject)
|
17
20
|
end
|
18
21
|
|
19
|
-
def email_changed
|
20
|
-
@user
|
21
|
-
subject = I18n.t('rails_jwt_auth.mailer.email_changed.subject')
|
22
|
-
mail(to: @user[RailsJwtAuth.email_field_name!], subject: subject)
|
22
|
+
def email_changed
|
23
|
+
mail(to: @user[RailsJwtAuth.email_field_name!], subject: @subject)
|
23
24
|
end
|
24
25
|
|
25
|
-
def reset_password_instructions
|
26
|
+
def reset_password_instructions
|
26
27
|
raise RailsJwtAuth::NotResetPasswordsUrl unless RailsJwtAuth.reset_passwords_url.present?
|
27
|
-
@user = user
|
28
28
|
|
29
29
|
@reset_passwords_url = add_param_to_url(
|
30
30
|
RailsJwtAuth.reset_passwords_url,
|
@@ -32,13 +32,11 @@ if defined?(ActionMailer)
|
|
32
32
|
@user.reset_password_token
|
33
33
|
)
|
34
34
|
|
35
|
-
|
36
|
-
mail(to: @user[RailsJwtAuth.email_field_name], subject: subject)
|
35
|
+
mail(to: @user[RailsJwtAuth.email_field_name], subject: @subject)
|
37
36
|
end
|
38
37
|
|
39
|
-
def set_password_instructions
|
38
|
+
def set_password_instructions
|
40
39
|
raise RailsJwtAuth::NotSetPasswordsUrl unless RailsJwtAuth.set_passwords_url.present?
|
41
|
-
@user = user
|
42
40
|
|
43
41
|
@reset_passwords_url = add_param_to_url(
|
44
42
|
RailsJwtAuth.set_passwords_url,
|
@@ -46,13 +44,11 @@ if defined?(ActionMailer)
|
|
46
44
|
@user.reset_password_token
|
47
45
|
)
|
48
46
|
|
49
|
-
|
50
|
-
mail(to: @user[RailsJwtAuth.email_field_name], subject: subject)
|
47
|
+
mail(to: @user[RailsJwtAuth.email_field_name], subject: @subject)
|
51
48
|
end
|
52
49
|
|
53
|
-
def send_invitation
|
50
|
+
def send_invitation
|
54
51
|
raise RailsJwtAuth::NotInvitationsUrl unless RailsJwtAuth.invitations_url.present?
|
55
|
-
@user = user
|
56
52
|
|
57
53
|
@invitations_url = add_param_to_url(
|
58
54
|
RailsJwtAuth.invitations_url,
|
@@ -60,17 +56,13 @@ if defined?(ActionMailer)
|
|
60
56
|
@user.invitation_token
|
61
57
|
)
|
62
58
|
|
63
|
-
|
64
|
-
mail(to: @user[RailsJwtAuth.email_field_name], subject: subject)
|
59
|
+
mail(to: @user[RailsJwtAuth.email_field_name], subject: @subject)
|
65
60
|
end
|
66
61
|
|
67
|
-
def send_unlock_instructions
|
68
|
-
@user = user
|
69
|
-
subject = I18n.t('rails_jwt_auth.mailer.send_unlock_instructions.subject')
|
70
|
-
|
62
|
+
def send_unlock_instructions
|
71
63
|
@unlock_url = add_param_to_url(RailsJwtAuth.unlock_url, 'unlock_token', @user.unlock_token)
|
72
64
|
|
73
|
-
mail(to: @user[RailsJwtAuth.email_field_name], subject: subject)
|
65
|
+
mail(to: @user[RailsJwtAuth.email_field_name], subject: @subject)
|
74
66
|
end
|
75
67
|
|
76
68
|
protected
|
@@ -46,8 +46,10 @@ module RailsJwtAuth
|
|
46
46
|
'invalid'
|
47
47
|
end
|
48
48
|
|
49
|
-
#
|
50
|
-
|
49
|
+
# if recoberable module is enabled ensure clean recovery to allow save
|
50
|
+
if self.respond_to? :reset_password_token
|
51
|
+
self.reset_password_token = self.reset_password_sent_at = nil
|
52
|
+
end
|
51
53
|
|
52
54
|
assign_attributes(params)
|
53
55
|
valid? # validates first other fields
|
@@ -33,16 +33,14 @@ module RailsJwtAuth
|
|
33
33
|
|
34
34
|
self.confirmation_token = SecureRandom.base58(24)
|
35
35
|
self.confirmation_sent_at = Time.current
|
36
|
-
|
37
|
-
mailer = Mailer.confirmation_instructions(self)
|
38
|
-
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
39
|
-
|
40
|
-
if RailsJwtAuth.send_email_changed_notification
|
41
|
-
mailer = Mailer.email_changed(self)
|
42
|
-
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
43
|
-
end
|
44
36
|
end
|
45
37
|
end
|
38
|
+
|
39
|
+
if defined?(ActiveRecord) && ancestors.include?(ActiveRecord::Base)
|
40
|
+
after_commit :deliver_email_changed_emails, if: :saved_change_to_unconfirmed_email?
|
41
|
+
elsif defined?(Mongoid) && ancestors.include?(Mongoid::Document)
|
42
|
+
after_update :deliver_email_changed_emails, if: :unconfirmed_email_changed?
|
43
|
+
end
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
@@ -58,8 +56,7 @@ module RailsJwtAuth
|
|
58
56
|
self.confirmation_sent_at = Time.current
|
59
57
|
return false unless save
|
60
58
|
|
61
|
-
|
62
|
-
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
59
|
+
RailsJwtAuth.send_email(:confirmation_instructions, self)
|
63
60
|
true
|
64
61
|
end
|
65
62
|
|
@@ -72,9 +69,15 @@ module RailsJwtAuth
|
|
72
69
|
self.confirmation_token = nil
|
73
70
|
|
74
71
|
if unconfirmed_email
|
75
|
-
|
76
|
-
|
72
|
+
email_field = RailsJwtAuth.email_field_name!
|
73
|
+
|
74
|
+
self[email_field] = unconfirmed_email
|
77
75
|
self.unconfirmed_email = nil
|
76
|
+
|
77
|
+
# supports email confirmation attr_accessor validation
|
78
|
+
if respond_to?("#{email_field}_confirmation")
|
79
|
+
instance_variable_set("@#{email_field}_confirmation", self[email_field])
|
80
|
+
end
|
78
81
|
end
|
79
82
|
|
80
83
|
save
|
@@ -89,6 +92,7 @@ module RailsJwtAuth
|
|
89
92
|
|
90
93
|
def validate_confirmation
|
91
94
|
return true unless confirmed_at
|
95
|
+
|
92
96
|
email_field = RailsJwtAuth.email_field_name!
|
93
97
|
|
94
98
|
if confirmed_at_was && !public_send("#{email_field}_changed?")
|
@@ -98,5 +102,15 @@ module RailsJwtAuth
|
|
98
102
|
errors.add(:confirmation_token, :expired)
|
99
103
|
end
|
100
104
|
end
|
105
|
+
|
106
|
+
def deliver_email_changed_emails
|
107
|
+
# send confirmation to new email
|
108
|
+
RailsJwtAuth.send_email(:confirmation_instructions, self)
|
109
|
+
|
110
|
+
# send notify to old email
|
111
|
+
if RailsJwtAuth.send_email_changed_notification
|
112
|
+
RailsJwtAuth.send_email(:email_changed, self)
|
113
|
+
end
|
114
|
+
end
|
101
115
|
end
|
102
116
|
end
|
@@ -112,9 +112,8 @@ module RailsJwtAuth
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def send_invitation_mail
|
115
|
-
RailsJwtAuth.email_field_name! # ensure email field
|
116
|
-
|
117
|
-
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
115
|
+
RailsJwtAuth.email_field_name! # ensure email field is valid
|
116
|
+
RailsJwtAuth.send_email(:send_invitation, self)
|
118
117
|
end
|
119
118
|
|
120
119
|
def invitation_period_valid?
|
@@ -68,8 +68,7 @@ module RailsJwtAuth
|
|
68
68
|
self.unlock_token = SecureRandom.base58(24)
|
69
69
|
save(validate: false)
|
70
70
|
|
71
|
-
|
72
|
-
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
71
|
+
RailsJwtAuth.send_email(:send_unlock_instructions, self)
|
73
72
|
end
|
74
73
|
|
75
74
|
def access_locked?
|
@@ -14,7 +14,10 @@ module RailsJwtAuth
|
|
14
14
|
validate :validate_reset_password_token, if: :password_digest_changed?
|
15
15
|
|
16
16
|
before_update do
|
17
|
-
|
17
|
+
if password_digest_changed? && reset_password_token
|
18
|
+
self.reset_password_token = nil
|
19
|
+
self.auth_tokens = []
|
20
|
+
end
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
@@ -37,8 +40,7 @@ module RailsJwtAuth
|
|
37
40
|
self.reset_password_sent_at = Time.current
|
38
41
|
return false unless save
|
39
42
|
|
40
|
-
|
41
|
-
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
43
|
+
RailsJwtAuth.send_email(:reset_password_instructions, self)
|
42
44
|
end
|
43
45
|
|
44
46
|
def set_and_send_password_instructions
|
@@ -53,8 +55,7 @@ module RailsJwtAuth
|
|
53
55
|
self.reset_password_sent_at = Time.current
|
54
56
|
return false unless save
|
55
57
|
|
56
|
-
|
57
|
-
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
58
|
+
RailsJwtAuth.send_email(:set_password_instructions, self)
|
58
59
|
true
|
59
60
|
end
|
60
61
|
|
data/lib/rails_jwt_auth.rb
CHANGED
@@ -114,4 +114,9 @@ module RailsJwtAuth
|
|
114
114
|
|
115
115
|
field_name
|
116
116
|
end
|
117
|
+
|
118
|
+
def self.send_email(method, user)
|
119
|
+
mailer = RailsJwtAuth::Mailer.with(user_id: user.id.to_s).public_send(method)
|
120
|
+
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
121
|
+
end
|
117
122
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_jwt_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rjurado
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt
|
@@ -120,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
|
-
|
124
|
-
rubygems_version: 2.7.3
|
123
|
+
rubygems_version: 3.0.3
|
125
124
|
signing_key:
|
126
125
|
specification_version: 4
|
127
126
|
summary: Rails jwt authentication.
|