devise_expirable 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +110 -0
- data/Rakefile +35 -0
- data/config/locales/en.yml +4 -0
- data/devise_expirable.gemspec +25 -0
- data/lib/devise/configuration.rb +5 -0
- data/lib/devise/expirable/model.rb +53 -0
- data/lib/devise/expirable/module.rb +1 -0
- data/lib/devise/expirable/version.rb +3 -0
- data/lib/devise_expirable.rb +3 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0cf5e8c2ae99c23f5d64c2486721a2f160e2f911109c6745fb0c2a8d740977fc
|
4
|
+
data.tar.gz: 1588752214f1b2c808eb1f7f7b154d2ae37ce8f23ed94ae017434a8400f07593
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: efc64dfabbc4f8271d6c0243dad3f7d0d15b9f85cf2317eb53e376116bad6ffa5d717eef54382d1961f2397244cdaca455eb8fb4be963937d1576a260ea43afc
|
7
|
+
data.tar.gz: a46e3fc2d945f1a226d9ff8b4c926b9550075e94e25b7eb296aaac864ae8cc75b8ca32b7cfd5212bb390a73ac5ef34da98e3f3d08591545deb36dc08809ab786
|
data/.gitignore
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 20@4 Yanotec
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# DevisePasswordExpiratable
|
2
|
+
|
3
|
+
This is a simple, however wonderful devise extension to expire user password after a period.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'devise_expirable'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install devise_expirable
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
u = User.create(:name => 'John Doe', :password => "john.doe")
|
22
|
+
u.password_expired? # false
|
23
|
+
u.password_still_valid? # true
|
24
|
+
u.active_for_authentication? # true
|
25
|
+
u.inactive_message # nil
|
26
|
+
|
27
|
+
u.update(expiration_password_at: nil)
|
28
|
+
u.password_expired? # true
|
29
|
+
u.password_still_valid? # false
|
30
|
+
u.active_for_authentication? # false
|
31
|
+
u.inactive_message # :password_expired
|
32
|
+
|
33
|
+
u.update(expiration_password_at: 1.second.ago)
|
34
|
+
u.password_expired? # true
|
35
|
+
u.password_still_valid? # false
|
36
|
+
u.active_for_authentication? # false
|
37
|
+
u.inactive_message # :password_expired
|
38
|
+
|
39
|
+
u.update(expiration_password_at: 10.minutes.from_now)
|
40
|
+
u.password_expired? # false
|
41
|
+
u.password_still_valid? # true
|
42
|
+
u.active_for_authentication? # true
|
43
|
+
u.inactive_message # nil
|
44
|
+
|
45
|
+
#### Using with ActiveRecord
|
46
|
+
You need to create a migration, manually (there is no magic here):
|
47
|
+
|
48
|
+
class DeviseExpirableToUsers < ActiveRecord::Migration
|
49
|
+
def up
|
50
|
+
add_column :users, :expiration_password_at, :timestamp
|
51
|
+
add_index :users, :expiration_password_at
|
52
|
+
end
|
53
|
+
|
54
|
+
def down
|
55
|
+
remove_index :users, :expiration_password_at
|
56
|
+
remove_column :users, :expiration_password_at
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
or
|
61
|
+
|
62
|
+
class DeviseExpirableToUsers < ActiveRecord::Migration
|
63
|
+
def change
|
64
|
+
change_table :users, bulk: true do |t|
|
65
|
+
t.datetime :expiration_password_at
|
66
|
+
t.index :expiration_password_at
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
Include in your model:
|
73
|
+
|
74
|
+
class User < ActiveRecord::Base
|
75
|
+
devise :database_authentication, :expirable
|
76
|
+
end
|
77
|
+
|
78
|
+
Adding two wonderful new public methods:
|
79
|
+
|
80
|
+
- password_still_valid? : checks whether password still valid
|
81
|
+
- password_expired? : checks whether password expired
|
82
|
+
|
83
|
+
And modifications to two other methods:
|
84
|
+
|
85
|
+
- active_for_authentication? : If password is expired returns false, else it preforms the super method
|
86
|
+
- inactive_message : If password is expired returns :password_expired, else it performs the super method
|
87
|
+
|
88
|
+
And add a before save callback and a auxiliar callback method:
|
89
|
+
|
90
|
+
- change_expiration_password_at : Changes expiration_password_at field ever that encrypted_password field is changed
|
91
|
+
- next_password_expiration_time : Returns a datetime with the moment that password will expires, based in password_expirate_in configuration of Devise
|
92
|
+
|
93
|
+
And add a devise configuration:
|
94
|
+
|
95
|
+
- password_expirate_in : The time you want to reach before any user's password expires. After this period, the user must change the password again. The default is 10 days.
|
96
|
+
|
97
|
+
## License
|
98
|
+
|
99
|
+
The devise_expirable is hosted on Github: https://github.com/jonathanccalixto/devise_expirable, where your contributions, forkings, comments and feedback are greatly welcomed.
|
100
|
+
|
101
|
+
Copyright (c) 2024 Yanotec, released under the MIT license.
|
102
|
+
|
103
|
+
|
104
|
+
## Contributing
|
105
|
+
|
106
|
+
1. Fork it ( http://github.com/jonathanccalixto/devise_expirable/fork )
|
107
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
108
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
109
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
110
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rdoc/task'
|
5
|
+
|
6
|
+
desc 'Default: run tests for all ORMs.'
|
7
|
+
task default: :test
|
8
|
+
|
9
|
+
desc 'Run Devise tests for all ORMs.'
|
10
|
+
task :pre_commit do
|
11
|
+
Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file|
|
12
|
+
orm = File.basename(file).split(".").first
|
13
|
+
# "Some day, my son, rake's inner wisdom will reveal itself. Until then,
|
14
|
+
# take this `system` -- may its brute force protect you well."
|
15
|
+
exit 1 unless system "rake test DEVISE_ORM=#{orm}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Run Devise unit tests.'
|
20
|
+
Rake::TestTask.new(:test) do |t|
|
21
|
+
t.libs << 'lib'
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
t.verbose = true
|
25
|
+
t.warning = false
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Generate documentation for Devise.'
|
29
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
30
|
+
rdoc.rdoc_dir = 'rdoc'
|
31
|
+
rdoc.title = 'Devise'
|
32
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
33
|
+
rdoc.rdoc_files.include('README.md')
|
34
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'devise/expirable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "devise_expirable"
|
8
|
+
spec.version = DeviseExpirable::VERSION
|
9
|
+
spec.authors = ["Jonathan C. Calixto"]
|
10
|
+
spec.email = ["jonathanccalixto@gmail.com"]
|
11
|
+
spec.summary = %q{Expires user password after a period}
|
12
|
+
spec.description = %q{This is a simple, however wonderful devise extension to expire user password.}
|
13
|
+
spec.homepage = "https://github.com/jonathanccalixto/devise_expirable"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^spec/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "devise", ">= 2.0"
|
25
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'devise/strategies/database_authenticatable'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Models
|
5
|
+
module Expirable
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
before_save :change_expiration_password_at
|
10
|
+
end
|
11
|
+
|
12
|
+
def password_expirate_in
|
13
|
+
self.class.password_expirate_in
|
14
|
+
end
|
15
|
+
|
16
|
+
def active_for_authentication?
|
17
|
+
password_still_valid? && super
|
18
|
+
end
|
19
|
+
|
20
|
+
def password_still_valid?
|
21
|
+
return false unless expiration_password_at
|
22
|
+
|
23
|
+
expiration_password_at >= Time.current
|
24
|
+
end
|
25
|
+
|
26
|
+
def password_expired?
|
27
|
+
!password_still_valid?
|
28
|
+
end
|
29
|
+
|
30
|
+
def inactive_message
|
31
|
+
password_expired? ? :password_expired : super
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def next_password_expiration_time
|
37
|
+
password_expirate_in.from_now
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def change_expiration_password_at
|
43
|
+
return unless encrypted_password_changed?
|
44
|
+
|
45
|
+
self.expiration_password_at = next_password_expiration_time
|
46
|
+
end
|
47
|
+
|
48
|
+
module ClassMethods
|
49
|
+
Devise::Models.config(self, :password_expirate_in)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Devise.add_module :expirable, :model => 'devise/expirable/model'
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise_expirable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan C. Calixto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: devise
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
description: This is a simple, however wonderful devise extension to expire user password.
|
56
|
+
email:
|
57
|
+
- jonathanccalixto@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- config/locales/en.yml
|
67
|
+
- devise_expirable.gemspec
|
68
|
+
- lib/devise/configuration.rb
|
69
|
+
- lib/devise/expirable/model.rb
|
70
|
+
- lib/devise/expirable/module.rb
|
71
|
+
- lib/devise/expirable/version.rb
|
72
|
+
- lib/devise_expirable.rb
|
73
|
+
homepage: https://github.com/jonathanccalixto/devise_expirable
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubygems_version: 3.5.6
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Expires user password after a period
|
96
|
+
test_files: []
|