rails_jwt_auth 1.4.0 → 1.7.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 +4 -4
- data/README.md +45 -33
- 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 +11 -8
- 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/generators/rails_jwt_auth/install_generator.rb +2 -2
- data/lib/rails_jwt_auth.rb +5 -0
- data/lib/rails_jwt_auth/version.rb +1 -1
- metadata +4 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc1754797f099cba50a36044a69225fbeffee8e01120b9aa394209761d30eaf4
|
4
|
+
data.tar.gz: da443b714e8d7af7fb687a66e46fc6f3a46feb8837239debd1d16c76c34a49dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f72dd3b12df746bd2d95291090b5e5f4dce0c0cdcba429b4de5ac2290c811e55637790cbbbb93209bf8184ae9a827986b1000b3d8c9fb834f2151e9b610ba993
|
7
|
+
data.tar.gz: 68a3963c17ef09d9225550a79f3989572e5edb8b4c7023d40fca80b647c06c1cdd2848a0bbe76d0d11a339ffc88801d80f7f131ab829ddbb3ef60dabf6a2168a
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# RailsJwtAuth
|
2
2
|
|
3
|
-
|
3
|
+

|
4
4
|

|
5
5
|
|
6
6
|
Rails-API authentication solution based on JWT and inspired by Devise.
|
@@ -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,36 +253,26 @@ 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
|
}
|
242
261
|
```
|
243
262
|
|
244
|
-
2. Delete user:
|
245
|
-
|
246
|
-
```js
|
247
|
-
{
|
248
|
-
url: host/registration,
|
249
|
-
method: DELETE,
|
250
|
-
headers: { 'Authorization': 'Bearer auth_token'}
|
251
|
-
}
|
252
|
-
```
|
253
|
-
|
254
263
|
### Confirmation
|
255
264
|
|
256
265
|
Confirmation api is defined by `RailsJwtAuth::ConfirmationsController`.
|
257
266
|
|
267
|
+
It is necessary to set a value for `confirmations_url` option into `config/initializers/rails_jwt_auth.rb`.
|
268
|
+
|
258
269
|
1. Confirm user:
|
259
270
|
|
260
271
|
```js
|
261
272
|
{
|
262
|
-
url: host/
|
273
|
+
url: host/confirmations/:token,
|
263
274
|
method: PUT
|
264
|
-
data: {
|
265
|
-
confirmation_token: "token"
|
266
|
-
}
|
275
|
+
data: {}
|
267
276
|
}
|
268
277
|
```
|
269
278
|
|
@@ -271,11 +280,11 @@ Confirmation api is defined by `RailsJwtAuth::ConfirmationsController`.
|
|
271
280
|
|
272
281
|
```js
|
273
282
|
{
|
274
|
-
url: host/
|
283
|
+
url: host/confirmations,
|
275
284
|
method: POST,
|
276
285
|
data: {
|
277
286
|
confirmation: {
|
278
|
-
email:
|
287
|
+
email: 'user@example.com'
|
279
288
|
}
|
280
289
|
}
|
281
290
|
}
|
@@ -289,11 +298,11 @@ Password api is defined by `RailsJwtAuth::PasswordsController`.
|
|
289
298
|
|
290
299
|
```js
|
291
300
|
{
|
292
|
-
url: host/
|
301
|
+
url: host/passwords,
|
293
302
|
method: POST,
|
294
303
|
data: {
|
295
304
|
password: {
|
296
|
-
email:
|
305
|
+
email: 'user@example.com'
|
297
306
|
}
|
298
307
|
}
|
299
308
|
}
|
@@ -303,10 +312,9 @@ Password api is defined by `RailsJwtAuth::PasswordsController`.
|
|
303
312
|
|
304
313
|
```js
|
305
314
|
{
|
306
|
-
url: host/
|
315
|
+
url: host/passwords/:token,
|
307
316
|
method: PUT,
|
308
317
|
data: {
|
309
|
-
reset_password_token: "token",
|
310
318
|
password: {
|
311
319
|
password: '1234',
|
312
320
|
password_confirmation: '1234'
|
@@ -327,7 +335,7 @@ Invitations api is provided by `RailsJwtAuth::InvitationsController`.
|
|
327
335
|
method: POST,
|
328
336
|
data: {
|
329
337
|
invitation: {
|
330
|
-
email:
|
338
|
+
email: 'user@example.com',
|
331
339
|
// More fields of your user
|
332
340
|
}
|
333
341
|
}
|
@@ -360,7 +368,8 @@ Unlock api is provided by `RailsJwtAuth::UnlocksController`.
|
|
360
368
|
```js
|
361
369
|
{
|
362
370
|
url: host/unlocks/:unlock_token,
|
363
|
-
method: PUT
|
371
|
+
method: PUT,
|
372
|
+
data: {}
|
364
373
|
}
|
365
374
|
```
|
366
375
|
|
@@ -436,7 +445,10 @@ class CurrentUserController < ApplicationController
|
|
436
445
|
|
437
446
|
def update
|
438
447
|
if update_params[:password]
|
439
|
-
|
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
|
+
)
|
440
452
|
else
|
441
453
|
current_user.update_attributes(update_params)
|
442
454
|
end
|
@@ -481,7 +493,7 @@ require 'rails_jwt_auth/spec_helpers'
|
|
481
493
|
...
|
482
494
|
RSpec.configure do |config|
|
483
495
|
...
|
484
|
-
config.include RailsJwtAuth::SpecHelpers, :
|
496
|
+
config.include RailsJwtAuth::SpecHelpers, type: :controller
|
485
497
|
end
|
486
498
|
```
|
487
499
|
|
@@ -489,11 +501,11 @@ And then we can just call sign_in(user) to sign in as a user:
|
|
489
501
|
|
490
502
|
```ruby
|
491
503
|
describe ExampleController
|
492
|
-
it
|
493
|
-
expect { get :index }.to raise_error(RailsJwtAuth::
|
504
|
+
it 'blocks unauthenticated access' do
|
505
|
+
expect { get :index }.to raise_error(RailsJwtAuth::NotAuthorized)
|
494
506
|
end
|
495
507
|
|
496
|
-
it
|
508
|
+
it 'allows authenticated access' do
|
497
509
|
sign_in user
|
498
510
|
get :index
|
499
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
|
@@ -34,12 +34,10 @@ module RailsJwtAuth
|
|
34
34
|
self.confirmation_token = SecureRandom.base58(24)
|
35
35
|
self.confirmation_sent_at = Time.current
|
36
36
|
|
37
|
-
|
38
|
-
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
37
|
+
RailsJwtAuth.send_email(:confirmation_instructions, self)
|
39
38
|
|
40
39
|
if RailsJwtAuth.send_email_changed_notification
|
41
|
-
|
42
|
-
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
40
|
+
RailsJwtAuth.send_email(:email_changed, self)
|
43
41
|
end
|
44
42
|
end
|
45
43
|
end
|
@@ -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
|
+
self.instance_variable_set("@#{email_field}_confirmation", self[email_field])
|
80
|
+
end
|
78
81
|
end
|
79
82
|
|
80
83
|
save
|
@@ -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
|
|
@@ -6,8 +6,8 @@ class RailsJwtAuth::InstallGenerator < Rails::Generators::Base
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def create_routes
|
9
|
-
route "
|
10
|
-
route "
|
9
|
+
route "resource :session, controller: 'rails_jwt_auth/sessions', only: [:create, :destroy]"
|
10
|
+
route "resource :registration, controller: 'rails_jwt_auth/registrations', only: [:create]"
|
11
11
|
|
12
12
|
route "resources :confirmations, controller: 'rails_jwt_auth/confirmations', only: [:create, :update]"
|
13
13
|
route "resources :passwords, controller: 'rails_jwt_auth/passwords', only: [:create, :update]"
|
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.0
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt
|
@@ -58,8 +58,7 @@ dependencies:
|
|
58
58
|
- - "<"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '6.1'
|
61
|
-
description: Rails authentication solution based on
|
62
|
-
Devise.
|
61
|
+
description: Rails-API authentication solution based on JWT and inspired by Devise.
|
63
62
|
email:
|
64
63
|
- rjurado@openmailbox.org
|
65
64
|
executables: []
|
@@ -121,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
120
|
- !ruby/object:Gem::Version
|
122
121
|
version: '0'
|
123
122
|
requirements: []
|
124
|
-
|
125
|
-
rubygems_version: 2.7.3
|
123
|
+
rubygems_version: 3.0.3
|
126
124
|
signing_key:
|
127
125
|
specification_version: 4
|
128
126
|
summary: Rails jwt authentication.
|