rails_jwt_auth 0.18.0 → 0.18.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/rails_jwt_auth/params_helper.rb +3 -1
- data/app/controllers/rails_jwt_auth/invitations_controller.rb +3 -6
- data/app/models/concerns/rails_jwt_auth/authenticatable.rb +1 -1
- data/app/models/concerns/rails_jwt_auth/confirmable.rb +5 -2
- data/app/models/concerns/rails_jwt_auth/invitable.rb +21 -10
- data/lib/rails_jwt_auth/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f935bf415eb61e8c8d04a0ee5701e35225a1f68
|
4
|
+
data.tar.gz: 5f97e07f1f1ff4de288872d717f6b632a6132417
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a8976264bfcf1fae83bf32d8c3f2930141b162614a0af7b9782ca90725ba4af8173508eb7c1fa7c8094624e0f477faad6337ca6a2e99376bbc84c7be5b75594
|
7
|
+
data.tar.gz: 297a00da37aff4ece4ba9580e0e2d59bd1351f9dfe234373e00ac8de9f917094b814de50ca501305465eaf1551158a0129102d59fd25f62ef80e72c87721d59f
|
@@ -29,7 +29,9 @@ module RailsJwtAuth
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def invitation_update_params
|
32
|
-
params.require(:accept_invitation).permit(:invitation_token,
|
32
|
+
params.require(:accept_invitation).permit(:invitation_token,
|
33
|
+
:password,
|
34
|
+
:password_confirmation)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -16,12 +16,9 @@ module RailsJwtAuth
|
|
16
16
|
user.assign_attributes attr_hash
|
17
17
|
user.accept_invitation!
|
18
18
|
|
19
|
-
if user.errors.empty? && user.save
|
20
|
-
|
21
|
-
|
22
|
-
user.update_attribute :invitation_token, token
|
23
|
-
return render_422(user.errors)
|
24
|
-
end
|
19
|
+
return render_204 if user.errors.empty? && user.save
|
20
|
+
|
21
|
+
render_422(user.errors)
|
25
22
|
end
|
26
23
|
end
|
27
24
|
end
|
@@ -51,7 +51,7 @@ module RailsJwtAuth
|
|
51
51
|
def self.included(base)
|
52
52
|
base.extend(ClassMethods)
|
53
53
|
|
54
|
-
base.class_eval do
|
54
|
+
base.class_eval do
|
55
55
|
if defined?(Mongoid) && ancestors.include?(Mongoid::Document)
|
56
56
|
field RailsJwtAuth.auth_field_name, type: String
|
57
57
|
field :password_digest, type: String
|
@@ -25,6 +25,7 @@ module RailsJwtAuth
|
|
25
25
|
|
26
26
|
if unconfirmed_email
|
27
27
|
self.email = unconfirmed_email
|
28
|
+
self.email_confirmation = unconfirmed_email if respond_to?(:email_confirmation)
|
28
29
|
self.unconfirmed_email = nil
|
29
30
|
end
|
30
31
|
|
@@ -53,11 +54,13 @@ module RailsJwtAuth
|
|
53
54
|
validate :validate_confirmation, if: :confirmed_at_changed?
|
54
55
|
|
55
56
|
after_create do
|
56
|
-
|
57
|
+
unless confirmed_at || confirmation_sent_at || self['invitation_token']
|
58
|
+
send_confirmation_instructions
|
59
|
+
end
|
57
60
|
end
|
58
61
|
|
59
62
|
before_update do
|
60
|
-
if email_changed? && email_was && !confirmed_at_changed?
|
63
|
+
if email_changed? && email_was && !confirmed_at_changed? && !self['invitation_token']
|
61
64
|
self.unconfirmed_email = email
|
62
65
|
self.email = email_was
|
63
66
|
|
@@ -33,6 +33,7 @@ module RailsJwtAuth
|
|
33
33
|
#
|
34
34
|
# @return [user] The user created or found by email.
|
35
35
|
|
36
|
+
# rubocop:disable Metrics/AbcSize
|
36
37
|
def invite!(attributes={})
|
37
38
|
attrs = ActiveSupport::HashWithIndifferentAccess.new(attributes.to_h)
|
38
39
|
auth_field = RailsJwtAuth.auth_field_name
|
@@ -52,13 +53,20 @@ module RailsJwtAuth
|
|
52
53
|
|
53
54
|
record.valid?
|
54
55
|
|
56
|
+
# Users that are registered and were not invited are not reinvitable
|
55
57
|
if !record.new_record? && !record.invited?
|
56
58
|
record.errors.add(RailsJwtAuth.auth_field_name, :taken)
|
57
59
|
end
|
58
60
|
|
61
|
+
# Users that have already accepted an invitation are not reinvitable
|
62
|
+
if !record.new_record? && record.invited? && record.invitation_accepted_at.present?
|
63
|
+
record.errors.add(RailsJwtAuth.auth_field_name, :taken)
|
64
|
+
end
|
65
|
+
|
59
66
|
record.invite! if record.errors.empty?
|
60
67
|
record
|
61
68
|
end
|
69
|
+
# rubocop:enable Metrics/AbcSize
|
62
70
|
end
|
63
71
|
|
64
72
|
# Accept an invitation by clearing token and setting invitation_accepted_at
|
@@ -71,8 +79,7 @@ module RailsJwtAuth
|
|
71
79
|
return unless invited?
|
72
80
|
if valid_invitation?
|
73
81
|
accept_invitation
|
74
|
-
|
75
|
-
self.confirmed_at = invitation_accepted_at if respond_to? :confirmed_at
|
82
|
+
self.confirmed_at = Time.now.utc if respond_to? :confirmed_at
|
76
83
|
else
|
77
84
|
errors.add(:invitation_token, :invalid)
|
78
85
|
end
|
@@ -80,28 +87,32 @@ module RailsJwtAuth
|
|
80
87
|
|
81
88
|
def invite!
|
82
89
|
generate_invitation_token if invitation_token.nil?
|
83
|
-
self.
|
90
|
+
self.invitation_sent_at = Time.now.utc
|
84
91
|
|
85
|
-
|
92
|
+
send_invitation_mail if save(validate: false)
|
86
93
|
end
|
87
94
|
|
88
95
|
def invited?
|
89
96
|
(persisted? && invitation_token.present?)
|
90
97
|
end
|
91
98
|
|
92
|
-
|
99
|
+
def generate_invitation_token!
|
100
|
+
generate_invitation_token && save(validate: false)
|
101
|
+
end
|
93
102
|
|
94
|
-
def
|
95
|
-
|
96
|
-
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
103
|
+
def valid_invitation?
|
104
|
+
invited? && invitation_period_valid?
|
97
105
|
end
|
98
106
|
|
107
|
+
protected
|
108
|
+
|
99
109
|
def generate_invitation_token
|
100
110
|
self.invitation_token = SecureRandom.base58(128)
|
101
111
|
end
|
102
112
|
|
103
|
-
def
|
104
|
-
|
113
|
+
def send_invitation_mail
|
114
|
+
mailer = Mailer.send_invitation(self)
|
115
|
+
RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
|
105
116
|
end
|
106
117
|
|
107
118
|
def invitation_period_valid?
|
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: 0.18.
|
4
|
+
version: 0.18.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rjurado
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|