devise_invitable 1.1.8 → 1.2.1
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.
Potentially problematic release.
This version of devise_invitable might be problematic. Click here for more details.
- data/README.rdoc +12 -2
- data/app/controllers/devise/invitations_controller.rb +13 -5
- data/app/controllers/devise_invitable/registrations_controller.rb +2 -2
- data/lib/devise_invitable.rb +1 -0
- data/lib/devise_invitable/model.rb +18 -22
- data/lib/devise_invitable/parameter_sanitizer.rb +11 -0
- data/lib/devise_invitable/rails.rb +1 -0
- data/lib/devise_invitable/version.rb +1 -1
- data/lib/generators/active_record/templates/migration.rb +2 -1
- data/test/functional/controller_helpers_test.rb +39 -0
- data/test/functional/registrations_controller_test.rb +59 -0
- data/test/generators/views_generator_test.rb +40 -0
- data/test/generators_test.rb +34 -0
- data/test/integration/invitation_remove_test.rb +29 -0
- data/test/integration/invitation_test.rb +223 -0
- data/test/integration_tests_helper.rb +48 -0
- data/test/mailers/invitation_mail_test.rb +59 -0
- data/test/model_tests_helper.rb +33 -0
- data/test/models/invitable_test.rb +533 -0
- data/test/models_test.rb +74 -0
- data/test/orm/active_record.rb +4 -0
- data/test/orm/mongoid.rb +20 -0
- data/test/rails_app/Rakefile +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +10 -0
- data/test/rails_app/app/controllers/free_invitations_controller.rb +6 -0
- data/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/app/controllers/users_controller.rb +12 -0
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/rails_app/app/models/admin.rb +23 -0
- data/test/rails_app/app/models/octopussy.rb +15 -0
- data/test/rails_app/app/models/user.rb +51 -0
- data/test/rails_app/app/views/admins/new.html.erb +12 -0
- data/test/rails_app/app/views/free_invitations/new.html.erb +12 -0
- data/test/rails_app/app/views/home/index.html.erb +0 -0
- data/test/rails_app/app/views/layouts/application.html.erb +16 -0
- data/test/rails_app/app/views/users/invitations/new.html.erb +15 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +24 -0
- data/test/rails_app/config/boot.rb +11 -0
- data/test/rails_app/config/database.yml +22 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +25 -0
- data/test/rails_app/config/environments/production.rb +49 -0
- data/test/rails_app/config/environments/test.rb +33 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +207 -0
- data/test/rails_app/config/initializers/inflections.rb +10 -0
- data/test/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/rails_app/config/initializers/session_store.rb +8 -0
- data/test/rails_app/config/initializers/wrap_parameters.rb +14 -0
- data/test/rails_app/config/locales/devise.en.yml +57 -0
- data/test/rails_app/config/locales/en.yml +14 -0
- data/test/rails_app/config/routes.rb +9 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +39 -0
- data/test/rails_app/mongoid.yml +10 -0
- data/test/rails_app/script/rails +6 -0
- data/test/routes_test.rb +20 -0
- data/test/test_helper.rb +24 -0
- metadata +128 -40
- data/app/controllers/devise_invitable/registrations_controller.rb~ +0 -15
- data/lib/devise_invitable.rb~ +0 -65
- data/lib/devise_invitable/controllers/helpers.rb~ +0 -21
- data/lib/devise_invitable/controllers/registrations.rb~ +0 -21
- data/lib/devise_invitable/model.rb~ +0 -224
- data/lib/devise_invitable/rails.rb~ +0 -21
data/test/routes_test.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RoutesTest < ActionController::TestCase
|
4
|
+
|
5
|
+
test 'map new user invitation' do
|
6
|
+
assert_recognizes({:controller => 'devise/invitations', :action => 'new'}, {:path => 'users/invitation/new', :method => :get})
|
7
|
+
end
|
8
|
+
|
9
|
+
test 'map create user invitation' do
|
10
|
+
assert_recognizes({:controller => 'devise/invitations', :action => 'create'}, {:path => 'users/invitation', :method => :post})
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'map accept user invitation' do
|
14
|
+
assert_recognizes({:controller => 'devise/invitations', :action => 'edit'}, 'users/invitation/accept')
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'map update user invitation' do
|
18
|
+
assert_recognizes({:controller => 'devise/invitations', :action => 'update'}, {:path => 'users/invitation', :method => :put})
|
19
|
+
end
|
20
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
DEVISE_ORM = (ENV["DEVISE_ORM"] || :active_record).to_sym
|
3
|
+
|
4
|
+
$:.unshift File.dirname(__FILE__)
|
5
|
+
puts "\n==> Devise.orm = #{DEVISE_ORM.inspect}"
|
6
|
+
require "rails_app/config/environment"
|
7
|
+
include Devise::TestHelpers
|
8
|
+
require "orm/#{DEVISE_ORM}"
|
9
|
+
require 'rails/test_help'
|
10
|
+
require 'capybara/rails'
|
11
|
+
require 'mocha/setup'
|
12
|
+
|
13
|
+
ActionMailer::Base.delivery_method = :test
|
14
|
+
ActionMailer::Base.perform_deliveries = true
|
15
|
+
ActionMailer::Base.default_url_options[:host] = 'test.com'
|
16
|
+
|
17
|
+
ActiveSupport::Deprecation.silenced = true
|
18
|
+
|
19
|
+
class ActionDispatch::IntegrationTest
|
20
|
+
include Capybara::DSL
|
21
|
+
end
|
22
|
+
class ActionController::TestCase
|
23
|
+
include Devise::TestHelpers
|
24
|
+
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: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 2
|
8
9
|
- 1
|
9
|
-
|
10
|
-
version: 1.1.8
|
10
|
+
version: 1.2.1
|
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: 2013-
|
18
|
+
date: 2013-08-22 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: bundler
|
@@ -34,22 +34,29 @@ dependencies:
|
|
34
34
|
type: :development
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: actionmailer
|
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: 3
|
45
45
|
segments:
|
46
46
|
- 3
|
47
|
-
-
|
48
|
-
|
47
|
+
- 2
|
48
|
+
- 6
|
49
|
+
version: 3.2.6
|
50
|
+
- - <
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
hash: 9
|
53
|
+
segments:
|
54
|
+
- 5
|
55
|
+
version: "5"
|
49
56
|
type: :runtime
|
50
57
|
version_requirements: *id002
|
51
58
|
- !ruby/object:Gem::Dependency
|
52
|
-
name:
|
59
|
+
name: devise
|
53
60
|
prerelease: false
|
54
61
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
62
|
none: false
|
@@ -60,25 +67,10 @@ dependencies:
|
|
60
67
|
segments:
|
61
68
|
- 3
|
62
69
|
- 0
|
63
|
-
|
70
|
+
- 0
|
71
|
+
version: 3.0.0
|
64
72
|
type: :runtime
|
65
73
|
version_requirements: *id003
|
66
|
-
- !ruby/object:Gem::Dependency
|
67
|
-
name: devise
|
68
|
-
prerelease: false
|
69
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
|
-
requirements:
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
hash: 15
|
75
|
-
segments:
|
76
|
-
- 2
|
77
|
-
- 1
|
78
|
-
- 2
|
79
|
-
version: 2.1.2
|
80
|
-
type: :runtime
|
81
|
-
version_requirements: *id004
|
82
74
|
description: It adds support for send invitations by email (it requires to be authenticated) and accept the invitation by setting a password.
|
83
75
|
email:
|
84
76
|
- sergio@entrecables.com
|
@@ -91,36 +83,82 @@ extra_rdoc_files: []
|
|
91
83
|
files:
|
92
84
|
- app/controllers/devise/invitations_controller.rb
|
93
85
|
- app/controllers/devise_invitable/registrations_controller.rb
|
94
|
-
- app/controllers/devise_invitable/registrations_controller.rb~
|
95
86
|
- app/views/devise/invitations/edit.html.erb
|
96
87
|
- app/views/devise/invitations/new.html.erb
|
97
88
|
- app/views/devise/mailer/invitation_instructions.html.erb
|
98
89
|
- config/locales/en.yml
|
99
90
|
- lib/devise_invitable.rb
|
91
|
+
- lib/devise_invitable/controllers/helpers.rb
|
92
|
+
- lib/devise_invitable/controllers/url_helpers.rb
|
93
|
+
- lib/devise_invitable/inviter.rb
|
100
94
|
- lib/devise_invitable/mailer.rb
|
95
|
+
- lib/devise_invitable/mapping.rb
|
101
96
|
- lib/devise_invitable/model.rb
|
97
|
+
- lib/devise_invitable/parameter_sanitizer.rb
|
102
98
|
- lib/devise_invitable/rails.rb
|
103
99
|
- lib/devise_invitable/routes.rb
|
104
100
|
- lib/devise_invitable/version.rb
|
105
|
-
- lib/devise_invitable/controllers/helpers.rb
|
106
|
-
- lib/devise_invitable/controllers/url_helpers.rb
|
107
|
-
- lib/devise_invitable/controllers/registrations.rb~
|
108
|
-
- lib/devise_invitable/controllers/helpers.rb~
|
109
|
-
- lib/devise_invitable/rails.rb~
|
110
|
-
- lib/devise_invitable/inviter.rb
|
111
|
-
- lib/devise_invitable/mapping.rb
|
112
|
-
- lib/devise_invitable/model.rb~
|
113
101
|
- lib/generators/active_record/devise_invitable_generator.rb
|
114
102
|
- lib/generators/active_record/templates/migration.rb
|
115
|
-
- lib/generators/devise_invitable/views_generator.rb
|
116
103
|
- lib/generators/devise_invitable/devise_invitable_generator.rb
|
117
104
|
- lib/generators/devise_invitable/install_generator.rb
|
118
105
|
- lib/generators/devise_invitable/templates/simple_form_for/invitations/edit.html.erb
|
119
106
|
- lib/generators/devise_invitable/templates/simple_form_for/invitations/new.html.erb
|
107
|
+
- lib/generators/devise_invitable/views_generator.rb
|
120
108
|
- lib/generators/mongoid/devise_invitable_generator.rb
|
121
|
-
- lib/devise_invitable.rb~
|
122
109
|
- LICENSE
|
123
110
|
- README.rdoc
|
111
|
+
- test/functional/controller_helpers_test.rb
|
112
|
+
- test/functional/registrations_controller_test.rb
|
113
|
+
- test/generators/views_generator_test.rb
|
114
|
+
- test/generators_test.rb
|
115
|
+
- test/integration/invitation_remove_test.rb
|
116
|
+
- test/integration/invitation_test.rb
|
117
|
+
- test/integration_tests_helper.rb
|
118
|
+
- test/mailers/invitation_mail_test.rb
|
119
|
+
- test/model_tests_helper.rb
|
120
|
+
- test/models/invitable_test.rb
|
121
|
+
- test/models_test.rb
|
122
|
+
- test/orm/active_record.rb
|
123
|
+
- test/orm/mongoid.rb
|
124
|
+
- test/rails_app/Rakefile
|
125
|
+
- test/rails_app/app/controllers/admins_controller.rb
|
126
|
+
- test/rails_app/app/controllers/application_controller.rb
|
127
|
+
- test/rails_app/app/controllers/free_invitations_controller.rb
|
128
|
+
- test/rails_app/app/controllers/home_controller.rb
|
129
|
+
- test/rails_app/app/controllers/users_controller.rb
|
130
|
+
- test/rails_app/app/helpers/application_helper.rb
|
131
|
+
- test/rails_app/app/models/admin.rb
|
132
|
+
- test/rails_app/app/models/octopussy.rb
|
133
|
+
- test/rails_app/app/models/user.rb
|
134
|
+
- test/rails_app/app/views/admins/new.html.erb
|
135
|
+
- test/rails_app/app/views/free_invitations/new.html.erb
|
136
|
+
- test/rails_app/app/views/home/index.html.erb
|
137
|
+
- test/rails_app/app/views/layouts/application.html.erb
|
138
|
+
- test/rails_app/app/views/users/invitations/new.html.erb
|
139
|
+
- test/rails_app/config.ru
|
140
|
+
- test/rails_app/config/application.rb
|
141
|
+
- test/rails_app/config/boot.rb
|
142
|
+
- test/rails_app/config/database.yml
|
143
|
+
- test/rails_app/config/environment.rb
|
144
|
+
- test/rails_app/config/environments/development.rb
|
145
|
+
- test/rails_app/config/environments/production.rb
|
146
|
+
- test/rails_app/config/environments/test.rb
|
147
|
+
- test/rails_app/config/initializers/backtrace_silencers.rb
|
148
|
+
- test/rails_app/config/initializers/devise.rb
|
149
|
+
- test/rails_app/config/initializers/inflections.rb
|
150
|
+
- test/rails_app/config/initializers/mime_types.rb
|
151
|
+
- test/rails_app/config/initializers/secret_token.rb
|
152
|
+
- test/rails_app/config/initializers/session_store.rb
|
153
|
+
- test/rails_app/config/initializers/wrap_parameters.rb
|
154
|
+
- test/rails_app/config/locales/devise.en.yml
|
155
|
+
- test/rails_app/config/locales/en.yml
|
156
|
+
- test/rails_app/config/routes.rb
|
157
|
+
- test/rails_app/db/migrate/20100401102949_create_tables.rb
|
158
|
+
- test/rails_app/mongoid.yml
|
159
|
+
- test/rails_app/script/rails
|
160
|
+
- test/routes_test.rb
|
161
|
+
- test/test_helper.rb
|
124
162
|
homepage: https://github.com/scambra/devise_invitable
|
125
163
|
licenses: []
|
126
164
|
|
@@ -160,6 +198,56 @@ rubygems_version: 1.8.23
|
|
160
198
|
signing_key:
|
161
199
|
specification_version: 3
|
162
200
|
summary: An invitation strategy for Devise
|
163
|
-
test_files:
|
164
|
-
|
201
|
+
test_files:
|
202
|
+
- test/functional/controller_helpers_test.rb
|
203
|
+
- test/functional/registrations_controller_test.rb
|
204
|
+
- test/generators/views_generator_test.rb
|
205
|
+
- test/generators_test.rb
|
206
|
+
- test/integration/invitation_remove_test.rb
|
207
|
+
- test/integration/invitation_test.rb
|
208
|
+
- test/integration_tests_helper.rb
|
209
|
+
- test/mailers/invitation_mail_test.rb
|
210
|
+
- test/model_tests_helper.rb
|
211
|
+
- test/models/invitable_test.rb
|
212
|
+
- test/models_test.rb
|
213
|
+
- test/orm/active_record.rb
|
214
|
+
- test/orm/mongoid.rb
|
215
|
+
- test/rails_app/Rakefile
|
216
|
+
- test/rails_app/app/controllers/admins_controller.rb
|
217
|
+
- test/rails_app/app/controllers/application_controller.rb
|
218
|
+
- test/rails_app/app/controllers/free_invitations_controller.rb
|
219
|
+
- test/rails_app/app/controllers/home_controller.rb
|
220
|
+
- test/rails_app/app/controllers/users_controller.rb
|
221
|
+
- test/rails_app/app/helpers/application_helper.rb
|
222
|
+
- test/rails_app/app/models/admin.rb
|
223
|
+
- test/rails_app/app/models/octopussy.rb
|
224
|
+
- test/rails_app/app/models/user.rb
|
225
|
+
- test/rails_app/app/views/admins/new.html.erb
|
226
|
+
- test/rails_app/app/views/free_invitations/new.html.erb
|
227
|
+
- test/rails_app/app/views/home/index.html.erb
|
228
|
+
- test/rails_app/app/views/layouts/application.html.erb
|
229
|
+
- test/rails_app/app/views/users/invitations/new.html.erb
|
230
|
+
- test/rails_app/config.ru
|
231
|
+
- test/rails_app/config/application.rb
|
232
|
+
- test/rails_app/config/boot.rb
|
233
|
+
- test/rails_app/config/database.yml
|
234
|
+
- test/rails_app/config/environment.rb
|
235
|
+
- test/rails_app/config/environments/development.rb
|
236
|
+
- test/rails_app/config/environments/production.rb
|
237
|
+
- test/rails_app/config/environments/test.rb
|
238
|
+
- test/rails_app/config/initializers/backtrace_silencers.rb
|
239
|
+
- test/rails_app/config/initializers/devise.rb
|
240
|
+
- test/rails_app/config/initializers/inflections.rb
|
241
|
+
- test/rails_app/config/initializers/mime_types.rb
|
242
|
+
- test/rails_app/config/initializers/secret_token.rb
|
243
|
+
- test/rails_app/config/initializers/session_store.rb
|
244
|
+
- test/rails_app/config/initializers/wrap_parameters.rb
|
245
|
+
- test/rails_app/config/locales/devise.en.yml
|
246
|
+
- test/rails_app/config/locales/en.yml
|
247
|
+
- test/rails_app/config/routes.rb
|
248
|
+
- test/rails_app/db/migrate/20100401102949_create_tables.rb
|
249
|
+
- test/rails_app/mongoid.yml
|
250
|
+
- test/rails_app/script/rails
|
251
|
+
- test/routes_test.rb
|
252
|
+
- test/test_helper.rb
|
165
253
|
has_rdoc:
|
@@ -1,15 +0,0 @@
|
|
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~
DELETED
@@ -1,65 +0,0 @@
|
|
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
|
@@ -1,21 +0,0 @@
|
|
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,21 +0,0 @@
|
|
1
|
-
module DeviseInvitable::Controllers::Registrations
|
2
|
-
def self.included(controller)
|
3
|
-
controller.alias_method_chain :build_resource, :invitation
|
4
|
-
end
|
5
|
-
|
6
|
-
protected
|
7
|
-
|
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
|
17
|
-
end
|
18
|
-
end
|
19
|
-
self.resource ||= build_resource_without_invitation(hash, *args)
|
20
|
-
end
|
21
|
-
end
|
@@ -1,224 +0,0 @@
|
|
1
|
-
require 'active_support/deprecation'
|
2
|
-
|
3
|
-
module Devise
|
4
|
-
module Models
|
5
|
-
# Invitable is responsible for sending invitation emails.
|
6
|
-
# When an invitation is sent to an email address, an account is created for it.
|
7
|
-
# Invitation email contains a link allowing the user to accept the invitation
|
8
|
-
# by setting a password (as reset password from Devise's recoverable module).
|
9
|
-
#
|
10
|
-
# Configuration:
|
11
|
-
#
|
12
|
-
# invite_for: The period the generated invitation token is valid, after
|
13
|
-
# this period, the invited resource won't be able to accept the invitation.
|
14
|
-
# When invite_for is 0 (the default), the invitation won't expire.
|
15
|
-
#
|
16
|
-
# Examples:
|
17
|
-
#
|
18
|
-
# User.find(1).invited_to_sign_up? # => true/false
|
19
|
-
# User.invite!(:email => 'someone@example.com') # => send invitation
|
20
|
-
# User.accept_invitation!(:invitation_token => '...') # => accept invitation with a token
|
21
|
-
# User.find(1).accept_invitation! # => accept invitation
|
22
|
-
# User.find(1).invite! # => reset invitation status and send invitation again
|
23
|
-
module Invitable
|
24
|
-
extend ActiveSupport::Concern
|
25
|
-
|
26
|
-
attr_accessor :skip_invitation
|
27
|
-
attr_accessor :completing_invite
|
28
|
-
|
29
|
-
included do
|
30
|
-
include ::DeviseInvitable::Inviter
|
31
|
-
belongs_to :invited_by, :polymorphic => true
|
32
|
-
|
33
|
-
include ActiveSupport::Callbacks
|
34
|
-
define_callbacks :invitation_accepted
|
35
|
-
|
36
|
-
attr_writer :skip_password
|
37
|
-
end
|
38
|
-
|
39
|
-
# Accept an invitation by clearing invitation token and and setting invitation_accepted_at
|
40
|
-
# Confirms it if model is confirmable
|
41
|
-
def accept_invitation!
|
42
|
-
self.completing_invite = true
|
43
|
-
if self.invited_to_sign_up? && self.valid?
|
44
|
-
run_callbacks :invitation_accepted do
|
45
|
-
self.invitation_token = nil
|
46
|
-
self.invitation_accepted_at = Time.now.utc if respond_to? :"invitation_accepted_at="
|
47
|
-
self.completing_invite = false
|
48
|
-
self.save(:validate => false)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Verifies whether a user has accepted an invite, was never invited, or is in the process of accepting an invitation, or not
|
54
|
-
def accepting_or_not_invited?
|
55
|
-
!!completing_invite || invited_to_sign_up?
|
56
|
-
end
|
57
|
-
|
58
|
-
# Verifies whether a user has been invited or not
|
59
|
-
def invited_to_sign_up?
|
60
|
-
persisted? && invitation_token.present?
|
61
|
-
end
|
62
|
-
|
63
|
-
def invited?
|
64
|
-
invited_to_sign_up?
|
65
|
-
end
|
66
|
-
deprecate :invited?
|
67
|
-
|
68
|
-
# Reset invitation token and send invitation again
|
69
|
-
def invite!
|
70
|
-
was_invited = invited_to_sign_up?
|
71
|
-
self.skip_confirmation! if self.new_record? && self.respond_to?(:skip_confirmation!)
|
72
|
-
generate_invitation_token if self.invitation_token.nil?
|
73
|
-
self.invitation_sent_at = Time.now.utc
|
74
|
-
|
75
|
-
# Call these before_validate methods since we aren't validating on save
|
76
|
-
self.downcase_keys if self.new_record? && self.respond_to?(:downcase_keys)
|
77
|
-
self.strip_whitespace if self.new_record? && self.respond_to?(:strip_whitespace)
|
78
|
-
|
79
|
-
if save(:validate => false)
|
80
|
-
self.invited_by.decrement_invitation_limit! if !was_invited and self.invited_by.present?
|
81
|
-
deliver_invitation unless @skip_invitation
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Verify whether a invitation is active or not. If the user has been
|
86
|
-
# invited, we need to calculate if the invitation time has not expired
|
87
|
-
# for this user, in other words, if the invitation is still valid.
|
88
|
-
def valid_invitation?
|
89
|
-
invited_to_sign_up? && invitation_period_valid?
|
90
|
-
end
|
91
|
-
|
92
|
-
# Only verify password when is not invited
|
93
|
-
def valid_password?(password)
|
94
|
-
super unless invited_to_sign_up?
|
95
|
-
end
|
96
|
-
|
97
|
-
def reset_password!(new_password, new_password_confirmation)
|
98
|
-
super
|
99
|
-
accept_invitation!
|
100
|
-
end
|
101
|
-
|
102
|
-
protected
|
103
|
-
# Overriding the method in Devise's :validatable module so password is not required on inviting
|
104
|
-
def password_required?
|
105
|
-
!@skip_password && super
|
106
|
-
end
|
107
|
-
|
108
|
-
# Deliver the invitation email
|
109
|
-
def deliver_invitation
|
110
|
-
::Devise.mailer.invitation_instructions(self).deliver
|
111
|
-
end
|
112
|
-
|
113
|
-
# Checks if the invitation for the user is within the limit time.
|
114
|
-
# We do this by calculating if the difference between today and the
|
115
|
-
# invitation sent date does not exceed the invite for time configured.
|
116
|
-
# Invite_for is a model configuration, must always be an integer value.
|
117
|
-
#
|
118
|
-
# Example:
|
119
|
-
#
|
120
|
-
# # invite_for = 1.day and invitation_sent_at = today
|
121
|
-
# invitation_period_valid? # returns true
|
122
|
-
#
|
123
|
-
# # invite_for = 5.days and invitation_sent_at = 4.days.ago
|
124
|
-
# invitation_period_valid? # returns true
|
125
|
-
#
|
126
|
-
# # invite_for = 5.days and invitation_sent_at = 5.days.ago
|
127
|
-
# invitation_period_valid? # returns false
|
128
|
-
#
|
129
|
-
# # invite_for = nil
|
130
|
-
# invitation_period_valid? # will always return true
|
131
|
-
#
|
132
|
-
def invitation_period_valid?
|
133
|
-
invitation_sent_at && (self.class.invite_for.to_i.zero? || invitation_sent_at.utc >= self.class.invite_for.ago)
|
134
|
-
end
|
135
|
-
|
136
|
-
# Generates a new random token for invitation, and stores the time
|
137
|
-
# this token is being generated
|
138
|
-
def generate_invitation_token
|
139
|
-
self.invitation_token = self.class.invitation_token
|
140
|
-
end
|
141
|
-
|
142
|
-
module ClassMethods
|
143
|
-
# Attempt to find a user by it's email. If a record is not found, create a new
|
144
|
-
# user and send invitation to it. If user is found, returns the user with an
|
145
|
-
# email already exists error.
|
146
|
-
# If user is found and still have pending invitation, email is resend unless
|
147
|
-
# resend_invitation is set to false
|
148
|
-
# Attributes must contain the user email, other attributes will be set in the record
|
149
|
-
def _invite(attributes={}, invited_by=nil, &block)
|
150
|
-
invitable = find_or_initialize_with_error_by(invite_key, attributes.delete(invite_key))
|
151
|
-
invitable.assign_attributes(attributes, :as => inviter_role(invited_by))
|
152
|
-
invitable.invited_by = invited_by
|
153
|
-
|
154
|
-
invitable.skip_password = true
|
155
|
-
invitable.valid? if self.validate_on_invite
|
156
|
-
if invitable.new_record?
|
157
|
-
invitable.errors.clear if !self.validate_on_invite and invitable.email.try(:match, Devise.email_regexp)
|
158
|
-
else
|
159
|
-
invitable.errors.add(invite_key, :taken) unless invitable.invited_to_sign_up? && self.resend_invitation
|
160
|
-
end
|
161
|
-
|
162
|
-
if invitable.errors.empty?
|
163
|
-
yield invitable if block_given?
|
164
|
-
mail = invitable.invite!
|
165
|
-
end
|
166
|
-
[invitable, mail]
|
167
|
-
end
|
168
|
-
|
169
|
-
# Override this method if the invitable is using Mass Assignment Security
|
170
|
-
# and the inviter has a non-default role.
|
171
|
-
def inviter_role(inviter)
|
172
|
-
:default
|
173
|
-
end
|
174
|
-
|
175
|
-
def invite!(attributes={}, invited_by=nil, &block)
|
176
|
-
invitable, mail = _invite(attributes, invited_by, &block)
|
177
|
-
invitable
|
178
|
-
end
|
179
|
-
|
180
|
-
def invite_mail!(attributes={}, invited_by=nil, &block)
|
181
|
-
invitable, mail = _invite(attributes, invited_by, &block)
|
182
|
-
mail
|
183
|
-
end
|
184
|
-
|
185
|
-
# Attempt to find a user by it's invitation_token to set it's password.
|
186
|
-
# If a user is found, reset it's password and automatically try saving
|
187
|
-
# the record. If not user is found, returns a new user containing an
|
188
|
-
# error in invitation_token attribute.
|
189
|
-
# Attributes must contain invitation_token, password and confirmation
|
190
|
-
def accept_invitation!(attributes={})
|
191
|
-
invitable = find_or_initialize_with_error_by(:invitation_token, attributes.delete(:invitation_token))
|
192
|
-
invitable.errors.add(:invitation_token, :invalid) if invitable.invitation_token && invitable.persisted? && !invitable.valid_invitation?
|
193
|
-
if invitable.errors.empty?
|
194
|
-
invitable.attributes = attributes
|
195
|
-
invitable.accept_invitation!
|
196
|
-
end
|
197
|
-
invitable
|
198
|
-
end
|
199
|
-
|
200
|
-
# Generate a token checking if one does not already exist in the database.
|
201
|
-
def invitation_token
|
202
|
-
generate_token(:invitation_token)
|
203
|
-
end
|
204
|
-
|
205
|
-
# Callback convenience methods
|
206
|
-
def before_invitation_accepted(*args, &blk)
|
207
|
-
set_callback(:invitation_accepted, :before, *args, &blk)
|
208
|
-
end
|
209
|
-
|
210
|
-
def after_invitation_accepted(*args, &blk)
|
211
|
-
set_callback(:invitation_accepted, :after, *args, &blk)
|
212
|
-
end
|
213
|
-
|
214
|
-
|
215
|
-
Devise::Models.config(self, :invite_for)
|
216
|
-
Devise::Models.config(self, :validate_on_invite)
|
217
|
-
Devise::Models.config(self, :invitation_limit)
|
218
|
-
Devise::Models.config(self, :invite_key)
|
219
|
-
Devise::Models.config(self, :resend_invitation)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|