devise_account_expireable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in devise_account_expireable.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Justin McNally
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,31 @@
1
+ # DeviseAccountExpireable
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ gem 'devise_account_expireable'
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install devise_account_expireable
16
+
17
+ ## Usage
18
+
19
+ 1. Install the migration: `rails g devise_account_expireable`
20
+ 2. `rake db:migrate`
21
+ 3. Add `:account_expireable` to the devise line of you account (User) model.
22
+ `devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :account_expireable`
23
+ 4. Add a way through your admin panel of setting the attribute `:expires_at` to a date/time on the account (User) model.
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ en:
2
+ devise:
3
+ failure:
4
+ user:
5
+ account_expired: "Your account has expired. You may re-request access from an administrator."
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/devise_account_expireable/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Justin McNally"]
6
+ gem.email = ["justin@kohactive.com"]
7
+ gem.description = %q{Expire a user's account at a certain date}
8
+ gem.summary = %q{At a certain date make a user's account not work}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "devise_account_expireable"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = DeviseAccountExpireable::VERSION
17
+
18
+ gem.add_dependency(%q<devise>, [">= 2.0.4"])
19
+ gem.add_dependency(%q<rails>, [">= 3.2"])
20
+ end
@@ -0,0 +1,35 @@
1
+ module Devise
2
+ module Models
3
+ # Trace information about your user sign in. It tracks the following columns:
4
+
5
+ # * resource_id
6
+ # * sign_in_at
7
+ # * sign_out_at
8
+
9
+ module AccountExpireable
10
+ extend ActiveSupport::Concern
11
+
12
+ def expired?
13
+ expires_at.present? && expires_at < DateTime.now
14
+ end
15
+
16
+
17
+
18
+ def self.required_fields(klass)
19
+ attributes = []
20
+ attributes << :expires_at
21
+ attributes
22
+ end
23
+ def access_locked?
24
+ expired?
25
+ end
26
+ def active_for_authentication?
27
+ super && !expired?
28
+ end
29
+
30
+ def inactive_message
31
+ expired? ? :account_expired : super
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ require 'devise_account_expireable'
2
+
3
+ module DeviseAccountExpireable
4
+ class Engine < ::Rails::Engine
5
+
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module DeviseAccountExpireable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,16 @@
1
+ require "devise_account_expireable/version"
2
+
3
+
4
+ unless defined?(Devise)
5
+ require 'devise'
6
+ end
7
+
8
+ require 'devise_account_expireable'
9
+
10
+ Devise.add_module :account_expireable, :model => 'devise_account_expireable/model'
11
+
12
+
13
+ module DeviseAccountExpireable
14
+ end
15
+
16
+ require 'devise_account_expireable/rails'
@@ -0,0 +1,50 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class DeviseAccountExpireableGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ desc "Generates a migration to add required field to devise account model."
7
+
8
+ def self.source_root
9
+ @_devise_source_root ||= File.expand_path("../templates", __FILE__)
10
+ end
11
+
12
+ def self.orm_has_migration?
13
+ Rails::Generators.options[:rails][:orm] == :active_record
14
+ end
15
+
16
+ def self.next_migration_number(dirname)
17
+ if ActiveRecord::Base.timestamped_migrations
18
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
19
+ else
20
+ "%.3d" % (current_migration_number(dirname) + 1)
21
+ end
22
+ end
23
+
24
+ class_option :orm
25
+ class_option :migration, :type => :boolean, :default => orm_has_migration?
26
+
27
+ def invoke_migration
28
+
29
+ model_name = ask("What is the name of your account model? (Leave blank for User): ")
30
+ model_name = "User" if model_name.blank?
31
+
32
+ @model_name = model_name.camelize.singularize
33
+
34
+
35
+
36
+ if colum_exists?
37
+ say "* Colum exists on model already exists."
38
+ else
39
+ migration_template 'migration.rb', "db/migrate/devise_update_#{model_name.downcase}_expire_fields.rb"
40
+ end
41
+
42
+ puts "Make sure to add :account_expireable to the devise line of your #{@model_name} model file."
43
+ end
44
+
45
+ protected
46
+
47
+ def colum_exists?
48
+ @model_name.constantize.column_names.include?("expires_at")
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ class DeviseUpdate<%= @model_name.camelize.singularize %>ExpireFields < ActiveRecord::Migration
2
+ def change
3
+ add_column :<%=@model_name.tableize%>, :expires_at, :datetime
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise_account_expireable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Justin McNally
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: devise
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '3.2'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '3.2'
46
+ description: Expire a user's account at a certain date
47
+ email:
48
+ - justin@kohactive.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - config/locales/en.yml
59
+ - devise_account_expireable.gemspec
60
+ - lib/devise_account_expireable.rb
61
+ - lib/devise_account_expireable/model.rb
62
+ - lib/devise_account_expireable/rails.rb
63
+ - lib/devise_account_expireable/version.rb
64
+ - lib/generators/devise_account_expireable/devise_account_expireable_generator.rb
65
+ - lib/generators/devise_account_expireable/templates/migration.rb
66
+ homepage: ''
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.24
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: At a certain date make a user's account not work
90
+ test_files: []