rails_jwt_auth 1.6.0 → 1.7.3
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/app/controllers/concerns/rails_jwt_auth/params_helper.rb +2 -2
- data/app/controllers/rails_jwt_auth/passwords_controller.rb +7 -3
- data/app/mailers/rails_jwt_auth/mailer.rb +17 -25
- 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 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe3b51e7a2d8f1f7f8debef824a18683878451b1623b824e4b87f7ca8eef3f97
|
4
|
+
data.tar.gz: 7f2df300a20ecd34567dc76a1c8f03bd0abe89416056d048374ee9c6d1f786b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2262fed0d629d5ce892c39e6b3285e510e5817802e38c17375cd16c20ee9f757cc96cb82a0b33e662a968386ffb3674c60e21a538693834251fc9c25f62630c9
|
7
|
+
data.tar.gz: '0228cbd71bc2cdf9e77a0c7ec9bd58593c9b9540eaef6e169e779fc7f0499668862e4b8e1b13de0d3e96a1f854ebcffd4d05bd6af9e17f93ad2c34877334a427'
|
@@ -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,13 +4,17 @@ module RailsJwtAuth
|
|
4
4
|
include RenderHelper
|
5
5
|
|
6
6
|
def create
|
7
|
-
|
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
|
8
12
|
|
9
13
|
user = RailsJwtAuth.model.where(
|
10
|
-
|
14
|
+
email_field => password_create_params[email_field].to_s.strip.downcase
|
11
15
|
).first
|
12
16
|
|
13
|
-
return render_422(
|
17
|
+
return render_422(email_field => [{error: :not_found}]) unless user
|
14
18
|
|
15
19
|
user.send_reset_password_instructions ? render_204 : render_422(user.errors.details)
|
16
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
|
@@ -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.3
|
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-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt
|
@@ -45,9 +45,6 @@ dependencies:
|
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '5.0'
|
48
|
-
- - "<"
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: '6.1'
|
51
48
|
type: :runtime
|
52
49
|
prerelease: false
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -55,9 +52,6 @@ dependencies:
|
|
55
52
|
- - ">="
|
56
53
|
- !ruby/object:Gem::Version
|
57
54
|
version: '5.0'
|
58
|
-
- - "<"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '6.1'
|
61
55
|
description: Rails-API authentication solution based on JWT and inspired by Devise.
|
62
56
|
email:
|
63
57
|
- rjurado@openmailbox.org
|
@@ -120,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
114
|
- !ruby/object:Gem::Version
|
121
115
|
version: '0'
|
122
116
|
requirements: []
|
123
|
-
rubygems_version: 3.
|
117
|
+
rubygems_version: 3.1.2
|
124
118
|
signing_key:
|
125
119
|
specification_version: 4
|
126
120
|
summary: Rails jwt authentication.
|