rails_jwt_auth 1.6.1 → 1.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a366c8d045f041a81ddb16e375a052f19dc011038d408c79dde19c31e6696968
4
- data.tar.gz: eafb8cf07deb41c01bf719fda8e66b2b5e6d8cc620bdc418dbd8ffa9d6f55ba1
3
+ metadata.gz: bc1754797f099cba50a36044a69225fbeffee8e01120b9aa394209761d30eaf4
4
+ data.tar.gz: da443b714e8d7af7fb687a66e46fc6f3a46feb8837239debd1d16c76c34a49dc
5
5
  SHA512:
6
- metadata.gz: 3a29adeb02a5e05ad95773eccdedbdeb53649f5e493c23e16a65541ac8191f39532308faed100866ab6c79ded869b6476e99dbac4257f27c27a5dbb920d31f71
7
- data.tar.gz: 39d19de7185410e1e8ecdcadaa13674a9ef520e3a0f91edeb883dddd43aa1ca3ed72187a810df475f20004f572a39796c27ebe4d815fa3f12791473d4f1696f4
6
+ metadata.gz: f72dd3b12df746bd2d95291090b5e5f4dce0c0cdcba429b4de5ac2290c811e55637790cbbbb93209bf8184ae9a827986b1000b3d8c9fb834f2151e9b610ba993
7
+ data.tar.gz: 68a3963c17ef09d9225550a79f3989572e5edb8b4c7023d40fca80b647c06c1cdd2848a0bbe76d0d11a339ffc88801d80f7f131ab829ddbb3ef60dabf6a2168a
@@ -2,9 +2,13 @@ if defined?(ActionMailer)
2
2
  class RailsJwtAuth::Mailer < ApplicationMailer
3
3
  default from: RailsJwtAuth.mailer_sender
4
4
 
5
- def confirmation_instructions(user)
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
- subject = I18n.t('rails_jwt_auth.mailer.confirmation_instructions.subject')
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(user)
20
- @user = 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(user)
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
- subject = I18n.t('rails_jwt_auth.mailer.reset_password_instructions.subject')
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(user)
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
- subject = I18n.t('rails_jwt_auth.mailer.set_password_instructions.subject')
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(user)
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
- subject = I18n.t('rails_jwt_auth.mailer.send_invitation.subject')
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(user)
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
@@ -34,12 +34,10 @@ module RailsJwtAuth
34
34
  self.confirmation_token = SecureRandom.base58(24)
35
35
  self.confirmation_sent_at = Time.current
36
36
 
37
- mailer = Mailer.confirmation_instructions(self)
38
- RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
37
+ RailsJwtAuth.send_email(:confirmation_instructions, self)
39
38
 
40
39
  if RailsJwtAuth.send_email_changed_notification
41
- mailer = Mailer.email_changed(self)
42
- RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
40
+ RailsJwtAuth.send_email(:email_changed, self)
43
41
  end
44
42
  end
45
43
  end
@@ -58,8 +56,7 @@ module RailsJwtAuth
58
56
  self.confirmation_sent_at = Time.current
59
57
  return false unless save
60
58
 
61
- mailer = Mailer.confirmation_instructions(self)
62
- RailsJwtAuth.deliver_later ? mailer.deliver_later : mailer.deliver
59
+ RailsJwtAuth.send_email(:confirmation_instructions, self)
63
60
  true
64
61
  end
65
62
 
@@ -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 es valid
116
- mailer = Mailer.send_invitation(self)
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
- mailer = Mailer.send_unlock_instructions(self)
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
- mailer = Mailer.reset_password_instructions(self)
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
- mailer = Mailer.set_password_instructions(self)
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
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RailsJwtAuth
2
- VERSION = '1.6.1'
2
+ VERSION = '1.7.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: 1.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rjurado
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-28 00:00:00.000000000 Z
11
+ date: 2020-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt