Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ script: bundle exec rake
rvm:
- 2.1.8
- 2.2.4
- 2.3.4
- 2.4.1
- ruby-head
matrix:
allow_failures:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PATH
devise_security_extension (0.10.0)
devise (>= 3.0.0, < 5.0)
json (~> 2.0)
railties (>= 3.2.6, < 6.0)
rails (>= 4.2.8, < 6.0)

GEM
remote: https://rubygems.org/
Expand Down
6 changes: 5 additions & 1 deletion devise_security_extension.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ Gem::Specification.new do |s|
s.require_paths = ['lib']
s.required_ruby_version = '>= 2.4.0'

s.add_runtime_dependency 'railties', '>= 3.2.6', '< 6.0'
if RUBY_VERSION >= '2.4'
s.add_runtime_dependency 'rails', '>= 4.2.8', '< 6.0'
else
s.add_runtime_dependency 'railties', '>= 3.2.6', '< 6.0'
end
s.add_runtime_dependency 'devise', '>= 3.0.0', '< 5.0'
s.add_runtime_dependency 'json', '~> 2.0'
s.add_development_dependency 'bundler', '>= 1.3.0', '< 2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def validate_password_archive

# validate is the password used in the past
def password_archive_included?
unless deny_old_passwords.is_a? Fixnum
unless deny_old_passwords.is_a? 1.class
if deny_old_passwords.is_a? TrueClass and archive_count > 0
self.deny_old_passwords = archive_count
else
Expand Down
14 changes: 10 additions & 4 deletions lib/devise_security_extension/models/password_expirable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module PasswordExpirable

# is an password change required?
def need_change_password?
if self.expire_password_after.is_a? Fixnum or self.expire_password_after.is_a? Float
if expired_password_after_numeric?
self.password_changed_at.nil? or self.password_changed_at < self.expire_password_after.seconds.ago
else
false
Expand All @@ -22,15 +22,15 @@ def need_change_password?

# set a fake datetime so a password change is needed and save the record
def need_change_password!
if self.expire_password_after.is_a? Fixnum or self.expire_password_after.is_a? Float
if expired_password_after_numeric?
need_change_password
self.save(:validate => false)
end
end

# set a fake datetime so a password change is needed
def need_change_password
if self.expire_password_after.is_a? Fixnum or self.expire_password_after.is_a? Float
if expired_password_after_numeric?
self.password_changed_at = self.expire_password_after.seconds.ago
end

Expand All @@ -39,7 +39,7 @@ def need_change_password

self.password_changed_at
end

def expire_password_after
self.class.expire_password_after
end
Expand All @@ -51,6 +51,12 @@ def update_password_changed
self.password_changed_at = Time.now if (self.new_record? or self.encrypted_password_changed?) and not self.password_changed_at_changed?
end

def expired_password_after_numeric?
return @_numeric if defined?(@_numeric)
@_numeric ||= self.expire_password_after.is_a?(1.class) ||
self.expire_password_after.is_a?(Float)
end

module ClassMethods
::Devise::Models.config(self, :expire_password_after)
end
Expand Down