devise_invitable 0.4.0 → 0.6.0
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.
- data/README.rdoc +67 -7
- data/app/controllers/devise/invitations_controller.rb +17 -7
- data/app/views/devise/invitations/new.html.erb +1 -1
- data/lib/devise_invitable/controllers/helpers.rb +1 -1
- data/lib/devise_invitable/inviter.rb +39 -0
- data/lib/devise_invitable/mailer.rb +1 -6
- data/lib/devise_invitable/model.rb +46 -35
- data/lib/devise_invitable/rails.rb +4 -1
- data/lib/devise_invitable/schema.rb +2 -0
- data/lib/devise_invitable/version.rb +1 -1
- data/lib/devise_invitable.rb +13 -0
- data/lib/generators/active_record/templates/migration.rb +3 -2
- data/lib/generators/devise_invitable/install_generator.rb +4 -0
- data/lib/generators/devise_invitable/views_generator.rb +11 -2
- metadata +26 -13
data/README.rdoc
CHANGED
|
@@ -4,7 +4,7 @@ It adds support to devise[http://github.com/plataformatec/devise] for send invit
|
|
|
4
4
|
|
|
5
5
|
DeviseInvitable currently only support Rails 3, if you want to use it with Rails 2.3 you must install version {0.2.3}[http://rubygems.org/gems/devise_invitable/versions/0.2.3]
|
|
6
6
|
|
|
7
|
-
== Installation for Rails ~> 3.0 and Devise ~> 1.
|
|
7
|
+
== Installation for Rails ~> 3.0 and Devise ~> 1.2
|
|
8
8
|
|
|
9
9
|
Install DeviseInvitable gem, it will also install dependencies (such as devise and warden):
|
|
10
10
|
|
|
@@ -12,8 +12,8 @@ Install DeviseInvitable gem, it will also install dependencies (such as devise a
|
|
|
12
12
|
|
|
13
13
|
Add DeviseInvitable to your Gemfile (and Devise if you weren't using them):
|
|
14
14
|
|
|
15
|
-
gem 'devise', '~> 1.
|
|
16
|
-
gem 'devise_invitable', '~> 0.
|
|
15
|
+
gem 'devise', '~> 1.2.0'
|
|
16
|
+
gem 'devise_invitable', '~> 0.4.0'
|
|
17
17
|
|
|
18
18
|
=== Automatic installation
|
|
19
19
|
|
|
@@ -51,6 +51,7 @@ or for a model that already exists, define a migration to add DeviseInvitable to
|
|
|
51
51
|
change_table :users do |t|
|
|
52
52
|
t.string :invitation_token, :limit => 60
|
|
53
53
|
t.datetime :invitation_sent_at
|
|
54
|
+
t.datetime :invitation_accepted_at
|
|
54
55
|
t.index :invitation_token
|
|
55
56
|
end
|
|
56
57
|
|
|
@@ -61,7 +62,7 @@ or for a model that already exists, define a migration to add DeviseInvitable to
|
|
|
61
62
|
|
|
62
63
|
== Model configuration
|
|
63
64
|
|
|
64
|
-
DeviseInvitable adds
|
|
65
|
+
DeviseInvitable adds some new configuration options:
|
|
65
66
|
|
|
66
67
|
* 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
68
|
|
|
@@ -81,6 +82,10 @@ or directly as parameters to the <tt>devise</tt> method:
|
|
|
81
82
|
|
|
82
83
|
* 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
84
|
|
|
85
|
+
* validate_on_invite: force a record to be valid before being actually invited.
|
|
86
|
+
|
|
87
|
+
* resend_invitation: resend invitation if user with invited status is invited again. Enabled by default.
|
|
88
|
+
|
|
84
89
|
For more details, see <tt>config/initializers/devise.rb</tt> (after you invoked the "devise_invitable:install" generator described above).
|
|
85
90
|
|
|
86
91
|
== Configuring views
|
|
@@ -95,6 +100,28 @@ You can also use the generator to generate scoped views:
|
|
|
95
100
|
|
|
96
101
|
Please refer to {Devise's README}[http://github.com/plataformatec/devise] for more information about views.
|
|
97
102
|
|
|
103
|
+
== Configuring controllers
|
|
104
|
+
|
|
105
|
+
To change the controller's behavior, create a controller that inherits from <tt>Devise::InvitationsController</tt>. The available methods are: new, create, edit, and update. You should read the {original controllers source}[https://raw.github.com/scambra/devise_invitable/master/app/controllers/devise/invitations_controller.rb] before editing any of these actions. Your controller might now look something like this:
|
|
106
|
+
|
|
107
|
+
class Users::InvitationsController < Devise::InvitationsController
|
|
108
|
+
def update
|
|
109
|
+
if this
|
|
110
|
+
redirect_to root_path
|
|
111
|
+
else
|
|
112
|
+
super
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
Now just tell Devise that you want to use your controller, the controller above is 'users/invitations', so our routes.rb would have this line:
|
|
118
|
+
|
|
119
|
+
devise_for :users, :controllers => { :invitations => 'users/invitations' }
|
|
120
|
+
|
|
121
|
+
be sure that you generate the views and put them into the controller that you generated, so for this example it would be:
|
|
122
|
+
|
|
123
|
+
rails generate devise_invitable:views users/invitations
|
|
124
|
+
|
|
98
125
|
== Usage
|
|
99
126
|
|
|
100
127
|
=== Send an invitation
|
|
@@ -122,14 +149,28 @@ To accept an invitation with a token use the <tt>accept_invitation!</tt> class m
|
|
|
122
149
|
|
|
123
150
|
User.accept_invitation!(:invitation_token => params[:invitation_token], :password => "ad97nwj3o2", :name => "John Doe")
|
|
124
151
|
|
|
152
|
+
=== Callbacks
|
|
153
|
+
|
|
154
|
+
A callback event is fired before and after an invitation is accepted (User#accept_invitation!). For example, in your resource model you can add:
|
|
155
|
+
|
|
156
|
+
after_invitation_accepted :email_invited_by
|
|
157
|
+
|
|
158
|
+
def email_invited_by
|
|
159
|
+
# ...
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
The callbacks support all options and arguments available to the standard callbacks provided by AR.
|
|
163
|
+
|
|
125
164
|
== Integration in a Rails application
|
|
126
165
|
|
|
127
166
|
Since the invitations controller take care of all the creation/acceptation of an invitation, in most cases you wouldn't call the <tt>invite!</tt> and <tt>accept_invitation!</tt> methods directly.
|
|
128
167
|
Instead, in your views, put a link to <tt>new_user_invitation_path</tt> or <tt>new_invitation_path(:user)</tt> or even <tt>/users/invitation/new</tt> to prepare and send an invitation (to a user in this example).
|
|
129
|
-
|
|
168
|
+
|
|
169
|
+
After an invitation is created and sent, the inviter will be redirected to after_invite_path_for(resource_name), which is stored path or the same path as after_sign_in_path_for by default.
|
|
170
|
+
|
|
171
|
+
After an invitation is accepted, the invitee will be redirected to after_accept_path_for(resource), which is the same path as after_sign_in_path_for by default. If you want to override the path, override invitations controller and define after_accept_path_for method. This is useful in the common case that a user is invited to a specific location in your application. More on {Devise's README}[http://github.com/plataformatec/devise], "Controller filters and helpers" section.
|
|
130
172
|
|
|
131
173
|
The invitation email includes a link to accept the invitation that looks like this: <tt>/users/invitation/accept?invitation_token=abcd123</tt>. When clicked, the invited must set a password in order to accept its invitation. Note that if the invitation_token is not present or not valid, the invited is redirected to after_sign_out_path_for(resource_name).
|
|
132
|
-
You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize your redirect hooks. More on {Devise's README}[http://github.com/plataformatec/devise], "Controller filters and helpers" section.
|
|
133
174
|
|
|
134
175
|
The controller sets the invited_by_id attribute for the new user to the current user. This will let you easily keep track of who invited who.
|
|
135
176
|
|
|
@@ -144,10 +185,29 @@ You would have a User model which is configured as invitable and an Admin model
|
|
|
144
185
|
class ApplicationController < ActionController::Base
|
|
145
186
|
protected
|
|
146
187
|
def authenticate_inviter!
|
|
147
|
-
authenticate_admin!
|
|
188
|
+
authenticate_admin!(:force => true)
|
|
148
189
|
end
|
|
149
190
|
end
|
|
150
191
|
|
|
192
|
+
And include DeviseInvitable::Inviter module into Admin model:
|
|
193
|
+
|
|
194
|
+
class Admin < ActiveRecord::Base
|
|
195
|
+
devise :database_authenticatable, :validatable
|
|
196
|
+
include DeviseInvitable::Inviter
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
== Has many invitations
|
|
200
|
+
|
|
201
|
+
If you want to get all records invited by a resource, you should define has_many association in the model allowed to send invitations.
|
|
202
|
+
|
|
203
|
+
For the default behavior, define it like this:
|
|
204
|
+
|
|
205
|
+
has_many :invitations, :class_name => self.class.to_s, :as => :invited_by
|
|
206
|
+
|
|
207
|
+
For the previous example, where admins send invitations to users, define it like this:
|
|
208
|
+
|
|
209
|
+
has_many :invitations, :class_name => 'User', :as => :invited_by
|
|
210
|
+
|
|
151
211
|
== I18n
|
|
152
212
|
|
|
153
213
|
DeviseInvitable uses flash messages with I18n with the flash keys <tt>:send_instructions</tt>, <tt>:invitation_token_invalid</tt> and <tt>:updated</tt>. To customize your app, you can modify the generated locale file:
|
|
@@ -18,15 +18,15 @@ class Devise::InvitationsController < ApplicationController
|
|
|
18
18
|
|
|
19
19
|
if resource.errors.empty?
|
|
20
20
|
set_flash_message :notice, :send_instructions, :email => self.resource.email
|
|
21
|
-
|
|
21
|
+
respond_with resource, :location => after_invite_path_for(resource)
|
|
22
22
|
else
|
|
23
|
-
render_with_scope :new
|
|
23
|
+
respond_with_navigational(resource) { render_with_scope :new }
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
# GET /resource/invitation/accept?invitation_token=abcdef
|
|
28
28
|
def edit
|
|
29
|
-
if params[:invitation_token] && self.resource = resource_class.
|
|
29
|
+
if params[:invitation_token] && self.resource = resource_class.to_adapter.find_first( :invitation_token => params[:invitation_token] )
|
|
30
30
|
render_with_scope :edit
|
|
31
31
|
else
|
|
32
32
|
set_flash_message(:alert, :invitation_token_invalid)
|
|
@@ -40,9 +40,10 @@ class Devise::InvitationsController < ApplicationController
|
|
|
40
40
|
|
|
41
41
|
if resource.errors.empty?
|
|
42
42
|
set_flash_message :notice, :updated
|
|
43
|
-
|
|
43
|
+
sign_in(resource_name, resource)
|
|
44
|
+
respond_with resource, :location => after_accept_path_for(resource)
|
|
44
45
|
else
|
|
45
|
-
render_with_scope :edit
|
|
46
|
+
respond_with_navigational(resource){ render_with_scope :edit }
|
|
46
47
|
end
|
|
47
48
|
end
|
|
48
49
|
|
|
@@ -54,8 +55,17 @@ class Devise::InvitationsController < ApplicationController
|
|
|
54
55
|
def has_invitations_left?
|
|
55
56
|
unless current_inviter.nil? || current_inviter.has_invitations_left?
|
|
56
57
|
build_resource
|
|
57
|
-
set_flash_message :alert, :no_invitations_remaining
|
|
58
|
-
render_with_scope :new
|
|
58
|
+
set_flash_message :alert, :no_invitations_remaining
|
|
59
|
+
respond_with_navigational(resource) { render_with_scope :new }
|
|
59
60
|
end
|
|
60
61
|
end
|
|
62
|
+
|
|
63
|
+
def after_invite_path_for(resource)
|
|
64
|
+
redirect_location(resource_name, resource)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def after_accept_path_for(resource)
|
|
68
|
+
after_sign_in_path_for(resource)
|
|
69
|
+
end
|
|
61
70
|
end
|
|
71
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<h2>Send invitation</h2>
|
|
2
2
|
|
|
3
|
-
<%= form_for resource, :as => resource_name, :url => invitation_path(resource_name) do |f| %>
|
|
3
|
+
<%= form_for resource, :as => resource_name, :url => invitation_path(resource_name), :html => {:method => :post} do |f| %>
|
|
4
4
|
<%= devise_error_messages! %>
|
|
5
5
|
|
|
6
6
|
<p><%= f.label :email %><br />
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module DeviseInvitable::Controllers::Helpers
|
|
2
2
|
protected
|
|
3
3
|
def authenticate_inviter!
|
|
4
|
-
send(:"authenticate_#{resource_name}!", true)
|
|
4
|
+
send(:"authenticate_#{resource_name}!", :force => true)
|
|
5
5
|
end
|
|
6
6
|
end
|
|
7
7
|
ActionController::Base.send :include, DeviseInvitable::Controllers::Helpers
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module DeviseInvitable
|
|
2
|
+
module Inviter
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
included do
|
|
6
|
+
extend ClassMethods
|
|
7
|
+
attr_writer :invitation_limit unless respond_to? :invitation_limit
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def invitation_limit
|
|
11
|
+
self[:invitation_limit] || self.class.invitation_limit
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Return true if this user has invitations left to send
|
|
15
|
+
def has_invitations_left?
|
|
16
|
+
if self.class.invitation_limit.present?
|
|
17
|
+
if invitation_limit
|
|
18
|
+
return invitation_limit > 0
|
|
19
|
+
else
|
|
20
|
+
return self.class.invitation_limit > 0
|
|
21
|
+
end
|
|
22
|
+
else
|
|
23
|
+
return true
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
protected
|
|
28
|
+
def decrement_invitation_limit!
|
|
29
|
+
if self.class.invitation_limit.present?
|
|
30
|
+
self.invitation_limit ||= self.class.invitation_limit
|
|
31
|
+
self.update_attribute(:invitation_limit, invitation_limit - 1)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
module ClassMethods
|
|
36
|
+
Devise::Models.config(self, :invitation_limit)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -3,12 +3,7 @@ module DeviseInvitable
|
|
|
3
3
|
|
|
4
4
|
# Deliver an invitation email
|
|
5
5
|
def invitation_instructions(record)
|
|
6
|
-
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def invitation(record)
|
|
10
|
-
ActiveSupport::Deprecation.warn('invitation has been renamed to invitation_instructions')
|
|
11
|
-
invitation_instructions(record)
|
|
6
|
+
devise_mail(record, :invitation_instructions)
|
|
12
7
|
end
|
|
13
8
|
end
|
|
14
9
|
end
|
|
@@ -24,15 +24,22 @@ module Devise
|
|
|
24
24
|
attr_accessor :skip_invitation
|
|
25
25
|
|
|
26
26
|
included do
|
|
27
|
+
include ::DeviseInvitable::Inviter
|
|
27
28
|
belongs_to :invited_by, :polymorphic => true
|
|
29
|
+
|
|
30
|
+
include ActiveSupport::Callbacks
|
|
31
|
+
define_callbacks :invitation_accepted
|
|
28
32
|
end
|
|
29
33
|
|
|
30
34
|
# Accept an invitation by clearing invitation token and confirming it if model
|
|
31
35
|
# is confirmable
|
|
32
36
|
def accept_invitation!
|
|
33
37
|
if self.invited? && self.valid?
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
run_callbacks :invitation_accepted do
|
|
39
|
+
self.invitation_token = nil
|
|
40
|
+
self.invitation_accepted_at = Time.now.utc if respond_to? :"invitation_accepted_at="
|
|
41
|
+
self.save(:validate => false)
|
|
42
|
+
end
|
|
36
43
|
end
|
|
37
44
|
end
|
|
38
45
|
|
|
@@ -41,30 +48,16 @@ module Devise
|
|
|
41
48
|
persisted? && invitation_token.present?
|
|
42
49
|
end
|
|
43
50
|
|
|
44
|
-
# Return true if this user has invitations left to send
|
|
45
|
-
def has_invitations_left?
|
|
46
|
-
if self.class.invitation_limit.present?
|
|
47
|
-
if invitation_limit
|
|
48
|
-
return invitation_limit > 0
|
|
49
|
-
else
|
|
50
|
-
return self.class.invitation_limit > 0
|
|
51
|
-
end
|
|
52
|
-
else
|
|
53
|
-
return true
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
51
|
# Reset invitation token and send invitation again
|
|
58
52
|
def invite!
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
end
|
|
53
|
+
@skip_password = true
|
|
54
|
+
was_invited = invited?
|
|
55
|
+
self.skip_confirmation! if self.new_record? && self.respond_to?(:skip_confirmation!)
|
|
56
|
+
generate_invitation_token if self.invitation_token.nil?
|
|
57
|
+
self.invitation_sent_at = Time.now.utc
|
|
58
|
+
if save(:validate => false)
|
|
59
|
+
self.invited_by.decrement_invitation_limit! if !was_invited and self.invited_by.present?
|
|
60
|
+
deliver_invitation unless @skip_invitation
|
|
68
61
|
end
|
|
69
62
|
end
|
|
70
63
|
|
|
@@ -81,13 +74,6 @@ module Devise
|
|
|
81
74
|
end
|
|
82
75
|
|
|
83
76
|
protected
|
|
84
|
-
def decrement_invitation_limit!
|
|
85
|
-
if self.class.invitation_limit.present?
|
|
86
|
-
self.invitation_limit ||= self.class.invitation_limit
|
|
87
|
-
self.decrement!(:invitation_limit)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
77
|
# Overriding the method in Devise's :validatable module so password is not required on inviting
|
|
92
78
|
def password_required?
|
|
93
79
|
!@skip_password && super
|
|
@@ -137,25 +123,38 @@ module Devise
|
|
|
137
123
|
# Attempt to find a user by it's email. If a record is not found, create a new
|
|
138
124
|
# user and send invitation to it. If user is found, returns the user with an
|
|
139
125
|
# email already exists error.
|
|
126
|
+
# If user is found and still have pending invitation, email is resend unless
|
|
127
|
+
# resend_invitation is set to false
|
|
140
128
|
# Attributes must contain the user email, other attributes will be set in the record
|
|
141
|
-
def
|
|
129
|
+
def _invite(attributes={}, invited_by=nil, &block)
|
|
142
130
|
invitable = find_or_initialize_with_error_by(invite_key, attributes.delete(invite_key))
|
|
143
131
|
invitable.attributes = attributes
|
|
144
132
|
invitable.invited_by = invited_by
|
|
145
133
|
|
|
134
|
+
invitable.valid? if self.validate_on_invite
|
|
146
135
|
if invitable.new_record?
|
|
147
|
-
invitable.errors.clear if invitable.email.try(:match, Devise.email_regexp)
|
|
136
|
+
invitable.errors.clear if !self.validate_on_invite and invitable.email.try(:match, Devise.email_regexp)
|
|
148
137
|
else
|
|
149
|
-
invitable.errors.add(invite_key, :taken) unless invitable.invited?
|
|
138
|
+
invitable.errors.add(invite_key, :taken) unless invitable.invited? && self.resend_invitation
|
|
150
139
|
end
|
|
151
140
|
|
|
152
141
|
if invitable.errors.empty?
|
|
153
142
|
yield invitable if block_given?
|
|
154
|
-
invitable.invite!
|
|
143
|
+
mail = invitable.invite!
|
|
155
144
|
end
|
|
145
|
+
[invitable, mail]
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def invite!(attributes={}, invited_by=nil, &block)
|
|
149
|
+
invitable, mail = _invite(attributes, invited_by, &block)
|
|
156
150
|
invitable
|
|
157
151
|
end
|
|
158
152
|
|
|
153
|
+
def invite_mail!(attributes={}, invited_by=nil, &block)
|
|
154
|
+
invitable, mail = _invite(attributes, invited_by, &block)
|
|
155
|
+
mail
|
|
156
|
+
end
|
|
157
|
+
|
|
159
158
|
# Attempt to find a user by it's invitation_token to set it's password.
|
|
160
159
|
# If a user is found, reset it's password and automatically try saving
|
|
161
160
|
# the record. If not user is found, returns a new user containing an
|
|
@@ -175,12 +174,24 @@ module Devise
|
|
|
175
174
|
def invitation_token
|
|
176
175
|
generate_token(:invitation_token)
|
|
177
176
|
end
|
|
177
|
+
|
|
178
|
+
# Callback convenience methods
|
|
179
|
+
def before_invitation_accepted(*args, &blk)
|
|
180
|
+
set_callback(:invitation_accepted, :before, *args, &blk)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def after_invitation_accepted(*args, &blk)
|
|
184
|
+
set_callback(:invitation_accepted, :after, *args, &blk)
|
|
185
|
+
end
|
|
186
|
+
|
|
178
187
|
|
|
179
188
|
Devise::Models.config(self, :invite_for)
|
|
180
189
|
Devise::Models.config(self, :validate_on_invite)
|
|
181
190
|
Devise::Models.config(self, :invitation_limit)
|
|
182
191
|
Devise::Models.config(self, :invite_key)
|
|
192
|
+
Devise::Models.config(self, :resend_invitation)
|
|
183
193
|
end
|
|
184
194
|
end
|
|
185
195
|
end
|
|
186
196
|
end
|
|
197
|
+
|
|
@@ -4,7 +4,10 @@ module DeviseInvitable
|
|
|
4
4
|
ActiveSupport.on_load(:action_controller) { include DeviseInvitable::Controllers::UrlHelpers }
|
|
5
5
|
ActiveSupport.on_load(:action_view) { include DeviseInvitable::Controllers::UrlHelpers }
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
# We use to_prepare instead of after_initialize here because Devise is a Rails engine; its
|
|
8
|
+
# mailer is reloaded like the rest of the user's app. Got to make sure that our mailer methods
|
|
9
|
+
# are included each time Devise::Mailer is (re)loaded.
|
|
10
|
+
config.to_prepare do
|
|
8
11
|
require 'devise/mailer'
|
|
9
12
|
Devise::Mailer.send :include, DeviseInvitable::Mailer
|
|
10
13
|
end
|
|
@@ -16,6 +16,7 @@ module DeviseInvitable
|
|
|
16
16
|
# change_table :the_resources do |t|
|
|
17
17
|
# t.string :invitation_token, :limit => 60
|
|
18
18
|
# t.datetime :invitation_sent_at
|
|
19
|
+
# t.datetime :invitation_accepted_at
|
|
19
20
|
# t.index :invitation_token # for invitable
|
|
20
21
|
# end
|
|
21
22
|
#
|
|
@@ -26,6 +27,7 @@ module DeviseInvitable
|
|
|
26
27
|
def invitable
|
|
27
28
|
apply_devise_schema :invitation_token, String, :limit => 60
|
|
28
29
|
apply_devise_schema :invitation_sent_at, DateTime
|
|
30
|
+
apply_devise_schema :invitation_accepted_at, DateTime
|
|
29
31
|
apply_devise_schema :invitation_limit, Integer
|
|
30
32
|
apply_devise_schema :invited_by_id, Integer
|
|
31
33
|
apply_devise_schema :invited_by_type, String
|
data/lib/devise_invitable.rb
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
require 'devise'
|
|
2
2
|
|
|
3
|
+
module DeviseInvitable
|
|
4
|
+
autoload :Inviter, 'devise_invitable/inviter'
|
|
5
|
+
end
|
|
6
|
+
|
|
3
7
|
require 'devise_invitable/mailer'
|
|
4
8
|
require 'devise_invitable/routes'
|
|
5
9
|
require 'devise_invitable/schema'
|
|
@@ -40,6 +44,15 @@ module Devise
|
|
|
40
44
|
# config.invite_key = :email
|
|
41
45
|
mattr_accessor :invite_key
|
|
42
46
|
@@invite_key = :email
|
|
47
|
+
|
|
48
|
+
# Public: Resend invitation if user with invited status is invited again
|
|
49
|
+
# (default: true)
|
|
50
|
+
#
|
|
51
|
+
# Example (in config/initializers/devise.rb)
|
|
52
|
+
#
|
|
53
|
+
# config.resend_invitation = false
|
|
54
|
+
mattr_accessor :resend_invitation
|
|
55
|
+
@@resend_invitation = true
|
|
43
56
|
end
|
|
44
57
|
|
|
45
58
|
Devise.add_module :invitable, :controller => :invitations, :model => 'devise_invitable/model', :route => :invitation
|
|
@@ -3,6 +3,7 @@ class DeviseInvitableAddTo<%= table_name.camelize %> < ActiveRecord::Migration
|
|
|
3
3
|
change_table :<%= table_name %> do |t|
|
|
4
4
|
t.string :invitation_token, :limit => 60
|
|
5
5
|
t.datetime :invitation_sent_at
|
|
6
|
+
t.datetime :invitation_accepted_at
|
|
6
7
|
t.integer :invitation_limit
|
|
7
8
|
t.references :invited_by, :polymorphic => true
|
|
8
9
|
t.index :invitation_token # for invitable
|
|
@@ -18,8 +19,8 @@ class DeviseInvitableAddTo<%= table_name.camelize %> < ActiveRecord::Migration
|
|
|
18
19
|
|
|
19
20
|
def self.down
|
|
20
21
|
change_table :<%= table_name %> do |t|
|
|
21
|
-
remove_references :invited_by, :polymorphic => true
|
|
22
|
-
remove :invitation_limit, :invitation_sent_at, :invitation_token
|
|
22
|
+
t.remove_references :invited_by, :polymorphic => true
|
|
23
|
+
t.remove :invitation_limit, :invitation_sent_at, :invitation_accepted_at, :invitation_token
|
|
23
24
|
end
|
|
24
25
|
end
|
|
25
26
|
end
|
|
@@ -34,6 +34,10 @@ module DeviseInvitable
|
|
|
34
34
|
# The key to be used to check existing users when sending an invitation
|
|
35
35
|
# config.invite_key = :email
|
|
36
36
|
|
|
37
|
+
# Flag that force a record to be valid before being actually invited
|
|
38
|
+
# Default: false
|
|
39
|
+
# config.validate_on_invite = true
|
|
40
|
+
|
|
37
41
|
CONTENT
|
|
38
42
|
end
|
|
39
43
|
end
|
|
@@ -2,9 +2,18 @@ require 'generators/devise/views_generator'
|
|
|
2
2
|
|
|
3
3
|
module DeviseInvitable
|
|
4
4
|
module Generators
|
|
5
|
-
class ViewsGenerator <
|
|
6
|
-
source_root File.expand_path("../../../../app/views", __FILE__)
|
|
5
|
+
class ViewsGenerator < Rails::Generators::Base
|
|
7
6
|
desc 'Copies all DeviseInvitable views to your application.'
|
|
7
|
+
|
|
8
|
+
argument :scope, :required => false, :default => nil,
|
|
9
|
+
:desc => "The scope to copy views to"
|
|
10
|
+
|
|
11
|
+
include ::Devise::Generators::ViewPathTemplates
|
|
12
|
+
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
|
13
|
+
def copy_views
|
|
14
|
+
view_directory :invitations
|
|
15
|
+
view_directory :mailer
|
|
16
|
+
end
|
|
8
17
|
end
|
|
9
18
|
end
|
|
10
19
|
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: 7
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
8
|
+
- 6
|
|
9
9
|
- 0
|
|
10
|
-
version: 0.
|
|
10
|
+
version: 0.6.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Sergio Cambra
|
|
@@ -15,8 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2011-
|
|
19
|
-
default_executable:
|
|
18
|
+
date: 2011-11-15 00:00:00 Z
|
|
20
19
|
dependencies:
|
|
21
20
|
- !ruby/object:Gem::Dependency
|
|
22
21
|
name: bundler
|
|
@@ -40,7 +39,7 @@ dependencies:
|
|
|
40
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
41
40
|
none: false
|
|
42
41
|
requirements:
|
|
43
|
-
- -
|
|
42
|
+
- - ">="
|
|
44
43
|
- !ruby/object:Gem::Version
|
|
45
44
|
hash: 7
|
|
46
45
|
segments:
|
|
@@ -48,6 +47,13 @@ dependencies:
|
|
|
48
47
|
- 0
|
|
49
48
|
- 0
|
|
50
49
|
version: 3.0.0
|
|
50
|
+
- - <
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
hash: 3
|
|
53
|
+
segments:
|
|
54
|
+
- 3
|
|
55
|
+
- 2
|
|
56
|
+
version: "3.2"
|
|
51
57
|
type: :runtime
|
|
52
58
|
version_requirements: *id002
|
|
53
59
|
- !ruby/object:Gem::Dependency
|
|
@@ -56,14 +62,21 @@ dependencies:
|
|
|
56
62
|
requirement: &id003 !ruby/object:Gem::Requirement
|
|
57
63
|
none: false
|
|
58
64
|
requirements:
|
|
59
|
-
- -
|
|
65
|
+
- - ">="
|
|
60
66
|
- !ruby/object:Gem::Version
|
|
61
|
-
hash:
|
|
67
|
+
hash: 11
|
|
62
68
|
segments:
|
|
63
69
|
- 1
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
version: 1.
|
|
70
|
+
- 4
|
|
71
|
+
- 6
|
|
72
|
+
version: 1.4.6
|
|
73
|
+
- - <
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
hash: 3
|
|
76
|
+
segments:
|
|
77
|
+
- 1
|
|
78
|
+
- 6
|
|
79
|
+
version: "1.6"
|
|
67
80
|
type: :runtime
|
|
68
81
|
version_requirements: *id003
|
|
69
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 +103,7 @@ files:
|
|
|
90
103
|
- lib/devise_invitable/controllers/helpers.rb
|
|
91
104
|
- lib/devise_invitable/controllers/url_helpers.rb
|
|
92
105
|
- lib/devise_invitable/version.rb
|
|
106
|
+
- lib/devise_invitable/inviter.rb
|
|
93
107
|
- lib/generators/active_record/devise_invitable_generator.rb
|
|
94
108
|
- lib/generators/active_record/templates/migration.rb
|
|
95
109
|
- lib/generators/devise_invitable/views_generator.rb
|
|
@@ -98,7 +112,6 @@ files:
|
|
|
98
112
|
- lib/generators/mongoid/devise_invitable_generator.rb
|
|
99
113
|
- LICENSE
|
|
100
114
|
- README.rdoc
|
|
101
|
-
has_rdoc: true
|
|
102
115
|
homepage: https://github.com/scambra/devise_invitable
|
|
103
116
|
licenses: []
|
|
104
117
|
|
|
@@ -134,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
134
147
|
requirements: []
|
|
135
148
|
|
|
136
149
|
rubyforge_project:
|
|
137
|
-
rubygems_version: 1.
|
|
150
|
+
rubygems_version: 1.8.10
|
|
138
151
|
signing_key:
|
|
139
152
|
specification_version: 3
|
|
140
153
|
summary: An invitation strategy for Devise
|