thincloud-authentication 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@ module Thincloud::Authentication
8
8
  validates :name, presence: true
9
9
  validates :email, presence: true, uniqueness: true, format: /@/
10
10
  validates :password, presence: { if: :password_required? },
11
- confirmation: { if: :password_required? }
11
+ confirmation: { if: :password_confirmation_required? }
12
12
 
13
13
  # Ensure that a `verification_token` exists for new records.
14
14
  after_initialize do
@@ -42,13 +42,14 @@ module Thincloud::Authentication
42
42
  #
43
43
  # Returns: An instance of the found `Identity`.
44
44
  # Raises: ActiveRecord::RecordNotFound if the `token` cannot be retrieved.
45
+ # ActiveRecord::RecordInvalid if the record cannot be saved.
45
46
  def self.verify!(token)
46
47
  find_by_verification_token!(token).tap do |identity|
47
48
  # ensure 'uid' exists, needed for 'identity' provider
48
49
  identity.uid = identity.id if identity.uid.blank?
49
50
  identity.verification_token = nil
50
51
  identity.verified_at = Time.zone.now
51
- identity.save
52
+ identity.save!
52
53
  end
53
54
  end
54
55
 
@@ -85,12 +86,23 @@ module Thincloud::Authentication
85
86
  # Returns: true
86
87
  #
87
88
  # Raises: ActiveRecord::RecordInvalid
88
- def generate_password_token!
89
+ def generate_password_reset!
89
90
  self.password_reset_token = SecureRandom.urlsafe_base64
90
91
  self.password_reset_sent_at = Time.zone.now
91
92
  save!
92
93
  end
93
94
 
95
+ # Public: Clear password reset fields, reset password_required? requirement
96
+ #
97
+ # Returns: true
98
+ #
99
+ # Raises: ActiveRecord::RecordInvalid
100
+ def clear_password_reset!
101
+ self.password_reset_token = nil
102
+ self.password_reset_sent_at = nil
103
+ save!
104
+ end
105
+
94
106
  # Public: Determine if the provider is 'identity'
95
107
  #
96
108
  # Returns: true or false
@@ -102,7 +114,16 @@ module Thincloud::Authentication
102
114
  #
103
115
  # Returns: true or false
104
116
  def password_required?
105
- identity_provider? && password_reset_token.blank?
117
+ identity_provider? && (new_record? || password_reset_token.present?)
118
+ end
119
+
120
+ # Public: Determine if the password confirmation must be provided
121
+ #
122
+ # Returns: true or false
123
+ def password_confirmation_required?
124
+ password_required? || (
125
+ password.present? || password_confirmation.present?
126
+ )
106
127
  end
107
128
  end
108
129
  end
@@ -9,7 +9,7 @@ module Thincloud::Authentication
9
9
  email: params[:email], password: password,
10
10
  password_confirmation: password)
11
11
  Identity.verify!(identity.verification_token)
12
- identity.generate_password_token!
12
+ identity.generate_password_reset!
13
13
  InvitationsMailer.new_invitation(identity.id).deliver
14
14
  true
15
15
  rescue ActiveRecord::RecordInvalid
@@ -3,7 +3,7 @@ module Thincloud::Authentication
3
3
  class PasswordResetWorkflow
4
4
  def self.call(email)
5
5
  return unless identity = Identity.find_by_email(email)
6
- identity.generate_password_token!
6
+ identity.generate_password_reset!
7
7
  PasswordsMailer.password_reset(identity.id).deliver
8
8
  end
9
9
  end
@@ -5,9 +5,8 @@ module Thincloud::Authentication
5
5
  def self.call(identity, params)
6
6
  identity.password = params[:password]
7
7
  identity.password_confirmation = params[:password_confirmation]
8
- identity.password_reset_token = nil
9
- identity.password_reset_sent_at = nil
10
8
  identity.save!
9
+ identity.clear_password_reset!
11
10
  rescue ActiveRecord::RecordInvalid
12
11
  identity.reload
13
12
  false
@@ -1,5 +1,5 @@
1
1
  module Thincloud
2
2
  module Authentication
3
- VERSION = "0.6.2"
3
+ VERSION = "0.6.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thincloud-authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-05-17 00:00:00.000000000 Z
13
+ date: 2013-05-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -150,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  segments:
152
152
  - 0
153
- hash: -1681311068432426013
153
+ hash: -4365408844162385494
154
154
  required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  none: false
156
156
  requirements:
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  version: '0'
160
160
  segments:
161
161
  - 0
162
- hash: -1681311068432426013
162
+ hash: -4365408844162385494
163
163
  requirements: []
164
164
  rubyforge_project:
165
165
  rubygems_version: 1.8.23