rails_jwt_auth 0.8.0 → 0.9.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
2
  SHA1:
3
- metadata.gz: bca93333f4c37dbd3dd906f70c3342782407e3f4
4
- data.tar.gz: e049172d67606c5cfad757e8f85ada512c1f185c
3
+ metadata.gz: 8a4b26a2187fcea5e112d830e6fe4c359b6c254e
4
+ data.tar.gz: c03420a5b617a85fcf3abe79029d12e1fc28d05d
5
5
  SHA512:
6
- metadata.gz: 4ad3e2570b0c8c3948d1a38fffc011914bf52fecffa4d4ca2ec8a187c91d1dc5417aaba5de6cafdb3e9ef1d4f9c3bad09cb1d7d94c71ecfe030e4aaff13d847e
7
- data.tar.gz: 73b4e8bac9ffc07b629c00108f9412d47f13a31df46cafbe8e2850de6def5553f2c96852ff9bf4370d87348fb3afe6d4bcca4b141f701e93b197c8f4b9277377
6
+ metadata.gz: 147277f3faf5e26b7df0d2ba902de62c3ab5ddc2cb11f9f851c058202612d2686a31e2adc8d89d34d84123a757d744e0d012df18569d1cbbfb9c82a726577195
7
+ data.tar.gz: 0d694343c935a6968417523c43853eabe68d521e15c09b0387b604bc6bf30a388659ea23c9a9ddd483738d19fb8321f3a5679c4277b4176c3dc14fc6861aab65
data/README.md CHANGED
@@ -107,6 +107,8 @@ and create a migration to add confirmation fields to User model:
107
107
  ```ruby
108
108
  # example migration
109
109
  change_table :users do |t|
110
+ t.string :email # if it doesn't exist yet
111
+ t.string :unconfirmed_email
110
112
  t.string :confirmation_token
111
113
  t.datetime :confirmation_sent_at
112
114
  t.datetime :confimed_at
@@ -126,6 +128,8 @@ class User
126
128
  end
127
129
  ```
128
130
 
131
+ This module needs that model has `email` field.
132
+
129
133
  ## Recoverable
130
134
 
131
135
  Resets the user password and sends reset instructions
@@ -17,7 +17,7 @@ if defined?(ActionMailer)
17
17
  end
18
18
 
19
19
  subject = I18n.t('rails_jwt_auth.mailer.confirmation_instructions.subject')
20
- mail(to: @user.email, subject: subject)
20
+ mail(to: @user.unconfirmed_email || @user.email, subject: subject)
21
21
  end
22
22
 
23
23
  def reset_password_instructions(user)
@@ -1,7 +1,7 @@
1
1
  module RailsJwtAuth
2
2
  module Confirmable
3
3
  def send_confirmation_instructions
4
- if confirmed?
4
+ if confirmed? && !unconfirmed_email_changed?
5
5
  errors.add(:email, I18n.t('rails_jwt_auth.errors.already_confirmed'))
6
6
  return false
7
7
  end
@@ -18,6 +18,12 @@ module RailsJwtAuth
18
18
 
19
19
  def confirm!
20
20
  self.confirmed_at = Time.now.utc
21
+
22
+ if unconfirmed_email
23
+ self.email = unconfirmed_email
24
+ self.unconfirmed_email = nil
25
+ end
26
+
21
27
  save
22
28
  end
23
29
 
@@ -32,6 +38,8 @@ module RailsJwtAuth
32
38
 
33
39
  def self.included(base)
34
40
  if base.ancestors.include? Mongoid::Document
41
+ base.send(:field, :email, type: String)
42
+ base.send(:field, :unconfirmed_email, type: String)
35
43
  base.send(:field, :confirmation_token, type: String)
36
44
  base.send(:field, :confirmation_sent_at, type: Time)
37
45
  base.send(:field, :confirmed_at, type: Time)
@@ -42,12 +50,20 @@ module RailsJwtAuth
42
50
  base.send(:after_create) do
43
51
  send_confirmation_instructions unless confirmed_at || confirmation_sent_at
44
52
  end
53
+
54
+ base.send(:before_update) do
55
+ if email_changed? && email_was && !confirmed_at_changed?
56
+ self.unconfirmed_email = email
57
+ self.email = email_was
58
+ send_confirmation_instructions
59
+ end
60
+ end
45
61
  end
46
62
 
47
63
  private
48
64
 
49
65
  def validate_confirmation
50
- return unless confirmed_at
66
+ return true if !confirmed_at || email_changed?
51
67
 
52
68
  if confirmed_at_was
53
69
  errors.add(:email, I18n.t('rails_jwt_auth.errors.already_confirmed'))
@@ -1,3 +1,3 @@
1
1
  module RailsJwtAuth
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.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.8.0
4
+ version: 0.9.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-03-09 00:00:00.000000000 Z
11
+ date: 2017-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails