rails_jwt_auth 1.5.0 → 1.7.2
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 +22 -9
- 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 +32 -10
- 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 +2 -4
- 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: 6c5dc21f39ff43ad410a4bc4060a5a027ec011f0a632f4b03244ce99852a88ee
|
4
|
+
data.tar.gz: abd710caa09455b2471b7138b59b33c92707c1d396bd78ca8fd8713def4ad5dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b3165148a4d567a440e1f7d157e4a24d2d4ea027e6629a6c3ab4c1b02a8dfdbf1a3434e3fcfa31eaf27f2a0a97c3cf5c430c323a48f9ad48787491f4b195bbb
|
7
|
+
data.tar.gz: 5fbf634a2de1544f1b63871f36b86e3413b6a3d1382c89f415a0a3af7ef2c51dfa0370892ab3f76f57dc646250a7c5b840fdf1137cfcdd6e2973eaa006344d26
|
data/README.md
CHANGED
@@ -197,6 +197,21 @@ end
|
|
197
197
|
|
198
198
|
## Default Controllers API
|
199
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
|
+
|
200
215
|
### Session
|
201
216
|
|
202
217
|
Session api is defined by `RailsJwtAuth::SessionsController`.
|
@@ -255,11 +270,9 @@ It is necessary to set a value for `confirmations_url` option into `config/initi
|
|
255
270
|
|
256
271
|
```js
|
257
272
|
{
|
258
|
-
url: host/
|
273
|
+
url: host/confirmations/:token,
|
259
274
|
method: PUT
|
260
|
-
data: {
|
261
|
-
confirmation_token: 'token'
|
262
|
-
}
|
275
|
+
data: {}
|
263
276
|
}
|
264
277
|
```
|
265
278
|
|
@@ -267,7 +280,7 @@ It is necessary to set a value for `confirmations_url` option into `config/initi
|
|
267
280
|
|
268
281
|
```js
|
269
282
|
{
|
270
|
-
url: host/
|
283
|
+
url: host/confirmations,
|
271
284
|
method: POST,
|
272
285
|
data: {
|
273
286
|
confirmation: {
|
@@ -285,7 +298,7 @@ Password api is defined by `RailsJwtAuth::PasswordsController`.
|
|
285
298
|
|
286
299
|
```js
|
287
300
|
{
|
288
|
-
url: host/
|
301
|
+
url: host/passwords,
|
289
302
|
method: POST,
|
290
303
|
data: {
|
291
304
|
password: {
|
@@ -299,10 +312,9 @@ Password api is defined by `RailsJwtAuth::PasswordsController`.
|
|
299
312
|
|
300
313
|
```js
|
301
314
|
{
|
302
|
-
url: host/
|
315
|
+
url: host/passwords/:token,
|
303
316
|
method: PUT,
|
304
317
|
data: {
|
305
|
-
reset_password_token: 'token',
|
306
318
|
password: {
|
307
319
|
password: '1234',
|
308
320
|
password_confirmation: '1234'
|
@@ -356,7 +368,8 @@ Unlock api is provided by `RailsJwtAuth::UnlocksController`.
|
|
356
368
|
```js
|
357
369
|
{
|
358
370
|
url: host/unlocks/:unlock_token,
|
359
|
-
method: PUT
|
371
|
+
method: PUT,
|
372
|
+
data: {}
|
360
373
|
}
|
361
374
|
```
|
362
375
|
|
@@ -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,13 +33,19 @@ module RailsJwtAuth
|
|
33
33
|
|
34
34
|
self.confirmation_token = SecureRandom.base58(24)
|
35
35
|
self.confirmation_sent_at = Time.current
|
36
|
+
end
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
if defined?(ActiveRecord) && ancestors.include?(ActiveRecord::Base)
|
40
|
+
after_commit do
|
41
|
+
if unconfirmed_email && saved_change_to_unconfirmed_email?
|
42
|
+
deliver_email_changed_emails
|
43
|
+
end
|
44
|
+
end
|
45
|
+
elsif defined?(Mongoid) && ancestors.include?(Mongoid::Document)
|
46
|
+
after_update do
|
47
|
+
if unconfirmed_email && unconfirmed_email_changed?
|
48
|
+
deliver_email_changed_emails
|
43
49
|
end
|
44
50
|
end
|
45
51
|
end
|
@@ -58,8 +64,7 @@ module RailsJwtAuth
|
|
58
64
|
self.confirmation_sent_at = Time.current
|
59
65
|
return false unless save
|
60
66
|
|
61
|
-
|
62
|
-
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
67
|
+
RailsJwtAuth.send_email(:confirmation_instructions, self)
|
63
68
|
true
|
64
69
|
end
|
65
70
|
|
@@ -72,9 +77,15 @@ module RailsJwtAuth
|
|
72
77
|
self.confirmation_token = nil
|
73
78
|
|
74
79
|
if unconfirmed_email
|
75
|
-
|
76
|
-
|
80
|
+
email_field = RailsJwtAuth.email_field_name!
|
81
|
+
|
82
|
+
self[email_field] = unconfirmed_email
|
77
83
|
self.unconfirmed_email = nil
|
84
|
+
|
85
|
+
# supports email confirmation attr_accessor validation
|
86
|
+
if respond_to?("#{email_field}_confirmation")
|
87
|
+
instance_variable_set("@#{email_field}_confirmation", self[email_field])
|
88
|
+
end
|
78
89
|
end
|
79
90
|
|
80
91
|
save
|
@@ -89,6 +100,7 @@ module RailsJwtAuth
|
|
89
100
|
|
90
101
|
def validate_confirmation
|
91
102
|
return true unless confirmed_at
|
103
|
+
|
92
104
|
email_field = RailsJwtAuth.email_field_name!
|
93
105
|
|
94
106
|
if confirmed_at_was && !public_send("#{email_field}_changed?")
|
@@ -98,5 +110,15 @@ module RailsJwtAuth
|
|
98
110
|
errors.add(:confirmation_token, :expired)
|
99
111
|
end
|
100
112
|
end
|
113
|
+
|
114
|
+
def deliver_email_changed_emails
|
115
|
+
# send confirmation to new email
|
116
|
+
RailsJwtAuth.send_email(:confirmation_instructions, self)
|
117
|
+
|
118
|
+
# send notify to old email
|
119
|
+
if RailsJwtAuth.send_email_changed_notification
|
120
|
+
RailsJwtAuth.send_email(:email_changed, self)
|
121
|
+
end
|
122
|
+
end
|
101
123
|
end
|
102
124
|
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?
|
@@ -40,8 +40,7 @@ module RailsJwtAuth
|
|
40
40
|
self.reset_password_sent_at = Time.current
|
41
41
|
return false unless save
|
42
42
|
|
43
|
-
|
44
|
-
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
43
|
+
RailsJwtAuth.send_email(:reset_password_instructions, self)
|
45
44
|
end
|
46
45
|
|
47
46
|
def set_and_send_password_instructions
|
@@ -56,8 +55,7 @@ module RailsJwtAuth
|
|
56
55
|
self.reset_password_sent_at = Time.current
|
57
56
|
return false unless save
|
58
57
|
|
59
|
-
|
60
|
-
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
58
|
+
RailsJwtAuth.send_email(:set_password_instructions, self)
|
61
59
|
true
|
62
60
|
end
|
63
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rjurado
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-24 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.
|