devise_deactivatable 0.2.0 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +21 -0
- data/README.md +4 -0
- data/app/controllers/devise/deactivate_controller.rb +18 -0
- data/config/locales/en.yml +4 -0
- data/lib/devise_deactivatable.rb +12 -0
- data/lib/devise_deactivatable/controllers/helpers.rb +13 -0
- data/lib/devise_deactivatable/mapping.rb +13 -0
- data/lib/devise_deactivatable/model.rb +31 -0
- data/lib/devise_deactivatable/rails.rb +11 -0
- data/lib/devise_deactivatable/routes.rb +11 -0
- data/lib/devise_deactivatable/version.rb +3 -0
- metadata +32 -7
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Elan Meng
|
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.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Devise::DeactivateController < DeviseController
|
2
|
+
prepend_before_filter :authenticate_deactivatee!
|
3
|
+
|
4
|
+
# POST /resource/deactivate
|
5
|
+
def create
|
6
|
+
@resource = current_deactivatee
|
7
|
+
@resource.deactivate! if @resource
|
8
|
+
head :ok
|
9
|
+
rescue
|
10
|
+
respond_with @resource
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def current_deactivatee
|
16
|
+
authenticate_deactivatee!
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module DeviceDeactivatable
|
2
|
+
autoload :Mapping, 'devise_deactivatable/mapping'
|
3
|
+
module Controllers
|
4
|
+
autoload :Helpers, 'devise_deactivatable/controllers/helpers'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'devise'
|
9
|
+
require 'devise_deactivatable/routes'
|
10
|
+
require 'devise_deactivatable/rails'
|
11
|
+
|
12
|
+
Devise.add_module :deactivatable, :controller => :deactivate, :model => 'devise_deactivatable/model', :route => { :deactivate => [ :create ] }
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module DeviceDeactivatable
|
2
|
+
module Mapping
|
3
|
+
def self.included(base)
|
4
|
+
base.alias_method_chain :default_controllers, :deactivatable
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
def default_controllers_with_deactivatable(options)
|
9
|
+
options[:controllers] ||= {}
|
10
|
+
default_controllers_without_deactivatable(options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Devise
|
2
|
+
module Models
|
3
|
+
module Deactivatable
|
4
|
+
def self.required_fields(klass)
|
5
|
+
attributes = [:deactivated_at]
|
6
|
+
attributes
|
7
|
+
end
|
8
|
+
|
9
|
+
# Overwrites active_for_authentication? from Devise::Models::Activatable for deactivate purposes
|
10
|
+
# by verifying whether a user is active to sign in or not based on deactivated?
|
11
|
+
def active_for_authentication?
|
12
|
+
!deactivated? && super
|
13
|
+
end
|
14
|
+
|
15
|
+
def deactivate!
|
16
|
+
self.deactivated_at = Time.now
|
17
|
+
save!(:validate => false)
|
18
|
+
end
|
19
|
+
|
20
|
+
def deactivated?
|
21
|
+
!!deactivated_at
|
22
|
+
end
|
23
|
+
|
24
|
+
# Overwrites invalid_message from Devise::Models::Authenticatable to define
|
25
|
+
# the correct reason for blocking the sign in.
|
26
|
+
def inactive_message
|
27
|
+
deactivated? ? :deactivated : super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module DeviceDeactivatable
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
ActiveSupport.on_load(:action_controller) do
|
4
|
+
include DeviceDeactivatable::Controllers::Helpers
|
5
|
+
end
|
6
|
+
|
7
|
+
config.after_initialize do
|
8
|
+
Devise::Mapping.send :include, DeviceDeactivatable::Mapping
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_deactivatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 5
|
10
|
+
version: 0.2.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Elan Meng
|
@@ -17,8 +17,23 @@ cert_chain: []
|
|
17
17
|
|
18
18
|
date: 2014-06-04 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: devise
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 3.0.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
22
37
|
description: Deactivate support for Devise.
|
23
38
|
email:
|
24
39
|
- dreamwords@gmail.com
|
@@ -28,8 +43,18 @@ extensions: []
|
|
28
43
|
|
29
44
|
extra_rdoc_files: []
|
30
45
|
|
31
|
-
files:
|
32
|
-
|
46
|
+
files:
|
47
|
+
- app/controllers/devise/deactivate_controller.rb
|
48
|
+
- config/locales/en.yml
|
49
|
+
- lib/devise_deactivatable.rb
|
50
|
+
- lib/devise_deactivatable/controllers/helpers.rb
|
51
|
+
- lib/devise_deactivatable/mapping.rb
|
52
|
+
- lib/devise_deactivatable/model.rb
|
53
|
+
- lib/devise_deactivatable/rails.rb
|
54
|
+
- lib/devise_deactivatable/routes.rb
|
55
|
+
- lib/devise_deactivatable/version.rb
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
33
58
|
has_rdoc: true
|
34
59
|
homepage: https://github.com/scambra/devise_invitable
|
35
60
|
licenses:
|