devise_invitable 0.3.2 → 0.3.4
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/Gemfile.lock +1 -1
- data/README.rdoc +116 -47
- data/VERSION +1 -1
- data/app/controllers/devise/invitations_controller.rb +1 -1
- data/devise_invitable.gemspec +13 -3
- data/lib/devise_invitable.rb +2 -6
- data/lib/devise_invitable/controllers/helpers.rb +5 -0
- data/lib/devise_invitable/mailer.rb +6 -5
- data/lib/devise_invitable/rails.rb +1 -0
- data/lib/generators/active_record/devise_invitable_generator.rb +13 -0
- data/lib/generators/active_record/templates/migration.rb +18 -0
- data/lib/generators/devise_invitable/devise_invitable_generator.rb +16 -0
- data/lib/generators/devise_invitable/install_generator.rb +34 -0
- data/lib/generators/devise_invitable/views_generator.rb +1 -1
- data/test/generators_test.rb +45 -0
- data/test/rails_app/app/models/octopussy.rb +11 -0
- data/test/rails_app/app/views/users/invitations/new.html.erb +15 -0
- data/test/rails_app/config/application.rb +1 -0
- data/test/rails_app/config/initializers/devise.rb +8 -6
- data/test/rails_app/script/rails +6 -0
- data/test/test_helper.rb +1 -0
- metadata +14 -4
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -1,95 +1,167 @@
|
|
1
|
-
=
|
1
|
+
= DeviseInvitable
|
2
2
|
|
3
3
|
It adds support to devise[http://github.com/plataformatec/devise] for send invitations by email (it requires to be authenticated) and accept the invitation setting the password.
|
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
|
6
6
|
|
7
|
-
== Installation
|
7
|
+
== Installation for Rails ~> 3.0.0 and Devise ~> 1.1.2
|
8
8
|
|
9
9
|
Install devise_invitable gem, it should install dependencies (such as devise and warden):
|
10
10
|
|
11
11
|
sudo gem install devise_invitable
|
12
12
|
|
13
|
-
Configure devise_invitable
|
13
|
+
Configure devise_invitable in your Gemfile (and devise if you weren't using them):
|
14
14
|
|
15
15
|
gem 'devise'
|
16
16
|
gem 'devise_invitable'
|
17
17
|
|
18
|
-
|
18
|
+
=== Automatic installation
|
19
19
|
|
20
|
-
|
20
|
+
After you install DeviseInvitable and add it to your Gemfile, you need to run the generator:
|
21
21
|
|
22
|
-
|
22
|
+
rails generate devise_invitable:install
|
23
|
+
|
24
|
+
The generator will inject DeviseInvitable’s configuration options and you should take a look at it. When you are done, you are ready to add DeviseInvitable to any of your Devise models using the generator:
|
25
|
+
|
26
|
+
rails generate devise_invitable MODEL
|
27
|
+
|
28
|
+
Replace MODEL by the class name you want to add DeviseInvitable, like User, Admin, etc. This will add the :invitable flag to your model's Devise modules. The generator will also create a migration file (if your ORM support them). Continue reading this file to understand exactly what the generator produces and how to use it.
|
29
|
+
|
30
|
+
=== Manual installation
|
31
|
+
|
32
|
+
Follow the walkthrough for Devise and after it's done, follow this walkthrough.
|
33
|
+
|
34
|
+
Add :invitable to the Devise line in your model (we’re assuming here you already have a User model with some Devise modules):
|
35
|
+
|
36
|
+
class User < ActiveRecord::Base
|
37
|
+
devise :database_authenticatable, :confirmable, :invitable
|
38
|
+
end
|
39
|
+
|
40
|
+
Add t.invitable to your Devise model migration:
|
23
41
|
|
24
42
|
create_table :users do
|
25
43
|
...
|
26
44
|
t.invitable
|
27
45
|
...
|
28
46
|
end
|
29
|
-
add_index :users, :invitation_token
|
47
|
+
add_index :users, :invitation_token
|
30
48
|
|
31
|
-
|
49
|
+
or for a model that is already created, define a migration to add DeviseInvitable to your model:
|
32
50
|
|
33
|
-
|
34
|
-
|
51
|
+
change_table :users do |t|
|
52
|
+
t.string :invitation_token, :limit => 20
|
53
|
+
t.datetime :invitation_sent_at
|
54
|
+
t.index :invitation_token
|
35
55
|
end
|
36
56
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
57
|
+
# Allow null encrypted_password and password_salt
|
58
|
+
change_column :users, :encrypted_password, :string, :null => true
|
59
|
+
change_column :users, :password_salt, :string, :null => true
|
60
|
+
|
61
|
+
DeviseInvitable doesn't use _attr_accessible_ or _attr_protected_, so be sure to define attributes as accessible or protected in your model.
|
43
62
|
|
44
63
|
== Model configuration
|
45
64
|
|
46
|
-
DeviseInvitable adds a new configuration option
|
65
|
+
DeviseInvitable adds a new configuration option:
|
66
|
+
|
67
|
+
* invite_for => The validity duration for an invitation. Default is 0, which means invitations doesn't expire.
|
68
|
+
|
69
|
+
You can set those configuration options in the Devise initializer as follow:
|
70
|
+
|
71
|
+
# ==> Configuration for :invitable
|
72
|
+
# Time interval where the invitation token is valid.
|
73
|
+
# If invite_for is 0 or nil, the invitation will never expire.
|
74
|
+
# Default: 0
|
75
|
+
# config.invite_for = 2.weeks
|
76
|
+
|
77
|
+
or directly as parameters to the <tt>devise</tt> method inside your Devise models:
|
78
|
+
|
79
|
+
devise :database_authenticatable, :confirmable, :invitable, :invite_for => 2.weeks
|
80
|
+
|
81
|
+
For details, see <tt>config/initializer/devise.rb</tt> (after you invoked the "devise_invitable:install" generator described above).
|
47
82
|
|
48
83
|
== Configuring views
|
49
84
|
|
50
|
-
All
|
85
|
+
All the views are packaged inside the gem. If you'd like to customize the views, invoke the following generator and it will copy all the views to your application:
|
51
86
|
|
52
|
-
|
87
|
+
rails generate devise_invitable:views
|
53
88
|
|
54
|
-
|
89
|
+
You can also use the generator to generate scoped views:
|
55
90
|
|
56
|
-
|
91
|
+
rails generate devise_invitable:views users
|
57
92
|
|
58
|
-
|
93
|
+
Please refer to {Devise's README}[http://github.com/plataformatec/devise] for more information about views.
|
59
94
|
|
60
|
-
==
|
95
|
+
== Usage
|
61
96
|
|
62
|
-
|
97
|
+
=== Send an invitation
|
63
98
|
|
64
|
-
|
99
|
+
To send an invitation to a user, use the <tt>invite!</tt> class method. You must set <tt>email</tt> in the parameters hash:
|
100
|
+
You can also include other attributes in the hash. The record will not be validated.
|
65
101
|
|
66
|
-
|
102
|
+
User.invite(:email => "new_user@example.com", :name => "John Doe")
|
103
|
+
# => an invitation email will be sent to new_user@example.com
|
67
104
|
|
68
|
-
|
105
|
+
=== Accept an invitation
|
69
106
|
|
70
|
-
To accept an invitation with a token use accept_invitation
|
107
|
+
To accept an invitation with a token use the <tt>accept_invitation</tt> class method. You must set <tt>invitation_token</tt> in the parameters hash. You can include other attributes in the hash (as in the <tt>update_attributes</tt> method for example).
|
71
108
|
|
72
|
-
User.accept_invitation
|
109
|
+
User.accept_invitation(:invitation_token => params[:invitation_token], :password => "ad97nwj3o2", :name => "John Doe")
|
73
110
|
|
74
|
-
|
111
|
+
== Integration in a Rails application
|
75
112
|
|
76
|
-
|
113
|
+
Since the invitations controller take care of all the invite/accept invitation process, in most cases you wouldn't call the <tt>invite</tt> and <tt>accept_invitation</tt> methods directly.
|
114
|
+
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.
|
115
|
+
This email includes a link to accept the invitation like <tt>/users/invitation/accept?invitation_token=abcd123</tt>.
|
77
116
|
|
78
|
-
|
117
|
+
== Controller filter
|
79
118
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
119
|
+
InvitationsController uses authenticate_inviter! filter to restrict who can send invitations. You can override this method in your ApplicationController.
|
120
|
+
|
121
|
+
Default behavior requires authentication of the same resource. For example, if your model User is <tt>:invitable</tt>, it will allow all authenticated users to send invitations to other users.
|
122
|
+
|
123
|
+
You would have a User model which is configured as invitable and an Admin model which is not. If you would like to allow only admins to send invitations, simply overwrite the authenticate_inviter! method as follow:
|
124
|
+
|
125
|
+
class ApplicationController < ActionController::Base
|
126
|
+
protected
|
127
|
+
def authenticate_inviter!
|
128
|
+
authenticate_admin!
|
129
|
+
end
|
84
130
|
end
|
85
131
|
|
86
|
-
|
87
|
-
|
88
|
-
|
132
|
+
== I18n
|
133
|
+
|
134
|
+
DeviseInvitable uses flash messages with I18n with the flash keys <tt>:send_instructions</tt> and <tt>:updated</tt>. To customize your app, you can modify the generated locale file:
|
135
|
+
|
136
|
+
en:
|
137
|
+
devise:
|
138
|
+
invitations:
|
139
|
+
send_instructions: 'An email with instructions about how to set the password has been sent.'
|
140
|
+
updated: 'Your password was set successfully. You are now signed in.'
|
141
|
+
|
142
|
+
You can also create distinct messages based on the resource you've configured using the singular name given in routes:
|
143
|
+
|
144
|
+
en:
|
145
|
+
devise:
|
146
|
+
invitations:
|
147
|
+
user:
|
148
|
+
send_instructions: 'A new user invitation has been sent.'
|
149
|
+
updated: 'Welcome on board! You are now signed in.'
|
150
|
+
|
151
|
+
The DeviseInvitable mailer uses the Devise pattern to create subject messages:
|
152
|
+
|
153
|
+
en:
|
154
|
+
devise:
|
155
|
+
mailer:
|
156
|
+
invitation:
|
157
|
+
subject: 'You got an invitation!'
|
158
|
+
user_subject: 'You got an user invitation!'
|
159
|
+
|
160
|
+
Take a look at the generated locale file (in <tt>config/locales/devise_invitable.en.yml</tt>) to check all available messages.
|
89
161
|
|
90
|
-
|
162
|
+
== Other ORMs
|
91
163
|
|
92
|
-
|
164
|
+
DeviseInvitable supports ActiveRecord and Mongoid, like Devise.
|
93
165
|
|
94
166
|
== Contributors
|
95
167
|
|
@@ -97,17 +169,14 @@ Check them all at:
|
|
97
169
|
|
98
170
|
http://github.com/scambra/devise_invitable/contributors
|
99
171
|
|
100
|
-
Special thanks to http://github.com/rymai
|
172
|
+
Special thanks to rymai[http://github.com/rymai] for rails3 support, his fork was a great help.
|
101
173
|
|
102
174
|
== Note on Patches/Pull Requests
|
103
175
|
|
104
176
|
* Fork the project.
|
105
177
|
* Make your feature addition or bug fix.
|
106
|
-
* Add tests for it. This is important so I don't break it in a
|
107
|
-
|
108
|
-
* Commit, do not mess with rakefile, version, or history.
|
109
|
-
(if you want to have your own version, that is fine but
|
110
|
-
bump version in a commit by itself I can ignore when I pull)
|
178
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
179
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
111
180
|
* Send me a pull request. Bonus points for topic branches.
|
112
181
|
|
113
182
|
== Copyright
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class Devise::InvitationsController < ApplicationController
|
2
2
|
include Devise::Controllers::InternalHelpers
|
3
3
|
|
4
|
-
before_filter :
|
4
|
+
before_filter :authenticate_inviter!, :only => [:new, :create]
|
5
5
|
before_filter :require_no_authentication, :only => [:edit, :update]
|
6
6
|
helper_method :after_sign_in_path_for
|
7
7
|
|
data/devise_invitable.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{devise_invitable}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sergio Cambra"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-02}
|
13
13
|
s.description = %q{It adds support for send invitations by email (it requires to be authenticated) and accept the invitation setting the password}
|
14
14
|
s.email = %q{sergio@entrecables.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -39,7 +39,12 @@ Gem::Specification.new do |s|
|
|
39
39
|
"lib/devise_invitable/rails.rb",
|
40
40
|
"lib/devise_invitable/routes.rb",
|
41
41
|
"lib/devise_invitable/schema.rb",
|
42
|
+
"lib/generators/active_record/devise_invitable_generator.rb",
|
43
|
+
"lib/generators/active_record/templates/migration.rb",
|
44
|
+
"lib/generators/devise_invitable/devise_invitable_generator.rb",
|
45
|
+
"lib/generators/devise_invitable/install_generator.rb",
|
42
46
|
"lib/generators/devise_invitable/views_generator.rb",
|
47
|
+
"test/generators_test.rb",
|
43
48
|
"test/integration/invitable_test.rb",
|
44
49
|
"test/integration_tests_helper.rb",
|
45
50
|
"test/mailers/invitation_test.rb",
|
@@ -51,9 +56,11 @@ Gem::Specification.new do |s|
|
|
51
56
|
"test/rails_app/app/controllers/home_controller.rb",
|
52
57
|
"test/rails_app/app/controllers/users_controller.rb",
|
53
58
|
"test/rails_app/app/helpers/application_helper.rb",
|
59
|
+
"test/rails_app/app/models/octopussy.rb",
|
54
60
|
"test/rails_app/app/models/user.rb",
|
55
61
|
"test/rails_app/app/views/home/index.html.erb",
|
56
62
|
"test/rails_app/app/views/layouts/application.html.erb",
|
63
|
+
"test/rails_app/app/views/users/invitations/new.html.erb",
|
57
64
|
"test/rails_app/config.ru",
|
58
65
|
"test/rails_app/config/application.rb",
|
59
66
|
"test/rails_app/config/boot.rb",
|
@@ -70,6 +77,7 @@ Gem::Specification.new do |s|
|
|
70
77
|
"test/rails_app/config/initializers/session_store.rb",
|
71
78
|
"test/rails_app/config/locales/en.yml",
|
72
79
|
"test/rails_app/config/routes.rb",
|
80
|
+
"test/rails_app/script/rails",
|
73
81
|
"test/routes_test.rb",
|
74
82
|
"test/test_helper.rb"
|
75
83
|
]
|
@@ -79,10 +87,12 @@ Gem::Specification.new do |s|
|
|
79
87
|
s.rubygems_version = %q{1.3.7}
|
80
88
|
s.summary = %q{An invitation strategy for devise}
|
81
89
|
s.test_files = [
|
82
|
-
"test/
|
90
|
+
"test/generators_test.rb",
|
91
|
+
"test/test_helper.rb",
|
83
92
|
"test/integration/invitable_test.rb",
|
84
93
|
"test/routes_test.rb",
|
85
94
|
"test/rails_app/app/helpers/application_helper.rb",
|
95
|
+
"test/rails_app/app/models/octopussy.rb",
|
86
96
|
"test/rails_app/app/models/user.rb",
|
87
97
|
"test/rails_app/app/controllers/admins_controller.rb",
|
88
98
|
"test/rails_app/app/controllers/application_controller.rb",
|
data/lib/devise_invitable.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
|
-
require 'devise'
|
3
|
-
end
|
1
|
+
require 'devise'
|
4
2
|
|
5
|
-
Devise
|
3
|
+
module Devise
|
6
4
|
# Time interval where the invitation token is valid.
|
7
5
|
mattr_accessor :invite_for
|
8
6
|
@@invite_for = 0
|
@@ -10,8 +8,6 @@ end
|
|
10
8
|
|
11
9
|
Devise.add_module :invitable, :controller => :invitations, :model => 'devise_invitable/model', :route => :invitation
|
12
10
|
|
13
|
-
module DeviseInvitable; end
|
14
|
-
|
15
11
|
require 'devise_invitable/mailer'
|
16
12
|
require 'devise_invitable/routes'
|
17
13
|
require 'devise_invitable/schema'
|
@@ -1,6 +1,11 @@
|
|
1
1
|
module DeviseInvitable::Controllers::Helpers
|
2
2
|
protected
|
3
3
|
def authenticate_resource!
|
4
|
+
ActiveSupport::Deprecation.warn('authenticate_resource! has been renamed to authenticate_inviter!')
|
5
|
+
authenticate_inviter!
|
6
|
+
end
|
7
|
+
|
8
|
+
def authenticate_inviter!
|
4
9
|
send(:"authenticate_#{resource_name}!")
|
5
10
|
end
|
6
11
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
-
module DeviseInvitable
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module DeviseInvitable
|
2
|
+
module Mailer
|
3
|
+
# Deliver an invitation when is requested
|
4
|
+
def invitation(record)
|
5
|
+
setup_mail(record, :invitation)
|
6
|
+
end
|
6
7
|
end
|
7
8
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module Generators
|
5
|
+
class DeviseInvitableGenerator < ActiveRecord::Generators::Base
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
def copy_devise_migration
|
9
|
+
migration_template "migration.rb", "db/migrate/devise_invitable_add_to_#{table_name}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class DeviseInvitableAddTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_table :<%= table_name %> do |t|
|
4
|
+
t.string :invitation_token, :limit => 20
|
5
|
+
t.datetime :invitation_sent_at
|
6
|
+
t.index :invitation_token # for invitable
|
7
|
+
end
|
8
|
+
|
9
|
+
# And allow null encrypted_password and password_salt:
|
10
|
+
change_column :<%= table_name %>, :encrypted_password, :string, :null => true
|
11
|
+
change_column :<%= table_name %>, :password_salt, :string, :null => true
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
remove_column :<%= table_name %>, :invitation_sent_at
|
16
|
+
remove_column :<%= table_name %>, :invitation_token
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module DeviseInvitable
|
2
|
+
module Generators
|
3
|
+
class DeviseInvitableGenerator < Rails::Generators::NamedBase
|
4
|
+
namespace "devise_invitable"
|
5
|
+
|
6
|
+
desc "Add :invitable directive in the given model. Also generate migration for ActiveRecord"
|
7
|
+
|
8
|
+
def inject_devise_invitable_content
|
9
|
+
path = File.join("app", "models", "#{file_path}.rb")
|
10
|
+
inject_into_file(path, "invitable, :", :after => "devise :") if File.exists?(path)
|
11
|
+
end
|
12
|
+
|
13
|
+
hook_for :orm
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module DeviseInvitable
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../templates", __FILE__)
|
5
|
+
desc "Add DeviseInvitable config variables to the Devise initializer and copy DeviseInvitable locale files to your application."
|
6
|
+
|
7
|
+
def add_config_options_to_initializer
|
8
|
+
devise_initializer_path = "config/initializers/devise.rb"
|
9
|
+
if File.exist?(devise_initializer_path)
|
10
|
+
old_content = File.read(devise_initializer_path)
|
11
|
+
|
12
|
+
if old_content.match(Regexp.new(/^\s# ==> Configuration for :invitable\n/))
|
13
|
+
false
|
14
|
+
else
|
15
|
+
inject_into_file(devise_initializer_path, :before => " # ==> Configuration for :confirmable\n") do
|
16
|
+
<<-CONTENT
|
17
|
+
# ==> Configuration for :invitable
|
18
|
+
# Time interval where the invitation token is valid (default: 0).
|
19
|
+
# If invite_for is 0 or nil, the invitation will never expire.
|
20
|
+
# config.invite_for = 2.weeks
|
21
|
+
|
22
|
+
CONTENT
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def copy_locale
|
29
|
+
copy_file "../../../config/locales/en.yml", "config/locales/devise_invitable.en.yml"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -3,7 +3,7 @@ require 'generators/devise/views_generator'
|
|
3
3
|
module DeviseInvitable
|
4
4
|
module Generators
|
5
5
|
class ViewsGenerator < Devise::Generators::ViewsGenerator
|
6
|
-
source_root File.expand_path(
|
6
|
+
source_root File.expand_path("../../../../app/views", __FILE__)
|
7
7
|
desc 'Copies all DeviseInvitable views to your application.'
|
8
8
|
end
|
9
9
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'generators/devise_invitable/devise_invitable_generator'
|
4
|
+
|
5
|
+
class GeneratorsTest < ActiveSupport::TestCase
|
6
|
+
RAILS_APP_PATH = File.expand_path("../rails_app", __FILE__)
|
7
|
+
|
8
|
+
test "rails g should include the 3 generators" do
|
9
|
+
@output = `cd #{RAILS_APP_PATH} && rails g`
|
10
|
+
assert @output.match(%r|DeviseInvitable:\n devise_invitable\n devise_invitable:install\n devise_invitable:views|)
|
11
|
+
end
|
12
|
+
|
13
|
+
test "rails g devise_invitable:install" do
|
14
|
+
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:install -p`
|
15
|
+
assert @output.match(%r|inject.+ config/initializers/devise\.rb\n|)
|
16
|
+
assert @output.match(%r|create.+ config/locales/devise_invitable\.en\.yml\n|)
|
17
|
+
end
|
18
|
+
|
19
|
+
test "rails g devise_invitable:views not scoped" do
|
20
|
+
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:views -p`
|
21
|
+
assert @output.match(%r|create.+ app/views/devise\n|)
|
22
|
+
assert @output.match(%r|create.+ app/views/devise/invitations/edit\.html\.erb\n|)
|
23
|
+
assert @output.match(%r|create.+ app/views/devise/invitations/new\.html\.erb\n|)
|
24
|
+
assert @output.match(%r|create.+ app/views/devise/mailer/invitation\.html\.erb\n|)
|
25
|
+
end
|
26
|
+
|
27
|
+
test "rails g devise_invitable:views scoped" do
|
28
|
+
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:views octopussies -p`
|
29
|
+
assert @output.match(%r|create.+ app/views/octopussies\n|)
|
30
|
+
assert @output.match(%r|create.+ app/views/octopussies/invitations/edit\.html\.erb\n|)
|
31
|
+
assert @output.match(%r|create.+ app/views/octopussies/invitations/new\.html\.erb\n|)
|
32
|
+
assert @output.match(%r|create.+ app/views/octopussies/mailer/invitation\.html\.erb\n|)
|
33
|
+
end
|
34
|
+
|
35
|
+
test "rails g devise_invitable Octopussy" do
|
36
|
+
@output = `cd #{RAILS_APP_PATH} && rails g devise_invitable Octopussy -p`
|
37
|
+
assert @output.match(%r|inject.+ app/models/octopussy\.rb\n|)
|
38
|
+
assert @output.match(%r|invoke.+ #{DEVISE_ORM}\n|)
|
39
|
+
if DEVISE_ORM == :active_record
|
40
|
+
assert @output.match(%r|create.+ db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
|
41
|
+
elsif DEVISE_ORM == :mongoid
|
42
|
+
assert !@output.match(%r|create.+ db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# This model is here for the generators' specs
|
2
|
+
if DEVISE_ORM == :active_record
|
3
|
+
class Octopussy < ActiveRecord::Base
|
4
|
+
devise :database_authenticatable, :validatable, :confirmable
|
5
|
+
end
|
6
|
+
elsif DEVISE_ORM == :mongoid
|
7
|
+
class Octopussy
|
8
|
+
include Mongoid::Document
|
9
|
+
devise :database_authenticatable, :validatable, :confirmable
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<h2>Send an invitation</h2>
|
2
|
+
|
3
|
+
<%= form_for resource, :as => resource_name, :url => invitation_path(resource_name), :html => { :method => :post } do |f| %>
|
4
|
+
<%= devise_error_messages! %>
|
5
|
+
|
6
|
+
<p><%= f.label :username %></p>
|
7
|
+
<p><%= f.text_field :username %></p>
|
8
|
+
|
9
|
+
<p><%= f.label :email %></p>
|
10
|
+
<p><%= f.text_field :email %></p>
|
11
|
+
|
12
|
+
<p><%= f.submit "Send an invitation" %></p>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<%= link_to "Home", after_sign_in_path_for(resource_name) %><br />
|
@@ -47,7 +47,13 @@ Devise.setup do |config|
|
|
47
47
|
|
48
48
|
# Setup a pepper to generate the encrypted password.
|
49
49
|
config.pepper = "c9ed39f2a5faea59e2f9634cd5466703ead30a1fe25ab08cad00fe4d41d23467401fd731eaca1b1326d97b3065217daa81a18368ecc435978e6e868442b753ac"
|
50
|
-
|
50
|
+
|
51
|
+
# ==> Configuration for :invitable
|
52
|
+
# Time interval where the invitation token is valid.
|
53
|
+
# If invite_for is 0 or nil, the invitation will never expire.
|
54
|
+
# Default: 0
|
55
|
+
# config.invite_for = 2.weeks
|
56
|
+
|
51
57
|
# ==> Configuration for :confirmable
|
52
58
|
# The time you want to give your user to confirm his account. During this time
|
53
59
|
# he will be able to access your application without confirming. Default is nil.
|
@@ -107,11 +113,7 @@ Devise.setup do |config|
|
|
107
113
|
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
108
114
|
# "users/sessions/new". It's turned off by default because it's slower if you
|
109
115
|
# are using only default views.
|
110
|
-
|
111
|
-
|
112
|
-
# Configure the default scope given to Warden. By default it's the first
|
113
|
-
# devise role declared in your routes.
|
114
|
-
# config.default_scope = :user
|
116
|
+
config.scoped_views = true
|
115
117
|
|
116
118
|
# Configure sign_out behavior.
|
117
119
|
# By default sign_out is scoped (i.e. /users/sign_out affects only :user scope).
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
data/test/test_helper.rb
CHANGED
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: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 4
|
10
|
+
version: 0.3.4
|
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: 2010-
|
18
|
+
date: 2010-10-02 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -128,7 +128,12 @@ files:
|
|
128
128
|
- lib/devise_invitable/rails.rb
|
129
129
|
- lib/devise_invitable/routes.rb
|
130
130
|
- lib/devise_invitable/schema.rb
|
131
|
+
- lib/generators/active_record/devise_invitable_generator.rb
|
132
|
+
- lib/generators/active_record/templates/migration.rb
|
133
|
+
- lib/generators/devise_invitable/devise_invitable_generator.rb
|
134
|
+
- lib/generators/devise_invitable/install_generator.rb
|
131
135
|
- lib/generators/devise_invitable/views_generator.rb
|
136
|
+
- test/generators_test.rb
|
132
137
|
- test/integration/invitable_test.rb
|
133
138
|
- test/integration_tests_helper.rb
|
134
139
|
- test/mailers/invitation_test.rb
|
@@ -140,9 +145,11 @@ files:
|
|
140
145
|
- test/rails_app/app/controllers/home_controller.rb
|
141
146
|
- test/rails_app/app/controllers/users_controller.rb
|
142
147
|
- test/rails_app/app/helpers/application_helper.rb
|
148
|
+
- test/rails_app/app/models/octopussy.rb
|
143
149
|
- test/rails_app/app/models/user.rb
|
144
150
|
- test/rails_app/app/views/home/index.html.erb
|
145
151
|
- test/rails_app/app/views/layouts/application.html.erb
|
152
|
+
- test/rails_app/app/views/users/invitations/new.html.erb
|
146
153
|
- test/rails_app/config.ru
|
147
154
|
- test/rails_app/config/application.rb
|
148
155
|
- test/rails_app/config/boot.rb
|
@@ -159,6 +166,7 @@ files:
|
|
159
166
|
- test/rails_app/config/initializers/session_store.rb
|
160
167
|
- test/rails_app/config/locales/en.yml
|
161
168
|
- test/rails_app/config/routes.rb
|
169
|
+
- test/rails_app/script/rails
|
162
170
|
- test/routes_test.rb
|
163
171
|
- test/test_helper.rb
|
164
172
|
has_rdoc: true
|
@@ -196,10 +204,12 @@ signing_key:
|
|
196
204
|
specification_version: 3
|
197
205
|
summary: An invitation strategy for devise
|
198
206
|
test_files:
|
207
|
+
- test/generators_test.rb
|
199
208
|
- test/test_helper.rb
|
200
209
|
- test/integration/invitable_test.rb
|
201
210
|
- test/routes_test.rb
|
202
211
|
- test/rails_app/app/helpers/application_helper.rb
|
212
|
+
- test/rails_app/app/models/octopussy.rb
|
203
213
|
- test/rails_app/app/models/user.rb
|
204
214
|
- test/rails_app/app/controllers/admins_controller.rb
|
205
215
|
- test/rails_app/app/controllers/application_controller.rb
|