devise_invitable 0.4.rc2 → 0.4.rc3
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/README.rdoc
CHANGED
@@ -61,7 +61,7 @@ or for a model that already exists, define a migration to add DeviseInvitable to
|
|
61
61
|
|
62
62
|
== Model configuration
|
63
63
|
|
64
|
-
DeviseInvitable adds
|
64
|
+
DeviseInvitable adds three new configuration options:
|
65
65
|
|
66
66
|
* invite_for: The period the generated invitation token is valid, after this period, the invited resource won't be able to accept the invitation. When invite_for is 0 (the default), the invitation won't expire.
|
67
67
|
|
@@ -79,6 +79,8 @@ or directly as parameters to the <tt>devise</tt> method:
|
|
79
79
|
|
80
80
|
* invitation_limit: The number of invitations users can send. The default value of nil means users can send as many invites as they want. A setting of 0 means they can't send invitations. A setting n > 0 means they can send n invitations.
|
81
81
|
|
82
|
+
* invite_key: The key to be used to check existing users when sending an invitation. The key must be an unique field. The default value is looking for users by email.
|
83
|
+
|
82
84
|
For more details, see <tt>config/initializers/devise.rb</tt> (after you invoked the "devise_invitable:install" generator described above).
|
83
85
|
|
84
86
|
== Configuring views
|
@@ -14,12 +14,12 @@ class Devise::InvitationsController < ApplicationController
|
|
14
14
|
|
15
15
|
# POST /resource/invitation
|
16
16
|
def create
|
17
|
-
self.resource = resource_class.invite!(params[resource_name],
|
17
|
+
self.resource = resource_class.invite!(params[resource_name], current_inviter)
|
18
18
|
|
19
19
|
if resource.errors.empty?
|
20
|
-
if resource_class.invitation_limit.present?
|
21
|
-
|
22
|
-
|
20
|
+
if resource_class.invitation_limit.present? && current_inviter
|
21
|
+
current_inviter.invitation_limit ||= resource_class.invitation_limit
|
22
|
+
current_inviter.decrement!(:invitation_limit)
|
23
23
|
end
|
24
24
|
set_flash_message :notice, :send_instructions, :email => self.resource.email
|
25
25
|
redirect_to after_sign_in_path_for(resource_name)
|
@@ -51,11 +51,14 @@ class Devise::InvitationsController < ApplicationController
|
|
51
51
|
end
|
52
52
|
|
53
53
|
protected
|
54
|
+
def current_inviter
|
55
|
+
@current_inviter ||= authenticate_inviter!
|
56
|
+
end
|
54
57
|
|
55
58
|
def has_invitations_left?
|
56
|
-
|
59
|
+
unless current_inviter.nil? || current_inviter.has_invitations_left?
|
57
60
|
build_resource
|
58
|
-
set_flash_message :
|
61
|
+
set_flash_message :alert, :no_invitations_remaining
|
59
62
|
render_with_scope :new
|
60
63
|
end
|
61
64
|
end
|
data/lib/devise_invitable.rb
CHANGED
@@ -19,6 +19,10 @@ module Devise
|
|
19
19
|
# config.invitation_limit = nil
|
20
20
|
mattr_accessor :invitation_limit
|
21
21
|
@@invitation_limit = nil
|
22
|
+
|
23
|
+
# The key to be used to check existing users when sending an invitation
|
24
|
+
mattr_accessor :invite_key
|
25
|
+
@@invite_key = :email
|
22
26
|
end
|
23
27
|
|
24
28
|
Devise.add_module :invitable, :controller => :invitations, :model => 'devise_invitable/model', :route => :invitation
|
@@ -70,8 +70,19 @@ module Devise
|
|
70
70
|
invited? && invitation_period_valid?
|
71
71
|
end
|
72
72
|
|
73
|
+
# Only verify password when is not invited
|
74
|
+
def valid_password?(password)
|
75
|
+
super unless invited?
|
76
|
+
end
|
77
|
+
|
73
78
|
protected
|
74
79
|
|
80
|
+
# Clear invitation token when reset password token is cleared too
|
81
|
+
def clear_reset_password_token
|
82
|
+
self.invitation_token = nil if invited?
|
83
|
+
super
|
84
|
+
end
|
85
|
+
|
75
86
|
# Checks if the invitation for the user is within the limit time.
|
76
87
|
# We do this by calculating if the difference between today and the
|
77
88
|
# invitation sent date does not exceed the invite for time configured.
|
@@ -107,14 +118,14 @@ module Devise
|
|
107
118
|
# email already exists error.
|
108
119
|
# Attributes must contain the user email, other attributes will be set in the record
|
109
120
|
def invite!(attributes={}, invited_by=nil)
|
110
|
-
invitable = find_or_initialize_with_error_by(
|
121
|
+
invitable = find_or_initialize_with_error_by(invite_key, attributes.delete(invite_key))
|
111
122
|
invitable.attributes = attributes
|
112
123
|
invitable.invited_by = invited_by
|
113
124
|
|
114
125
|
if invitable.new_record?
|
115
126
|
invitable.errors.clear if invitable.email.try(:match, Devise.email_regexp)
|
116
127
|
else
|
117
|
-
invitable.errors.add(
|
128
|
+
invitable.errors.add(invite_key, :taken) unless invitable.invited?
|
118
129
|
end
|
119
130
|
|
120
131
|
invitable.invite! if invitable.errors.empty?
|
@@ -143,6 +154,7 @@ module Devise
|
|
143
154
|
|
144
155
|
Devise::Models.config(self, :invite_for)
|
145
156
|
Devise::Models.config(self, :invitation_limit)
|
157
|
+
Devise::Models.config(self, :invite_key)
|
146
158
|
end
|
147
159
|
end
|
148
160
|
end
|
@@ -24,6 +24,16 @@ module DeviseInvitable
|
|
24
24
|
# When invite_for is 0 (the default), the invitation won't expire.
|
25
25
|
# config.invite_for = 2.weeks
|
26
26
|
|
27
|
+
# Number of invitations users can send.
|
28
|
+
# If invitation_limit is nil, users can send unlimited invitations.
|
29
|
+
# If invitation_limit is 0, users can't send invitations.
|
30
|
+
# If invitation_limit n > 0, users can send n invitations.
|
31
|
+
# Default: nil
|
32
|
+
# config.invitation_limit = 5
|
33
|
+
|
34
|
+
# The key to be used to check existing users when sending an invitation
|
35
|
+
# config.invite_key = :email
|
36
|
+
|
27
37
|
CONTENT
|
28
38
|
end
|
29
39
|
end
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_invitable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15424195
|
5
|
+
prerelease: 4
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
|
9
|
+
- rc
|
10
|
+
- 3
|
11
|
+
version: 0.4.rc3
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Sergio Cambra
|
@@ -15,29 +16,13 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2011-02-
|
19
|
+
date: 2011-02-23 00:00:00 +01:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
name: rspec-rails
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 27
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 5
|
33
|
-
- 0
|
34
|
-
version: 2.5.0
|
35
|
-
type: :development
|
36
|
-
version_requirements: *id001
|
37
22
|
- !ruby/object:Gem::Dependency
|
38
23
|
name: bundler
|
39
24
|
prerelease: false
|
40
|
-
requirement: &
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
41
26
|
none: false
|
42
27
|
requirements:
|
43
28
|
- - ~>
|
@@ -49,11 +34,11 @@ dependencies:
|
|
49
34
|
- 7
|
50
35
|
version: 1.0.7
|
51
36
|
type: :development
|
52
|
-
version_requirements: *
|
37
|
+
version_requirements: *id001
|
53
38
|
- !ruby/object:Gem::Dependency
|
54
39
|
name: rails
|
55
40
|
prerelease: false
|
56
|
-
requirement: &
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
57
42
|
none: false
|
58
43
|
requirements:
|
59
44
|
- - ~>
|
@@ -65,11 +50,11 @@ dependencies:
|
|
65
50
|
- 0
|
66
51
|
version: 3.0.0
|
67
52
|
type: :runtime
|
68
|
-
version_requirements: *
|
53
|
+
version_requirements: *id002
|
69
54
|
- !ruby/object:Gem::Dependency
|
70
55
|
name: devise
|
71
56
|
prerelease: false
|
72
|
-
requirement: &
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
73
58
|
none: false
|
74
59
|
requirements:
|
75
60
|
- - ~>
|
@@ -81,7 +66,7 @@ dependencies:
|
|
81
66
|
- rc
|
82
67
|
version: 1.2.rc
|
83
68
|
type: :runtime
|
84
|
-
version_requirements: *
|
69
|
+
version_requirements: *id003
|
85
70
|
description: It adds support for send invitations by email (it requires to be authenticated) and accept the invitation by setting a password.
|
86
71
|
email:
|
87
72
|
- sergio@entrecables.com
|
@@ -151,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
136
|
requirements: []
|
152
137
|
|
153
138
|
rubyforge_project:
|
154
|
-
rubygems_version: 1.
|
139
|
+
rubygems_version: 1.5.2
|
155
140
|
signing_key:
|
156
141
|
specification_version: 3
|
157
142
|
summary: An invitation strategy for Devise
|