rails_jwt_auth 0.18.1 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3f935bf415eb61e8c8d04a0ee5701e35225a1f68
4
- data.tar.gz: 5f97e07f1f1ff4de288872d717f6b632a6132417
2
+ SHA256:
3
+ metadata.gz: 762f53596609290e2f1ac7d6091796fd55167d96e5bb77ba7566336b5fea3dd4
4
+ data.tar.gz: caa5365c0300a1adf1b9ec6e3f0ac9354487171ef9c7813717439d126a39bed5
5
5
  SHA512:
6
- metadata.gz: 0a8976264bfcf1fae83bf32d8c3f2930141b162614a0af7b9782ca90725ba4af8173508eb7c1fa7c8094624e0f477faad6337ca6a2e99376bbc84c7be5b75594
7
- data.tar.gz: 297a00da37aff4ece4ba9580e0e2d59bd1351f9dfe234373e00ac8de9f917094b814de50ca501305465eaf1551158a0129102d59fd25f62ef80e72c87721d59f
6
+ metadata.gz: dd76e94ecc84e8cb1f0ff57754fec3eb21202ed0560b3b1d3d16488d982510169d8f37e4b66348b78386a0d70fd2f098c99ca6d02aa9e3da359ef8b15ec77c7a
7
+ data.tar.gz: 846793af29ba968cc33e81762b93e28030efc48045086b5a661c603fcdfa25577f4c84e7675237951b215e9df1f87fe61ade6e776c893c1f03feaa33366ade50
data/README.md CHANGED
@@ -51,7 +51,7 @@ You can edit configuration options into `config/initializers/auth_token_auth.rb`
51
51
  | set_password_url | password_path | Url used to create email link with set password token |
52
52
  | deliver_later | false | Uses `deliver_later` method to send emails |
53
53
  | invitation_expiration_time | 2.days | Time an invitation is valid and can be accepted |
54
- | invitation_url | invitation_path | URL used to create email link with invitation token |
54
+ | accept_invitation_url | invitations_path | URL used to create email link with invitation token |
55
55
 
56
56
  ## Authenticatable
57
57
 
@@ -118,7 +118,7 @@ change_table :users do |t|
118
118
  t.string :unconfirmed_email
119
119
  t.string :confirmation_token
120
120
  t.datetime :confirmation_sent_at
121
- t.datetime :confimed_at
121
+ t.datetime :confirmed_at
122
122
  end
123
123
  ```
124
124
 
@@ -420,7 +420,7 @@ Invitations api is provided by RailsJwtAuth::InvitationsController.
420
420
 
421
421
  ```js
422
422
  {
423
- url: host/invitation,
423
+ url: host/invitations,
424
424
  method: POST,
425
425
  data: {
426
426
  invitation: {
@@ -435,14 +435,12 @@ Invitations api is provided by RailsJwtAuth::InvitationsController.
435
435
 
436
436
  ```js
437
437
  {
438
- url: host/invitation,
438
+ url: host/invitations/:invitation_token,
439
439
  method: PUT,
440
440
  data: {
441
- accept_invitation: {
442
- invitation_token: "token",
441
+ invitation: {
443
442
  password: '1234',
444
- password_confirmation: '1234',
445
- // More fields of your user...
443
+ password_confirmation: '1234'
446
444
  }
447
445
  }
448
446
  }
@@ -29,9 +29,7 @@ module RailsJwtAuth
29
29
  end
30
30
 
31
31
  def invitation_update_params
32
- params.require(:accept_invitation).permit(:invitation_token,
33
- :password,
34
- :password_confirmation)
32
+ params.require(:invitation).permit(:password, :password_confirmation)
35
33
  end
36
34
  end
37
35
  end
@@ -11,8 +11,7 @@ module RailsJwtAuth
11
11
 
12
12
  def update
13
13
  attr_hash = invitation_update_params
14
- token = attr_hash.delete(:invitation_token)
15
- user = RailsJwtAuth.model.where(invitation_token: token).first
14
+ user = RailsJwtAuth.model.where(invitation_token: params[:id]).first
16
15
  user.assign_attributes attr_hash
17
16
  user.accept_invitation!
18
17
 
@@ -56,13 +56,13 @@ if defined?(ActionMailer)
56
56
  def send_invitation(user)
57
57
  @user = user
58
58
 
59
- if RailsJwtAuth.invitation_url
60
- url, params = RailsJwtAuth.invitation_url.split '?'
59
+ if RailsJwtAuth.accept_invitation_url
60
+ url, params = RailsJwtAuth.accept_invitation_url.split '?'
61
61
  params = params ? params.split('&') : []
62
62
  params.push("invitation_token=#{@user.invitation_token}")
63
63
  @accept_invitation_url = "#{url}?#{params.join('&')}"
64
64
  else
65
- @accept_invitation_url = invitation_url(invitation_token: @user.invitation_token)
65
+ @accept_invitation_url = invitations_url(invitation_token: @user.invitation_token)
66
66
  end
67
67
 
68
68
  subject = I18n.t('rails_jwt_auth.mailer.send_invitation.subject')
@@ -14,8 +14,6 @@ module RailsJwtAuth
14
14
  field :invitation_sent_at, type: Time
15
15
  field :invitation_accepted_at, type: Time
16
16
  field :invitation_created_at, type: Time
17
-
18
- index({invitation_token: 1}, {unique: true})
19
17
  end
20
18
  end
21
19
  end
@@ -33,7 +31,6 @@ module RailsJwtAuth
33
31
  #
34
32
  # @return [user] The user created or found by email.
35
33
 
36
- # rubocop:disable Metrics/AbcSize
37
34
  def invite!(attributes={})
38
35
  attrs = ActiveSupport::HashWithIndifferentAccess.new(attributes.to_h)
39
36
  auth_field = RailsJwtAuth.auth_field_name
@@ -43,30 +40,10 @@ module RailsJwtAuth
43
40
 
44
41
  record = RailsJwtAuth.model.find_or_initialize_by(auth_field => auth_attribute)
45
42
  record.assign_attributes(attrs)
46
- record.invitation_created_at = Time.now.utc if record.new_record?
47
-
48
- unless record.password || record.password_digest
49
- password = SecureRandom.base58(16)
50
- record.password = password
51
- record.password_confirmation = password
52
- end
53
-
54
- record.valid?
55
-
56
- # Users that are registered and were not invited are not reinvitable
57
- if !record.new_record? && !record.invited?
58
- record.errors.add(RailsJwtAuth.auth_field_name, :taken)
59
- end
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
43
 
66
- record.invite! if record.errors.empty?
44
+ record.invite!
67
45
  record
68
46
  end
69
- # rubocop:enable Metrics/AbcSize
70
47
  end
71
48
 
72
49
  # Accept an invitation by clearing token and setting invitation_accepted_at
@@ -85,12 +62,37 @@ module RailsJwtAuth
85
62
  end
86
63
  end
87
64
 
65
+ # rubocop:disable Metrics/AbcSize
88
66
  def invite!
67
+ self.invitation_created_at = Time.now.utc if new_record?
68
+
69
+ unless password || password_digest
70
+ passw = SecureRandom.base58(16)
71
+ self.password = passw
72
+ self.password_confirmation = passw
73
+ end
74
+
75
+ valid?
76
+
77
+ # Users that are registered and were not invited are not reinvitable
78
+ if !new_record? && !invited?
79
+ errors.add(RailsJwtAuth.auth_field_name, :taken)
80
+ end
81
+
82
+ # Users that have already accepted an invitation are not reinvitable
83
+ if !new_record? && invited? && invitation_accepted_at.present?
84
+ errors.add(RailsJwtAuth.auth_field_name, :taken)
85
+ end
86
+
87
+ return self unless errors.empty?
88
+
89
89
  generate_invitation_token if invitation_token.nil?
90
90
  self.invitation_sent_at = Time.now.utc
91
91
 
92
92
  send_invitation_mail if save(validate: false)
93
+ self
93
94
  end
95
+ # rubocop:enable Metrics/AbcSize
94
96
 
95
97
  def invited?
96
98
  (persisted? && invitation_token.present?)
@@ -104,6 +106,10 @@ module RailsJwtAuth
104
106
  invited? && invitation_period_valid?
105
107
  end
106
108
 
109
+ def accepted_invitation?
110
+ invitation_token.nil? && invitation_accepted_at.present?
111
+ end
112
+
107
113
  protected
108
114
 
109
115
  def generate_invitation_token
@@ -2,7 +2,7 @@ class RailsJwtAuth::InstallGenerator < Rails::Generators::Base
2
2
  source_root File.expand_path('../../templates', __FILE__)
3
3
 
4
4
  def create_initializer_file
5
- copy_file "initializer.rb", "config/initializers/rails_jwt_auth.rb"
5
+ copy_file 'initializer.rb', 'config/initializers/rails_jwt_auth.rb'
6
6
  end
7
7
 
8
8
  def create_routes
@@ -12,6 +12,6 @@ class RailsJwtAuth::InstallGenerator < Rails::Generators::Base
12
12
  route "resource :confirmation, controller: 'rails_jwt_auth/confirmations', only: [:create, :update]"
13
13
  route "resource :password, controller: 'rails_jwt_auth/passwords', only: [:create, :update]"
14
14
 
15
- route "resource :invitation, controller: 'rails_jwt_auth/invitations', only: [:create, :update]"
15
+ route "resource :invitations, controller: 'rails_jwt_auth/invitations', only: [:create, :update]"
16
16
  end
17
17
  end
@@ -18,7 +18,7 @@ RailsJwtAuth.setup do |config|
18
18
  #config.jwt_issuer = 'RailsJwtAuth'
19
19
 
20
20
  # number of simultaneously sessions for an user
21
- #config.simultaneously_sessions = 2
21
+ #config.simultaneous_sessions = 2
22
22
 
23
23
  # mailer sender
24
24
  #config.mailer_sender = 'initialize-mailer_sender@example.com'
@@ -33,6 +33,7 @@ RailsJwtAuth.setup do |config|
33
33
  #config.reset_password_url = 'http://frontend.com/reset_password'
34
34
 
35
35
  # url used to create email link with set password token
36
+ # by set_and_send_password_instructions method
36
37
  #config.set_password_url = 'http://frontend.com/set_password'
37
38
 
38
39
  # expiration time for reset password tokens
@@ -41,11 +42,9 @@ RailsJwtAuth.setup do |config|
41
42
  # uses deliver_later to send emails instead of deliver method
42
43
  #config.deliver_later = false
43
44
 
44
- # Invitable configuration
45
- #
46
- # Time an invitation is valid after sent
45
+ # time an invitation is valid after sent
47
46
  # config.invitation_expiration_time = 2.days
48
- #
49
- # URL used to create email link to activate invitation
47
+
48
+ # url used to create email link with activation token parameter to accept invitation
50
49
  # config.accept_invitation_url = 'http://frontend.com/accept_invitation'
51
50
  end
@@ -1,59 +1,59 @@
1
- require "warden"
2
- require "bcrypt"
1
+ require 'warden'
2
+ require 'bcrypt'
3
3
 
4
- require "rails_jwt_auth/engine"
4
+ require 'rails_jwt_auth/engine'
5
5
 
6
6
  module RailsJwtAuth
7
7
  mattr_accessor :model_name
8
- @@model_name = 'User'
8
+ self.model_name = 'User'
9
9
 
10
10
  mattr_accessor :auth_field_name
11
- @@auth_field_name = 'email'
11
+ self.auth_field_name = 'email'
12
12
 
13
13
  mattr_accessor :auth_field_email
14
- @@auth_field_email = true
14
+ self.auth_field_email = true
15
15
 
16
16
  mattr_accessor :email_regex
17
- @@email_regex = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
17
+ self.email_regex = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
18
18
 
19
19
  mattr_accessor :jwt_expiration_time
20
- @@jwt_expiration_time = 7.days
20
+ self.jwt_expiration_time = 7.days
21
21
 
22
22
  mattr_accessor :jwt_issuer
23
- @@jwt_issuer = 'RailsJwtAuth'
23
+ self.jwt_issuer = 'RailsJwtAuth'
24
24
 
25
25
  mattr_accessor :simultaneous_sessions
26
- @@simultaneous_sessions = 2
26
+ self.simultaneous_sessions = 2
27
27
 
28
28
  mattr_accessor :mailer_sender
29
- @@mailer_sender = 'initialize-mailer_sender@example.com'
29
+ self.mailer_sender = 'initialize-mailer_sender@example.com'
30
30
 
31
31
  mattr_accessor :confirmation_url
32
- @@confirmation_url = nil
32
+ self.confirmation_url = nil
33
33
 
34
34
  mattr_accessor :confirmation_expiration_time
35
- @@confirmation_expiration_time = 1.day
35
+ self.confirmation_expiration_time = 1.day
36
36
 
37
37
  mattr_accessor :reset_password_url
38
- @@reset_password_url = nil
38
+ self.reset_password_url = nil
39
39
 
40
40
  mattr_accessor :set_password_url
41
- @@set_password_url = nil
41
+ self.set_password_url = nil
42
42
 
43
43
  mattr_accessor :reset_password_expiration_time
44
- @@reset_password_expiration_time = 1.day
44
+ self.reset_password_expiration_time = 1.day
45
45
 
46
46
  mattr_accessor :deliver_later
47
- @@deliver_later = false
47
+ self.deliver_later = false
48
48
 
49
49
  mattr_accessor :invitation_expiration_time
50
- @@invitation_expiration_time = 2.days
50
+ self.invitation_expiration_time = 2.days
51
51
 
52
- mattr_accessor :invitation_url
53
- @@invitation_url = nil
52
+ mattr_accessor :accept_invitation_url
53
+ self.accept_invitation_url = nil
54
54
 
55
55
  def self.model
56
- @@model_name.constantize
56
+ model_name.constantize
57
57
  end
58
58
 
59
59
  def self.setup
@@ -1,3 +1,3 @@
1
1
  module RailsJwtAuth
2
- VERSION = '0.18.1'
2
+ VERSION = '0.19.0'
3
3
  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: 0.18.1
4
+ version: 0.19.0
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-19 00:00:00.000000000 Z
11
+ date: 2018-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.5.2
132
+ rubygems_version: 2.7.3
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Rails jwt authentication.