devise_invitable 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise_invitable might be problematic. Click here for more details.
- data/app/controllers/devise_invitable/registrations_controller.rb +15 -0
- data/app/controllers/devise_invitable/registrations_controller.rb~ +15 -0
- data/lib/devise_invitable.rb +8 -6
- data/lib/devise_invitable.rb~ +65 -0
- data/lib/devise_invitable/controllers/helpers.rb +1 -1
- data/lib/devise_invitable/controllers/helpers.rb~ +21 -0
- data/lib/devise_invitable/controllers/registrations.rb~ +11 -26
- data/lib/devise_invitable/mapping.rb +14 -0
- data/lib/devise_invitable/rails.rb +5 -2
- data/lib/devise_invitable/rails.rb~ +21 -0
- data/lib/devise_invitable/version.rb +1 -1
- metadata +21 -16
- data/lib/devise_invitable/controllers/registrations.rb +0 -39
@@ -0,0 +1,15 @@
|
|
1
|
+
class DeviseInvitable::RegistrationsController < Devise::RegistrationsController
|
2
|
+
protected
|
3
|
+
|
4
|
+
def build_resource(*args)
|
5
|
+
hash = args.pop || resource_params || {}
|
6
|
+
if hash[:email]
|
7
|
+
self.resource = resource_class.where(:email => hash[:email], :encrypted_password => '').first
|
8
|
+
if self.resource
|
9
|
+
self.resource.attributes = hash
|
10
|
+
self.resource.accept_invitation!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
self.resource ||= super
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class DeviseInvitable::RegistrationsController < Devise::RegistrationsController
|
2
|
+
protected
|
3
|
+
|
4
|
+
def build_resource(*args)
|
5
|
+
hash = args.pop || resource_params || {}
|
6
|
+
if hash[:email]
|
7
|
+
self.resource = resource_class.where(:email => hash[:email], :encrypted_password => '').first
|
8
|
+
if self.resource
|
9
|
+
self.resource.attributes = hash
|
10
|
+
self.resource.accept_invitation!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
self.resource ||= super(hash, *args)
|
14
|
+
end
|
15
|
+
end
|
data/lib/devise_invitable.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
require 'devise'
|
2
|
-
|
3
1
|
module DeviseInvitable
|
4
2
|
autoload :Inviter, 'devise_invitable/inviter'
|
3
|
+
autoload :Mailer, 'devise_invitable/mailer'
|
4
|
+
autoload :Mapping, 'devise_invitable/mapping'
|
5
|
+
module Controllers
|
6
|
+
autoload :UrlHelpers, 'devise_invitable/controllers/url_helpers'
|
7
|
+
autoload :Registrations, 'devise_invitable/controllers/registrations'
|
8
|
+
autoload :Helpers, 'devise_invitable/controllers/helpers'
|
9
|
+
end
|
5
10
|
end
|
6
11
|
|
7
|
-
require '
|
12
|
+
require 'devise'
|
8
13
|
require 'devise_invitable/routes'
|
9
|
-
require 'devise_invitable/controllers/url_helpers'
|
10
|
-
require 'devise_invitable/controllers/registrations'
|
11
|
-
require 'devise_invitable/controllers/helpers'
|
12
14
|
require 'devise_invitable/rails'
|
13
15
|
|
14
16
|
module Devise
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module DeviseInvitable
|
2
|
+
autoload :Inviter, 'devise_invitable/inviter'
|
3
|
+
autoload :Mailer, 'devise_invitable/mailer'
|
4
|
+
module Controllers
|
5
|
+
autoload :UrlHelpers, 'devise_invitable/controllers/url_helpers'
|
6
|
+
autoload :Registrations, 'devise_invitable/controllers/registrations'
|
7
|
+
autoload :Helpers, 'devise_invitable/controllers/helpers'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'devise'
|
12
|
+
require 'devise_invitable/routes'
|
13
|
+
require 'devise_invitable/rails'
|
14
|
+
|
15
|
+
module Devise
|
16
|
+
# Public: Validity period of the invitation token (default: 0). If
|
17
|
+
# invite_for is 0 or nil, the invitation will never expire.
|
18
|
+
# Set invite_for in the Devise configuration file (in config/initializers/devise.rb).
|
19
|
+
#
|
20
|
+
# config.invite_for = 2.weeks # => The invitation token will be valid 2 weeks
|
21
|
+
mattr_accessor :invite_for
|
22
|
+
@@invite_for = 0
|
23
|
+
|
24
|
+
# Public: Flag that force a record to be valid before being actually invited
|
25
|
+
# (default: false).
|
26
|
+
#
|
27
|
+
# Examples (in config/initializers/devise.rb)
|
28
|
+
#
|
29
|
+
# config.validate_on_invite = true
|
30
|
+
mattr_accessor :validate_on_invite
|
31
|
+
@@validate_on_invite = false
|
32
|
+
|
33
|
+
# Public: number of invitations the user is allowed to send
|
34
|
+
#
|
35
|
+
# Examples (in config/initializers/devise.rb)
|
36
|
+
#
|
37
|
+
# config.invitation_limit = nil
|
38
|
+
mattr_accessor :invitation_limit
|
39
|
+
@@invitation_limit = nil
|
40
|
+
|
41
|
+
# Public: The key to be used to check existing users when sending an invitation,
|
42
|
+
# and the regexp used to test it when validate_on_invite is not set.
|
43
|
+
#
|
44
|
+
# Examples (in config/initializers/devise.rb)
|
45
|
+
#
|
46
|
+
# config.invite_key = {:email => /\A[^@]+@[^@]+\z/}
|
47
|
+
mattr_accessor :invite_key
|
48
|
+
@@invite_key = {:email => Devise.email_regexp}
|
49
|
+
|
50
|
+
# Public: Resend invitation if user with invited status is invited again
|
51
|
+
# (default: true)
|
52
|
+
#
|
53
|
+
# Example (in config/initializers/devise.rb)
|
54
|
+
#
|
55
|
+
# config.resend_invitation = false
|
56
|
+
mattr_accessor :resend_invitation
|
57
|
+
@@resend_invitation = true
|
58
|
+
|
59
|
+
# Public: The class name of the inviting model. If this is nil,
|
60
|
+
# the #invited_by association is declared to be polymorphic. (default: nil)
|
61
|
+
mattr_accessor :invited_by_class_name
|
62
|
+
@@invited_by_class_name = nil
|
63
|
+
end
|
64
|
+
|
65
|
+
Devise.add_module :invitable, :controller => :invitations, :model => 'devise_invitable/model', :route => :invitation
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DeviseInvitable::Controllers::Helpers
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
hide_action :after_invite_path_for, :after_accept_path_for
|
6
|
+
end
|
7
|
+
|
8
|
+
def after_invite_path_for(resource)
|
9
|
+
after_sign_in_path_for(resource)
|
10
|
+
end
|
11
|
+
|
12
|
+
def after_accept_path_for(resource)
|
13
|
+
after_sign_in_path_for(resource)
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
def authenticate_inviter!
|
18
|
+
send(:"authenticate_#{resource_name}!", :force => true)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -1,36 +1,21 @@
|
|
1
1
|
module DeviseInvitable::Controllers::Registrations
|
2
2
|
def self.included(controller)
|
3
|
-
controller.
|
3
|
+
controller.alias_method_chain :build_resource, :invitation
|
4
4
|
end
|
5
5
|
|
6
6
|
protected
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
invitation_info[:invited_by_type] = resource[:invited_by_type]
|
18
|
-
resource.destroy
|
8
|
+
def build_resource_with_invitation(*args)
|
9
|
+
hash = args.pop || resource_params || {}
|
10
|
+
if hash[:email]
|
11
|
+
self.resource = resource_class.where(:email => hash[:email], :encrypted_password => '').first
|
12
|
+
if self.resource
|
13
|
+
puts self.resource.inspect
|
14
|
+
self.resource.attributes = hash
|
15
|
+
self.resource.accept_invitation!
|
16
|
+
puts self.resource.inspect
|
19
17
|
end
|
20
18
|
end
|
21
|
-
|
22
|
-
# execute the action (create)
|
23
|
-
yield
|
24
|
-
# Note that the after_filter is executed at THIS position !
|
25
|
-
|
26
|
-
# Restore info about the last invitation (for later reference)
|
27
|
-
# Reset the invitation_info only, if invited_by_id is still nil at this stage:
|
28
|
-
resource = resource_class.where(:email => hash[:email], :invited_by_id => nil).first
|
29
|
-
if resource
|
30
|
-
resource[:invitation_sent_at] = invitation_info[:invitation_sent_at]
|
31
|
-
resource[:invited_by_id] = invitation_info[:invited_by_id]
|
32
|
-
resource[:invited_by_type] = invitation_info[:invited_by_type]
|
33
|
-
resource.save!
|
34
|
-
end
|
19
|
+
self.resource ||= build_resource_without_invitation(hash, *args)
|
35
20
|
end
|
36
21
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DeviseInvitable
|
2
|
+
module Mapping
|
3
|
+
def self.included(base)
|
4
|
+
base.alias_method_chain :default_controllers, :invitable
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
def default_controllers_with_invitable(options)
|
9
|
+
options[:controllers] ||= {}
|
10
|
+
options[:controllers][:registrations] ||= "devise_invitable/registrations"
|
11
|
+
default_controllers_without_invitable(options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
module DeviseInvitable
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
|
4
|
-
ActiveSupport.on_load(:action_controller)
|
4
|
+
ActiveSupport.on_load(:action_controller) do
|
5
|
+
include DeviseInvitable::Controllers::UrlHelpers
|
6
|
+
include DeviseInvitable::Controllers::Helpers
|
7
|
+
end
|
5
8
|
ActiveSupport.on_load(:action_view) { include DeviseInvitable::Controllers::UrlHelpers }
|
6
9
|
|
7
10
|
# We use to_prepare instead of after_initialize here because Devise is a Rails engine; its
|
@@ -10,7 +13,7 @@ module DeviseInvitable
|
|
10
13
|
config.to_prepare do
|
11
14
|
require 'devise/mailer'
|
12
15
|
Devise::Mailer.send :include, DeviseInvitable::Mailer
|
13
|
-
Devise::
|
16
|
+
Devise::Mapping.send :include, DeviseInvitable::Mapping
|
14
17
|
end
|
15
18
|
end
|
16
19
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DeviseInvitable
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
|
4
|
+
ActiveSupport.on_load(:action_controller) do
|
5
|
+
include DeviseInvitable::Controllers::UrlHelpers
|
6
|
+
include DeviseInvitable::Controllers::Helpers
|
7
|
+
end
|
8
|
+
ActiveSupport.on_load(:action_view) { include DeviseInvitable::Controllers::UrlHelpers }
|
9
|
+
|
10
|
+
# We use to_prepare instead of after_initialize here because Devise is a Rails engine; its
|
11
|
+
# mailer is reloaded like the rest of the user's app. Got to make sure that our mailer methods
|
12
|
+
# are included each time Devise::Mailer is (re)loaded.
|
13
|
+
config.to_prepare do
|
14
|
+
require 'devise/mailer'
|
15
|
+
Devise::Mailer.send :include, DeviseInvitable::Mailer
|
16
|
+
Devise::Mapping.send :include, DeviseInvitable::Mapping
|
17
|
+
end
|
18
|
+
config.after_initialize do
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_invitable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 3
|
10
|
+
version: 1.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sergio Cambra
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-11-
|
18
|
+
date: 2012-11-19 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: bundler
|
@@ -34,19 +34,18 @@ dependencies:
|
|
34
34
|
type: :development
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: railties
|
38
38
|
prerelease: false
|
39
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
hash:
|
44
|
+
hash: 7
|
45
45
|
segments:
|
46
|
-
-
|
47
|
-
- 1
|
46
|
+
- 3
|
48
47
|
- 0
|
49
|
-
version:
|
48
|
+
version: "3.0"
|
50
49
|
type: :runtime
|
51
50
|
version_requirements: *id002
|
52
51
|
- !ruby/object:Gem::Dependency
|
@@ -65,18 +64,19 @@ dependencies:
|
|
65
64
|
type: :runtime
|
66
65
|
version_requirements: *id003
|
67
66
|
- !ruby/object:Gem::Dependency
|
68
|
-
name:
|
67
|
+
name: devise
|
69
68
|
prerelease: false
|
70
69
|
requirement: &id004 !ruby/object:Gem::Requirement
|
71
70
|
none: false
|
72
71
|
requirements:
|
73
|
-
- -
|
72
|
+
- - ">="
|
74
73
|
- !ruby/object:Gem::Version
|
75
|
-
hash:
|
74
|
+
hash: 11
|
76
75
|
segments:
|
77
|
-
-
|
76
|
+
- 2
|
77
|
+
- 1
|
78
78
|
- 0
|
79
|
-
version:
|
79
|
+
version: 2.1.0
|
80
80
|
type: :runtime
|
81
81
|
version_requirements: *id004
|
82
82
|
description: It adds support for send invitations by email (it requires to be authenticated) and accept the invitation by setting a password.
|
@@ -90,6 +90,8 @@ extra_rdoc_files: []
|
|
90
90
|
|
91
91
|
files:
|
92
92
|
- app/controllers/devise/invitations_controller.rb
|
93
|
+
- app/controllers/devise_invitable/registrations_controller.rb
|
94
|
+
- app/controllers/devise_invitable/registrations_controller.rb~
|
93
95
|
- app/views/devise/invitations/edit.html.erb
|
94
96
|
- app/views/devise/invitations/new.html.erb
|
95
97
|
- app/views/devise/mailer/invitation_instructions.html.erb
|
@@ -102,9 +104,11 @@ files:
|
|
102
104
|
- lib/devise_invitable/version.rb
|
103
105
|
- lib/devise_invitable/controllers/helpers.rb
|
104
106
|
- lib/devise_invitable/controllers/url_helpers.rb
|
105
|
-
- lib/devise_invitable/controllers/registrations.rb
|
106
107
|
- lib/devise_invitable/controllers/registrations.rb~
|
108
|
+
- lib/devise_invitable/controllers/helpers.rb~
|
109
|
+
- lib/devise_invitable/rails.rb~
|
107
110
|
- lib/devise_invitable/inviter.rb
|
111
|
+
- lib/devise_invitable/mapping.rb
|
108
112
|
- lib/devise_invitable/model.rb~
|
109
113
|
- lib/generators/active_record/devise_invitable_generator.rb
|
110
114
|
- lib/generators/active_record/templates/migration.rb
|
@@ -114,6 +118,7 @@ files:
|
|
114
118
|
- lib/generators/devise_invitable/templates/simple_form_for/invitations/edit.html.erb
|
115
119
|
- lib/generators/devise_invitable/templates/simple_form_for/invitations/new.html.erb
|
116
120
|
- lib/generators/mongoid/devise_invitable_generator.rb
|
121
|
+
- lib/devise_invitable.rb~
|
117
122
|
- LICENSE
|
118
123
|
- README.rdoc
|
119
124
|
homepage: https://github.com/scambra/devise_invitable
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module DeviseInvitable::Controllers::Registrations
|
2
|
-
def self.included(controller)
|
3
|
-
controller.send :around_filter, :keep_invitation_info, :only => :create
|
4
|
-
end
|
5
|
-
|
6
|
-
protected
|
7
|
-
|
8
|
-
def destroy_if_previously_invited
|
9
|
-
hash = params[resource_name]
|
10
|
-
if hash && hash[:email]
|
11
|
-
resource = resource_class.where(:email => hash[:email], :encrypted_password => '').first
|
12
|
-
if resource
|
13
|
-
@invitation_info = Hash[resource.invitation_fields.map {|field|
|
14
|
-
[field, resource.send(field)]
|
15
|
-
}]
|
16
|
-
resource.destroy
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def keep_invitation_info
|
22
|
-
resource_invitable = resource_class.devise_modules.include?(:invitable)
|
23
|
-
destroy_if_previously_invited if resource_invitable
|
24
|
-
yield
|
25
|
-
reset_invitation_info if resource_invitable
|
26
|
-
end
|
27
|
-
|
28
|
-
def reset_invitation_info
|
29
|
-
# Restore info about the last invitation (for later reference)
|
30
|
-
# Reset the invitation_info only, if invited_by_id is still nil at this stage:
|
31
|
-
resource = resource_class.where(:email => params[resource_name][:email], :invited_by_id => nil).first rescue nil
|
32
|
-
if resource && @invitation_info
|
33
|
-
resource.invitation_fields.each do |field|
|
34
|
-
resource.send("#{field}=", @invitation_info[field])
|
35
|
-
end
|
36
|
-
resource.save!
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|