devise_password_expirable 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- data.tar.gz: 580d34c38ff0183b3a09f42988a1c77441df2945
4
- metadata.gz: 55c8b247f7f7a72167a97d4d5320bbc86d05271d
5
2
  SHA512:
6
- data.tar.gz: 37da798f6da4020241ad192e3d1c0f7bb644dfcc6b63e8167b345c31dccb32627221dadbaf515e0240a6fafa79a7de50a7c4ce93d3462f369838b6ad4c59f0e7
7
- metadata.gz: aade38df02cfb36229bb7c4993786e1e6fdfe9cc4b73f88bb517bd103551515e0d222e102003eeb485a0ffff31a412750380f0d7001a93a51bd89b4474c18e24
3
+ metadata.gz: 1b378548f93783f04fe45db7e8b412e1f7f3f90a55274e90a83e200a74eb4b1a86b3413816f8694a4ca5384d6d93db751d01d403ec28aebda9ad65c54f3918cf
4
+ data.tar.gz: ba579f4edb72e39cbbba04566202580767517fdba43be23bba69ca43fef50863dcb4e583a5e61d59f5413a75bfeb00477fd170b5cbdfcc072ba562d2a7c7ff34
5
+ SHA1:
6
+ metadata.gz: 07c5709271f496dd1c5aa31c7680245be5bd5f59
7
+ data.tar.gz: 90cdcb77894e11dd20e9e8159f6826cce7502158
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile CHANGED
@@ -2,5 +2,5 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in devise_ip_filter.gemspec
4
4
  gemspec
5
- gem "rails"
5
+ gem "rails", ">= 3.0.20"
6
6
  gem "devise"
@@ -1,31 +1,29 @@
1
- class Devise::PasswordExpiredController < DeviseController
1
+ class Devise::PasswordExpiredController < ApplicationController
2
2
  skip_before_filter :handle_password_change
3
3
  prepend_before_filter :authenticate_scope!, :only => [:show, :update]
4
+ include Devise::Controllers::InternalHelpers
4
5
 
5
6
  def show
6
7
  if not resource.nil? and resource.need_change_password?
7
- respond_with(resource)
8
+ render_with_scope :show
8
9
  else
9
10
  redirect_to :root
10
11
  end
11
12
  end
12
13
 
13
14
  def update
14
- if resource.update_with_password(resource_params)
15
+ if resource.update_with_password(params[resource_name])
15
16
  warden.session(scope)[:password_expired] = false
16
17
  set_flash_message :notice, :updated
17
- sign_in scope, resource, :bypass => true
18
+ sign_in scope, resource
18
19
  redirect_to stored_location_for(scope) || :root
19
20
  else
20
21
  clean_up_passwords(resource)
21
- respond_with(resource, action: :show)
22
+ render_with_scope :show
22
23
  end
23
24
  end
24
25
 
25
26
  private
26
- def resource_params
27
- params.require(resource_name).permit!
28
- end
29
27
 
30
28
  def scope
31
29
  resource_name.to_sym
@@ -1,4 +1,5 @@
1
1
  <h2>Renew your password</h2>
2
+ <p>Your password is out of date and must be updated.</p>
2
3
 
3
4
  <%= form_for(resource, :as => resource_name, :url => [resource_name, :password_expired], :html => { :method => :put }) do |f| %>
4
5
  <%= devise_error_messages! %>
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.homepage = "https://github.com/jenjaina/devise_password_expirable"
11
11
  s.licenses = ["MIT"]
12
12
  s.summary = %q{Expire passwords plugin for devise}
13
- s.description = "An extension to devise that will expire user passwords after a set amount of time and prompt them to update their password."
13
+ s.description = "A plugin to devise that will expire user passwords after a set amount of time and prompt them to update their password."
14
14
 
15
15
  # s.rubyforge_project = "devise_password_expirable"
16
16
 
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_runtime_dependency 'rails', '3.0.20'
23
- s.add_runtime_dependency 'devise', '1.1.3'
22
+ s.add_runtime_dependency 'rails', '>= 3.0.20'
23
+ s.add_runtime_dependency 'devise', '>= 1.1.3'
24
24
 
25
25
  s.add_development_dependency 'bundler'
26
26
  end
@@ -1,11 +1,12 @@
1
1
  require 'devise_password_expirable/version'
2
- require 'active_record'
2
+ require 'active_record/connection_adapters/abstract/schema_definitions'
3
3
  require 'active_support/core_ext/integer'
4
4
  require 'active_support/ordered_hash'
5
5
  require 'active_support/concern'
6
6
  require 'devise'
7
7
 
8
- module Devise
8
+ module Devise # :nodoc:
9
+
9
10
  # Should the password expire (e.g 3.months)
10
11
  mattr_accessor :expire_password_after
11
12
  @@expire_password_after = 3.months
@@ -30,3 +31,4 @@ Devise.add_module :password_expirable, :controller => :password_expirable, :mode
30
31
  # requires
31
32
  require 'devise_password_expirable/routes'
32
33
  require 'devise_password_expirable/rails'
34
+ require 'devise_password_expirable/orm/active_record'
@@ -1,6 +1,6 @@
1
1
  module DevisePasswordExpirable
2
- module Controllers
3
- module Helpers
2
+ module Controllers # :nodoc:
3
+ module Helpers # :nodoc:
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
@@ -8,14 +8,14 @@ module DevisePasswordExpirable
8
8
  end
9
9
 
10
10
  # controller instance methods
11
-
11
+ module InstanceMethods
12
12
  private
13
13
 
14
14
  # lookup if an password change needed
15
15
  def handle_password_change
16
16
  if not devise_controller? and not ignore_password_expire? and not request.format.nil? and request.format.html?
17
17
  Devise.mappings.keys.flatten.any? do |scope|
18
- if signed_in?(scope) and warden.session(scope)['password_expired']
18
+ if signed_in?(scope) and warden.session(scope)[:password_expired]
19
19
  session["#{scope}_return_to"] = request.path if request.get?
20
20
  redirect_for_password_change scope
21
21
  return
@@ -43,7 +43,7 @@ module DevisePasswordExpirable
43
43
  false
44
44
  end
45
45
 
46
-
46
+ end
47
47
  end
48
48
  end
49
49
 
@@ -1,5 +1,5 @@
1
1
  Warden::Manager.after_authentication do |record, warden, options|
2
2
  if record.respond_to?(:need_change_password?)
3
- warden.session(options[:scope])['password_expired'] = record.need_change_password?
3
+ warden.session(options[:scope])[:password_expired] = record.need_change_password?
4
4
  end
5
5
  end
@@ -1,57 +1,63 @@
1
- require 'devise_password_expirable/hooks/password_expirable'
1
+ require 'devise_security_extension/hooks/password_expirable'
2
2
 
3
- module Devise
4
- module Models
3
+ module Devise # :nodoc:
4
+ module Models # :nodoc:
5
5
 
6
6
  # PasswordExpirable takes care of change password after
7
7
  module PasswordExpirable
8
- extend ActiveSupport::Concern
9
8
 
10
- included do
11
- before_save :update_password_changed
12
- end
9
+ def self.included(base) # :nodoc:
10
+ base.extend ClassMethods
13
11
 
14
- # is an password change required?
15
- def need_change_password?
16
- if self.class.expire_password_after.is_a? Fixnum or self.class.expire_password_after.is_a? Float
17
- self.last_password_reset.nil? or self.last_password_reset < self.class.expire_password_after.ago
18
- else
19
- false
12
+ base.class_eval do
13
+ before_save :update_password_changed
14
+ include InstanceMethods
20
15
  end
21
16
  end
22
17
 
23
- # set a fake datetime so a password change is needed and save the record
24
- def need_change_password!
25
- if self.class.expire_password_after.is_a? Fixnum or self.class.expire_password_after.is_a? Float
26
- need_change_password
27
- self.save(:validate => false)
18
+ module InstanceMethods # :nodoc:
19
+
20
+ # is an password change required?
21
+ def need_change_password?
22
+ if self.class.expire_password_after.is_a? Fixnum
23
+ self.last_password_reset.nil? or self.last_password_reset < self.class.expire_password_after.ago
24
+ else
25
+ false
26
+ end
28
27
  end
29
- end
30
28
 
31
- # set a fake datetime so a password change is needed
32
- def need_change_password
33
- if self.class.expire_password_after.is_a? Fixnum or self.class.expire_password_after.is_a? Float
34
- self.last_password_reset = self.class.expire_password_after.ago
29
+ # set a fake datetime so a password change is needed and save the record
30
+ def need_change_password!
31
+ if self.class.expire_password_after.is_a? Fixnum
32
+ need_change_password
33
+ self.save(:validate => false)
34
+ end
35
35
  end
36
36
 
37
- # is date not set it will set default to need set new password next login
38
- need_change_password if self.last_password_reset.nil?
37
+ # set a fake datetime so a password change is needed
38
+ def need_change_password
39
+ if self.class.expire_password_after.is_a? Fixnum
40
+ self.last_password_reset = self.class.expire_password_after.ago
41
+ end
39
42
 
40
- self.last_password_reset
41
- end
43
+ # is date not set it will set default to need set new password next login
44
+ need_change_password if self.last_password_reset.nil?
42
45
 
43
- private
46
+ self.last_password_reset
47
+ end
48
+
49
+ private
44
50
 
45
51
  # is password changed then update password_cahanged_at
46
52
  def update_password_changed
47
53
  self.last_password_reset = Time.now if (self.new_record? or self.encrypted_password_changed?) and not self.last_password_reset_changed?
48
54
  end
55
+ end
49
56
 
50
- module ClassMethods
57
+ module ClassMethods #:nodoc:
51
58
  ::Devise::Models.config(self, :expire_password_after)
52
59
  end
53
60
  end
54
-
55
61
  end
56
62
 
57
- end
63
+ end
@@ -0,0 +1,20 @@
1
+ module DevisePasswordExpirable
2
+ module Orm
3
+ # This module contains some helpers and handle schema (migrations):
4
+ #
5
+ # create_table :accounts do |t|
6
+ # t.password_expirable
7
+ # end
8
+ #
9
+ module ActiveRecord
10
+ module Schema
11
+ include DevisePasswordExpirable::Schema
12
+
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ ActiveRecord::ConnectionAdapters::Table.send :include, DevisePasswordExpirable::Orm::ActiveRecord::Schema
20
+ ActiveRecord::ConnectionAdapters::TableDefinition.send :include, DevisePasswordExpirable::Orm::ActiveRecord::Schema
@@ -1,7 +1,7 @@
1
1
  module DevisePasswordExpirable
2
- class Engine < ::Rails::Engine
2
+ class Engine < ::Rails::Engine # :nodoc:
3
3
  ActiveSupport.on_load(:action_controller) do
4
4
  include DevisePasswordExpirable::Controllers::Helpers
5
- end
5
+ end
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
- module ActionDispatch::Routing
2
- class Mapper
1
+ module ActionDispatch::Routing # :nodoc:
2
+ class Mapper # :nodoc:
3
3
 
4
4
  protected
5
5
 
@@ -1,3 +1,3 @@
1
1
  module DevisePasswordExpirable
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,39 @@
1
+ module DevisePasswordExpirable
2
+ module Generators # :nodoc:
3
+ # Install Generator
4
+ class InstallGenerator < Rails::Generators::Base
5
+ source_root File.expand_path("../../templates", __FILE__)
6
+
7
+ desc "Install the devise password expirable extension"
8
+
9
+ def add_configs
10
+ devise_initializer_path = "config/initializers/devise.rb"
11
+ if File.exist?(devise_initializer_path)
12
+ old_content = File.read(devise_initializer_path)
13
+
14
+ if old_content.match(Regexp.new(/^\s# ==> Password Expirable Extension\n/))
15
+ false
16
+ else
17
+ inject_into_file(devise_initializer_path, :before => " # ==> Configuration for :confirmable\n") do
18
+ <<-CONTENT
19
+ # ==> Password Expirable Extension
20
+ # Configure expire passwords extension for devise
21
+
22
+ # Should the password expire (e.g 3.months)
23
+ # config.expire_password_after = false
24
+
25
+ # Need 1 char of A-Z, a-z and 0-9
26
+ # config.password_regex = /(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])/
27
+
28
+ CONTENT
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ def copy_locale
35
+ copy_file "../../../config/locales/en.yml", "config/locales/devise.password_expirable.en.yml"
36
+ end
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_password_expirable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jenni Kissinger
@@ -9,14 +9,14 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2014-10-21 00:00:00 Z
12
+ date: 2014-10-22 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  prerelease: false
17
17
  requirement: &id001 !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "="
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
21
  version: 3.0.20
22
22
  type: :runtime
@@ -26,7 +26,7 @@ dependencies:
26
26
  prerelease: false
27
27
  requirement: &id002 !ruby/object:Gem::Requirement
28
28
  requirements:
29
- - - "="
29
+ - - ">="
30
30
  - !ruby/object:Gem::Version
31
31
  version: 1.1.3
32
32
  type: :runtime
@@ -42,7 +42,7 @@ dependencies:
42
42
  version: "0"
43
43
  type: :development
44
44
  version_requirements: *id003
45
- description: An extension to devise that will expire user passwords after a set amount of time and prompt them to update their password.
45
+ description: A plugin to devise that will expire user passwords after a set amount of time and prompt them to update their password.
46
46
  email:
47
47
  - jkissinger@carekinesis.com
48
48
  executables: []
@@ -52,6 +52,7 @@ extensions: []
52
52
  extra_rdoc_files: []
53
53
 
54
54
  files:
55
+ - .document
55
56
  - .gitignore
56
57
  - Gemfile
57
58
  - README.md
@@ -64,11 +65,12 @@ files:
64
65
  - lib/devise_password_expirable/controllers/helpers.rb
65
66
  - lib/devise_password_expirable/hooks/password_expirable.rb
66
67
  - lib/devise_password_expirable/models/password_expirable.rb
68
+ - lib/devise_password_expirable/orm/active_record.rb
67
69
  - lib/devise_password_expirable/rails.rb
68
70
  - lib/devise_password_expirable/routes.rb
69
71
  - lib/devise_password_expirable/schema.rb
70
72
  - lib/devise_password_expirable/version.rb
71
- - lib/generators/devise_expire_passwords/install_generator.rb
73
+ - lib/generators/devise_password_expirable/install_generator.rb
72
74
  homepage: https://github.com/jenjaina/devise_password_expirable
73
75
  licenses:
74
76
  - MIT
@@ -1,23 +0,0 @@
1
- module DevisePasswordExpirable
2
- module Generators
3
- # Install Generator
4
- class InstallGenerator < Rails::Generators::Base
5
- source_root File.expand_path("../../templates", __FILE__)
6
-
7
- desc "Install the devise password expirable extension"
8
-
9
- def add_configs
10
- inject_into_file "config/initializers/devise.rb", "\n # ==> Password Expirable Extension\n # Configure expire passwords extension for devise\n\n" +
11
- " # Should the password expire (e.g 3.months)\n" +
12
- " # config.expire_password_after = false\n\n" +
13
- " # Need 1 char of A-Z, a-z and 0-9\n" +
14
- " # config.password_regex = /(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])/\n\n" +
15
- "", :before => /end[ |\n|]+\Z/
16
- end
17
-
18
- def copy_locale
19
- copy_file "../../../config/locales/en.yml", "config/locales/devise.password_expirable.en.yml"
20
- end
21
- end
22
- end
23
- end