rails_jwt_auth 0.21.0 → 0.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/controllers/rails_jwt_auth/confirmations_controller.rb +5 -5
- data/app/controllers/rails_jwt_auth/invitations_controller.rb +2 -2
- data/app/controllers/rails_jwt_auth/passwords_controller.rb +6 -10
- data/app/controllers/rails_jwt_auth/registrations_controller.rb +1 -1
- data/app/controllers/rails_jwt_auth/sessions_controller.rb +3 -7
- data/app/models/concerns/rails_jwt_auth/authenticatable.rb +3 -3
- data/app/models/concerns/rails_jwt_auth/confirmable.rb +3 -3
- data/app/models/concerns/rails_jwt_auth/invitable.rb +4 -7
- data/app/models/concerns/rails_jwt_auth/recoverable.rb +2 -2
- data/app/validators/email_validator.rb +1 -1
- data/config/locales/en.yml +0 -17
- data/lib/rails_jwt_auth/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f352112fd6b12718777361e279d9e4ff743cc60ff9fe631ea21379478dc3040
|
4
|
+
data.tar.gz: 94981bb16178f532ce0ef5c7ec5da60b3afd8c85483a884c3fae8ddb6303429c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26221283e2e5fa7191d37fc41470dc60ca3aee634a69de10d2b5844fe34ac9fc3329840f74ceac08209bc0bdd77ee5666cb15bb3dd0a79721a46e9446fff19db
|
7
|
+
data.tar.gz: fc03b5a3fb9642674de2f218fdbcc733c57ad5c7fa39dd77299129c14d4b7f2fc3e2040366fe3e15abee0fa67e15f57258b16ffd86849eea96e18f0da9219d60
|
data/README.md
CHANGED
@@ -539,7 +539,7 @@ class UsersController < ApplicationController
|
|
539
539
|
|
540
540
|
def create
|
541
541
|
user = User.new(create_params)
|
542
|
-
user.set_and_send_password_instructions ? render_204 : render_422(user.errors)
|
542
|
+
user.set_and_send_password_instructions ? render_204 : render_422(user.errors.details)
|
543
543
|
end
|
544
544
|
|
545
545
|
private
|
@@ -5,20 +5,20 @@ module RailsJwtAuth
|
|
5
5
|
|
6
6
|
def create
|
7
7
|
user = RailsJwtAuth.model.where(email: confirmation_create_params[:email]).first
|
8
|
-
return render_422(email: [
|
8
|
+
return render_422(email: [{error: :not_found}]) unless user
|
9
9
|
|
10
|
-
user.send_confirmation_instructions ? render_204 : render_422(user.errors)
|
10
|
+
user.send_confirmation_instructions ? render_204 : render_422(user.errors.details)
|
11
11
|
end
|
12
12
|
|
13
13
|
def update
|
14
14
|
if params[:confirmation_token].blank?
|
15
|
-
return render_422(confirmation_token: [
|
15
|
+
return render_422(confirmation_token: [{error: :not_found}])
|
16
16
|
end
|
17
17
|
|
18
18
|
user = RailsJwtAuth.model.where(confirmation_token: params[:confirmation_token]).first
|
19
|
-
return render_422(confirmation_token: [
|
19
|
+
return render_422(confirmation_token: [{error: :not_found}]) unless user
|
20
20
|
|
21
|
-
user.confirm! ? render_204 : render_422(user.errors)
|
21
|
+
user.confirm! ? render_204 : render_422(user.errors.details)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -6,7 +6,7 @@ module RailsJwtAuth
|
|
6
6
|
def create
|
7
7
|
attr_hash = invitation_create_params
|
8
8
|
user = RailsJwtAuth.model.invite!(attr_hash)
|
9
|
-
user.errors.empty? ? render_204 : render_422(user.errors)
|
9
|
+
user.errors.empty? ? render_204 : render_422(user.errors.details)
|
10
10
|
end
|
11
11
|
|
12
12
|
def update
|
@@ -17,7 +17,7 @@ module RailsJwtAuth
|
|
17
17
|
|
18
18
|
return render_204 if user.errors.empty? && user.save
|
19
19
|
|
20
|
-
render_422(user.errors)
|
20
|
+
render_422(user.errors.details)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -5,27 +5,23 @@ module RailsJwtAuth
|
|
5
5
|
|
6
6
|
def create
|
7
7
|
user = RailsJwtAuth.model.where(email: password_create_params[:email].to_s.downcase).first
|
8
|
-
return render_422(email: [
|
8
|
+
return render_422(email: [{error: :not_found}]) unless user
|
9
9
|
|
10
|
-
user.send_reset_password_instructions ? render_204 : render_422(user.errors)
|
10
|
+
user.send_reset_password_instructions ? render_204 : render_422(user.errors.details)
|
11
11
|
end
|
12
12
|
|
13
13
|
def update
|
14
14
|
if params[:reset_password_token].blank?
|
15
|
-
return render_422(reset_password_token: [
|
15
|
+
return render_422(reset_password_token: [{error: :not_found}])
|
16
16
|
end
|
17
17
|
|
18
18
|
user = RailsJwtAuth.model.where(reset_password_token: params[:reset_password_token]).first
|
19
19
|
|
20
|
-
unless user
|
21
|
-
return render_422(reset_password_token: [I18n.t('rails_jwt_auth.errors.not_found')])
|
22
|
-
end
|
20
|
+
return render_422(reset_password_token: [{error: :not_found}]) unless user
|
23
21
|
|
24
|
-
|
25
|
-
return render_422(password: [I18n.t('rails_jwt_auth.errors.password.blank')])
|
26
|
-
end
|
22
|
+
return render_422(password: [{error: :blank}]) if password_update_params[:password].blank?
|
27
23
|
|
28
|
-
user.
|
24
|
+
user.update(password_update_params) ? render_204 : render_422(user.errors.details)
|
29
25
|
end
|
30
26
|
end
|
31
27
|
end
|
@@ -11,13 +11,13 @@ module RailsJwtAuth
|
|
11
11
|
session_create_params[RailsJwtAuth.auth_field_name].to_s.downcase).first
|
12
12
|
|
13
13
|
if !user
|
14
|
-
render_422 session: [
|
14
|
+
render_422 session: [{error: :invalid_session}]
|
15
15
|
elsif user.respond_to?('confirmed?') && !user.confirmed?
|
16
|
-
render_422 session: [
|
16
|
+
render_422 session: [{error: :unconfirmed}]
|
17
17
|
elsif user.authenticate(session_create_params[:password])
|
18
18
|
render_session get_jwt(user), user
|
19
19
|
else
|
20
|
-
render_422 session: [
|
20
|
+
render_422 session: [{error: :invalid_session}]
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -32,9 +32,5 @@ module RailsJwtAuth
|
|
32
32
|
def get_jwt(user)
|
33
33
|
RailsJwtAuth::Jwt::Manager.encode(user.to_token_payload(request))
|
34
34
|
end
|
35
|
-
|
36
|
-
def create_session_error
|
37
|
-
I18n.t('rails_jwt_auth.errors.create_session', field: RailsJwtAuth.auth_field_name)
|
38
|
-
end
|
39
35
|
end
|
40
36
|
end
|
@@ -26,13 +26,13 @@ module RailsJwtAuth
|
|
26
26
|
|
27
27
|
def update_with_password(params)
|
28
28
|
if (current_password = params.delete(:current_password)).blank?
|
29
|
-
errors.add(:current_password,
|
29
|
+
errors.add(:current_password, 'blank')
|
30
30
|
elsif !authenticate(current_password)
|
31
|
-
errors.add(:current_password,
|
31
|
+
errors.add(:current_password, 'invalid')
|
32
32
|
end
|
33
33
|
|
34
34
|
if params[:password].blank?
|
35
|
-
errors.add(:password,
|
35
|
+
errors.add(:password, 'blank')
|
36
36
|
end
|
37
37
|
|
38
38
|
errors.empty? ? update_attributes(params) : false
|
@@ -2,7 +2,7 @@ module RailsJwtAuth
|
|
2
2
|
module Confirmable
|
3
3
|
def send_confirmation_instructions
|
4
4
|
if confirmed? && !unconfirmed_email
|
5
|
-
errors.add(:email,
|
5
|
+
errors.add(:email, :already_confirmed)
|
6
6
|
return false
|
7
7
|
end
|
8
8
|
|
@@ -80,10 +80,10 @@ module RailsJwtAuth
|
|
80
80
|
return true unless confirmed_at
|
81
81
|
|
82
82
|
if confirmed_at_was && !email_changed?
|
83
|
-
errors.add(:email,
|
83
|
+
errors.add(:email, :already_confirmed)
|
84
84
|
elsif confirmation_sent_at &&
|
85
85
|
(confirmation_sent_at < (Time.now - RailsJwtAuth.confirmation_expiration_time))
|
86
|
-
errors.add(:confirmation_token,
|
86
|
+
errors.add(:confirmation_token, :expired)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
@@ -5,7 +5,7 @@ module RailsJwtAuth
|
|
5
5
|
def self.included(base)
|
6
6
|
base.extend ClassMethods
|
7
7
|
base.class_eval do
|
8
|
-
if ancestors.include?
|
8
|
+
if defined?(Mongoid) && ancestors.include?(Mongoid::Document)
|
9
9
|
# include GlobalID::Identification to use deliver_later method
|
10
10
|
# http://edgeguides.rubyonrails.org/active_job_basics.html#globalid
|
11
11
|
include GlobalID::Identification if RailsJwtAuth.deliver_later
|
@@ -28,9 +28,7 @@ module RailsJwtAuth
|
|
28
28
|
# @param [Hash] attributes Hash containing user's attributes to be filled.
|
29
29
|
# Must contain an email key.
|
30
30
|
#
|
31
|
-
#
|
32
31
|
# @return [user] The user created or found by email.
|
33
|
-
|
34
32
|
def invite!(attributes={})
|
35
33
|
attrs = ActiveSupport::HashWithIndifferentAccess.new(attributes.to_h)
|
36
34
|
auth_field = RailsJwtAuth.auth_field_name
|
@@ -54,6 +52,7 @@ module RailsJwtAuth
|
|
54
52
|
|
55
53
|
def accept_invitation!
|
56
54
|
return unless invited?
|
55
|
+
|
57
56
|
if valid_invitation?
|
58
57
|
accept_invitation
|
59
58
|
self.confirmed_at = Time.now.utc if respond_to? :confirmed_at
|
@@ -62,7 +61,6 @@ module RailsJwtAuth
|
|
62
61
|
end
|
63
62
|
end
|
64
63
|
|
65
|
-
# rubocop:disable Metrics/AbcSize
|
66
64
|
def invite!
|
67
65
|
self.invitation_created_at = Time.now.utc if new_record?
|
68
66
|
|
@@ -74,12 +72,12 @@ module RailsJwtAuth
|
|
74
72
|
|
75
73
|
valid?
|
76
74
|
|
77
|
-
#
|
75
|
+
# users that are registered and were not invited are not reinvitable
|
78
76
|
if !new_record? && !invited?
|
79
77
|
errors.add(RailsJwtAuth.auth_field_name, :taken)
|
80
78
|
end
|
81
79
|
|
82
|
-
#
|
80
|
+
# users that have already accepted an invitation are not reinvitable
|
83
81
|
if !new_record? && invited? && invitation_accepted_at.present?
|
84
82
|
errors.add(RailsJwtAuth.auth_field_name, :taken)
|
85
83
|
end
|
@@ -92,7 +90,6 @@ module RailsJwtAuth
|
|
92
90
|
send_invitation_mail if save(validate: false)
|
93
91
|
self
|
94
92
|
end
|
95
|
-
# rubocop:enable Metrics/AbcSize
|
96
93
|
|
97
94
|
def invited?
|
98
95
|
(persisted? && invitation_token.present?)
|
@@ -2,7 +2,7 @@ module RailsJwtAuth
|
|
2
2
|
module Recoverable
|
3
3
|
def send_reset_password_instructions
|
4
4
|
if self.class.ancestors.include?(RailsJwtAuth::Confirmable) && !confirmed?
|
5
|
-
errors.add(:email,
|
5
|
+
errors.add(:email, :unconfirmed)
|
6
6
|
return false
|
7
7
|
end
|
8
8
|
|
@@ -56,7 +56,7 @@ module RailsJwtAuth
|
|
56
56
|
def validate_reset_password_token
|
57
57
|
if reset_password_sent_at &&
|
58
58
|
(reset_password_sent_at < (Time.now - RailsJwtAuth.reset_password_expiration_time))
|
59
|
-
errors.add(:reset_password_token,
|
59
|
+
errors.add(:reset_password_token, :expired)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class EmailValidator < ActiveModel::EachValidator
|
2
2
|
def validate_each(record, attribute, value)
|
3
3
|
unless value =~ RailsJwtAuth.email_regex
|
4
|
-
record.errors
|
4
|
+
record.errors.add(attribute, (options[:message] || 'invalid'))
|
5
5
|
end
|
6
6
|
end
|
7
7
|
end
|
data/config/locales/en.yml
CHANGED
@@ -9,20 +9,3 @@ en:
|
|
9
9
|
subject: "Set password instructions"
|
10
10
|
send_invitation:
|
11
11
|
subject: "Someone has sent you an invitation!"
|
12
|
-
|
13
|
-
errors:
|
14
|
-
unconfirmed: "unconfirmed email"
|
15
|
-
already_confirmed: "was already confirmed, please try signing in"
|
16
|
-
create_session: "invalid %{field} / password"
|
17
|
-
expired: "has expired, please request a new one"
|
18
|
-
invalid: "invalid"
|
19
|
-
blank: "blank"
|
20
|
-
not_found: "not found"
|
21
|
-
missing: "is missing"
|
22
|
-
email:
|
23
|
-
invalid: "is not an email"
|
24
|
-
current_password:
|
25
|
-
blank: "blank"
|
26
|
-
invalid: "invalid"
|
27
|
-
password:
|
28
|
-
blank: "blank"
|
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.
|
4
|
+
version: 0.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rjurado
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt
|