devise_date_restrictable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +13 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.textile +42 -0
- data/config/locales/en.yml +5 -0
- data/devise_date_restrictable.gemspec +19 -0
- data/lib/devise_date_restrictable/active_record.rb +36 -0
- data/lib/devise_date_restrictable/rails.rb +5 -0
- data/lib/devise_date_restrictable/version.rb +3 -0
- data/lib/devise_date_restrictable.rb +11 -0
- data/lib/generators/devise_date_restrictable/devise_date_restrictable_generator.rb +40 -0
- data/lib/generators/devise_date_restrictable/templates/migration.rb +6 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d8e7bdcb5d131667ce1606ceff520840e41d0d2f
|
4
|
+
data.tar.gz: ed13b406d6044280fe46e737e15f6ec0979972b9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43c0c1db641ce4b175d9cb98ef51016b47a06f8fb65569cb0d7b0d2a9322fdf87015fd939dd82bd5f092163ccf4e570a4fd5d21054d2cbec3bc53554a960e9c2
|
7
|
+
data.tar.gz: 3366256cf7c11522b25468940d675bf6591dceb501203c416e51bc9fbaabc693fb083abfc126fe8583aa685500daf82720876ba6ae627b90db25ad4a4843e066
|
data/.editorconfig
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# EditorConfig is awesome: http://EditorConfig.org
|
2
|
+
|
3
|
+
# top-most EditorConfig file
|
4
|
+
root = true
|
5
|
+
|
6
|
+
# Defaults for all files
|
7
|
+
[*]
|
8
|
+
end_of_line = lf
|
9
|
+
insert_final_newline = true
|
10
|
+
charset = utf-8
|
11
|
+
indent_style = space
|
12
|
+
indent_size = 2
|
13
|
+
trim_trailing_whitespace = true
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jon Pearse
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
h1. Devise Date Restrictable
|
2
|
+
|
3
|
+
This is a module for "Devise":https://github.com/plataformatec/devise that allows a user account to be restricted by date range.
|
4
|
+
|
5
|
+
h2. Installation + Setup
|
6
|
+
|
7
|
+
Add the following line to your application’s Gemfile:
|
8
|
+
|
9
|
+
<pre><code>gem 'devise_date_restrictable'</code></pre>
|
10
|
+
|
11
|
+
And then run @bundle install@.
|
12
|
+
|
13
|
+
Next, you will need to generate an ActiveRecord migration and run that migration.
|
14
|
+
|
15
|
+
<pre><code>$ rails generate devise_date_restrictable --model MODEL
|
16
|
+
rake db:migrate</code></pre>
|
17
|
+
|
18
|
+
Finally, add @:date_restrictable@ to the devise line of your model, for instance:
|
19
|
+
|
20
|
+
<pre><code>devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :date_restrictable</code></pre>
|
21
|
+
|
22
|
+
h2. Usage
|
23
|
+
|
24
|
+
This gem adds two @DATE@ fields to your account model: @valid_from@ and @valid_until@. One or both may be specified in order to restrict an account’s ability to log in.
|
25
|
+
If neither is specified, the user will be able to log in without restriction.
|
26
|
+
|
27
|
+
Note that dates are _inclusive_: that is, setting an account to be valid *from* 2017-05-28 means they will be able to log in from midnight on 2017-05-28. Similarly, setting an account to be valid *until* 2017-05-27 means they will be able to log in until 23.59.59 on that date.
|
28
|
+
At this time, all restrictions are based on server time—no provision has been made, as yet, for different timezones.
|
29
|
+
|
30
|
+
h2. To-do
|
31
|
+
|
32
|
+
This has been fairly quickly bashed together for use within a project, therefore isn’t perhaps as polished as it might be. At some point, I might get around to implementing some of the following:
|
33
|
+
|
34
|
+
* add support for timezones
|
35
|
+
* add helper methods to the account object to facilitate easier management (eg. @user.set_valid_for(3.years)@, and the like)
|
36
|
+
* support for better messaging
|
37
|
+
|
38
|
+
h2. Version History
|
39
|
+
|
40
|
+
h3. 0.0.1 _(May 28th, 2017)_
|
41
|
+
|
42
|
+
* initial release
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/devise_date_restrictable/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = "Jon Pearse"
|
6
|
+
gem.email = "jon@jonpearse.net"
|
7
|
+
gem.description = "This allows a Devise user’s validity to be restricted by a date range. This allows administrators to set up accounts that are valid to-, or from-, or between specific dates."
|
8
|
+
gem.summary = "Devise plugin to restrict access based on a date range."
|
9
|
+
gem.homepage = "https://github.com/jonpearse/devise_date_restrictable"
|
10
|
+
gem.license = "MIT"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.name = "devise_date_restrictable"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = DeviseDateRestrictable::VERSION
|
16
|
+
|
17
|
+
gem.add_dependency('devise', [">= 4.0.0"])
|
18
|
+
gem.add_dependency('rails', [">= 5.0.0"])
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Devise
|
2
|
+
module Models
|
3
|
+
module DateRestrictable
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def date_restricted?
|
7
|
+
now = Date.today
|
8
|
+
|
9
|
+
puts now.inspect
|
10
|
+
puts valid_from.nil?.inspect
|
11
|
+
puts valid_until.nil?.inspect
|
12
|
+
|
13
|
+
!((valid_from.nil? or now >= valid_from) and (valid_until.nil? or now <= valid_until))
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.required_fields(klass)
|
17
|
+
attributes = []
|
18
|
+
attributes << :valid_from
|
19
|
+
attributes << :valid_until
|
20
|
+
attributes
|
21
|
+
end
|
22
|
+
|
23
|
+
def access_locked?
|
24
|
+
date_restricted?
|
25
|
+
end
|
26
|
+
|
27
|
+
def active_for_authentication?
|
28
|
+
super && !date_restricted?
|
29
|
+
end
|
30
|
+
|
31
|
+
def inactive_message
|
32
|
+
date_restricted? ? :account_date_restricted : super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "devise_date_restrictable/version"
|
2
|
+
require "devise_date_restrictable/rails"
|
3
|
+
|
4
|
+
unless defined?(Devise)
|
5
|
+
require 'devise'
|
6
|
+
end
|
7
|
+
|
8
|
+
Devise.add_module :date_restrictable, model: 'devise_date_restrictable/active_record'
|
9
|
+
|
10
|
+
module DeviseDateRestrictable
|
11
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
class DeviseDateRestrictableGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
@_devise_source_root ||= File.expand_path("../templates", __FILE__)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.next_migration_number(dirname)
|
11
|
+
if ActiveRecord::Base.timestamped_migrations
|
12
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
13
|
+
else
|
14
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class_option :model, type: :string, default: 'User'
|
19
|
+
|
20
|
+
desc "Generates a migration to add required fields to devise account model."
|
21
|
+
def invoke_migration
|
22
|
+
|
23
|
+
model_name = options['model']
|
24
|
+
@model_name = model_name.camelize.singularize
|
25
|
+
|
26
|
+
if columns_exist?
|
27
|
+
say "* Date restrictable columns already seem to exist on @{model_name}"
|
28
|
+
else
|
29
|
+
migration_template 'migration.rb', "db/migrate/devise_add_#{model_name.downcase}_date_restriction_fields.rb"
|
30
|
+
end
|
31
|
+
|
32
|
+
puts "Make sure to add :date_restrictable to the devise line of your #{@model_name} model file."
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def columns_exist?
|
38
|
+
@model_name.constantize.column_names.include?("valid_from") and @model_name.constantize.column_names.include?("valid_until")
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise_date_restrictable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Pearse
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: devise
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.0.0
|
41
|
+
description: This allows a Devise user’s validity to be restricted by a date range.
|
42
|
+
This allows administrators to set up accounts that are valid to-, or from-, or between
|
43
|
+
specific dates.
|
44
|
+
email: jon@jonpearse.net
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".editorconfig"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE
|
52
|
+
- README.textile
|
53
|
+
- config/locales/en.yml
|
54
|
+
- devise_date_restrictable.gemspec
|
55
|
+
- lib/devise_date_restrictable.rb
|
56
|
+
- lib/devise_date_restrictable/active_record.rb
|
57
|
+
- lib/devise_date_restrictable/rails.rb
|
58
|
+
- lib/devise_date_restrictable/version.rb
|
59
|
+
- lib/generators/devise_date_restrictable/devise_date_restrictable_generator.rb
|
60
|
+
- lib/generators/devise_date_restrictable/templates/migration.rb
|
61
|
+
homepage: https://github.com/jonpearse/devise_date_restrictable
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.6.11
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Devise plugin to restrict access based on a date range.
|
85
|
+
test_files: []
|