devise 2.1.2 → 3.5.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.travis.yml +39 -10
- data/.yardopts +9 -0
- data/{CHANGELOG.rdoc → CHANGELOG.md} +445 -112
- data/CODE_OF_CONDUCT.md +22 -0
- data/CONTRIBUTING.md +16 -0
- data/Gemfile +10 -15
- data/Gemfile.lock +151 -129
- data/MIT-LICENSE +1 -1
- data/README.md +256 -96
- data/Rakefile +4 -2
- data/app/controllers/devise/confirmations_controller.rb +15 -7
- data/app/controllers/devise/omniauth_callbacks_controller.rb +6 -2
- data/app/controllers/devise/passwords_controller.rb +33 -9
- data/app/controllers/devise/registrations_controller.rb +66 -26
- data/app/controllers/devise/sessions_controller.rb +52 -21
- data/app/controllers/devise/unlocks_controller.rb +11 -6
- data/app/controllers/devise_controller.rb +65 -58
- data/app/helpers/devise_helper.rb +2 -2
- data/app/mailers/devise/mailer.rb +19 -10
- data/app/views/devise/confirmations/new.html.erb +8 -4
- data/app/views/devise/mailer/confirmation_instructions.html.erb +2 -2
- data/app/views/devise/mailer/password_change.html.erb +3 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +2 -2
- data/app/views/devise/mailer/unlock_instructions.html.erb +2 -2
- data/app/views/devise/passwords/edit.html.erb +15 -6
- data/app/views/devise/passwords/new.html.erb +8 -4
- data/app/views/devise/registrations/edit.html.erb +29 -15
- data/app/views/devise/registrations/new.html.erb +19 -8
- data/app/views/devise/sessions/new.html.erb +17 -8
- data/app/views/devise/shared/{_links.erb → _links.html.erb} +4 -4
- data/app/views/devise/unlocks/new.html.erb +8 -4
- data/config/locales/en.yml +51 -47
- data/devise.gemspec +8 -6
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2-stable +29 -0
- data/gemfiles/Gemfile.rails-3.2-stable.lock +172 -0
- data/gemfiles/Gemfile.rails-4.0-stable +30 -0
- data/gemfiles/Gemfile.rails-4.0-stable.lock +166 -0
- data/gemfiles/Gemfile.rails-4.1-stable +30 -0
- data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
- data/gemfiles/Gemfile.rails-4.2-stable +30 -0
- data/gemfiles/Gemfile.rails-4.2-stable.lock +193 -0
- data/lib/devise/controllers/helpers.rb +126 -108
- data/lib/devise/controllers/rememberable.rb +19 -17
- data/lib/devise/controllers/scoped_views.rb +1 -1
- data/lib/devise/controllers/sign_in_out.rb +96 -0
- data/lib/devise/controllers/store_location.rb +58 -0
- data/lib/devise/controllers/url_helpers.rb +7 -7
- data/lib/devise/encryptor.rb +22 -0
- data/lib/devise/failure_app.rb +85 -25
- data/lib/devise/hooks/activatable.rb +5 -6
- data/lib/devise/hooks/csrf_cleaner.rb +7 -0
- data/lib/devise/hooks/forgetable.rb +1 -1
- data/lib/devise/hooks/lockable.rb +2 -2
- data/lib/devise/hooks/proxy.rb +21 -0
- data/lib/devise/hooks/rememberable.rb +5 -4
- data/lib/devise/hooks/timeoutable.rb +16 -8
- data/lib/devise/hooks/trackable.rb +1 -1
- data/lib/devise/mailers/helpers.rb +27 -23
- data/lib/devise/mapping.rb +11 -7
- data/lib/devise/models/authenticatable.rb +82 -66
- data/lib/devise/models/confirmable.rb +142 -55
- data/lib/devise/models/database_authenticatable.rb +59 -15
- data/lib/devise/models/lockable.rb +41 -30
- data/lib/devise/models/omniauthable.rb +3 -3
- data/lib/devise/models/recoverable.rb +56 -41
- data/lib/devise/models/rememberable.rb +65 -27
- data/lib/devise/models/timeoutable.rb +2 -8
- data/lib/devise/models/trackable.rb +6 -4
- data/lib/devise/models/validatable.rb +9 -9
- data/lib/devise/models.rb +4 -13
- data/lib/devise/modules.rb +10 -11
- data/lib/devise/omniauth/url_helpers.rb +2 -2
- data/lib/devise/orm/active_record.rb +1 -1
- data/lib/devise/orm/mongoid.rb +1 -1
- data/lib/devise/{param_filter.rb → parameter_filter.rb} +10 -11
- data/lib/devise/parameter_sanitizer.rb +99 -0
- data/lib/devise/rails/routes.rb +173 -115
- data/lib/devise/rails/warden_compat.rb +10 -31
- data/lib/devise/rails.rb +14 -12
- data/lib/devise/strategies/authenticatable.rb +26 -26
- data/lib/devise/strategies/base.rb +1 -1
- data/lib/devise/strategies/database_authenticatable.rb +8 -4
- data/lib/devise/strategies/rememberable.rb +15 -5
- data/lib/devise/test_helpers.rb +7 -5
- data/lib/devise/time_inflector.rb +14 -0
- data/lib/devise/token_generator.rb +70 -0
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +110 -52
- data/lib/generators/active_record/devise_generator.rb +34 -18
- data/lib/generators/active_record/templates/migration.rb +5 -6
- data/lib/generators/active_record/templates/migration_existing.rb +5 -6
- data/lib/generators/devise/controllers_generator.rb +44 -0
- data/lib/generators/devise/devise_generator.rb +5 -3
- data/lib/generators/devise/install_generator.rb +5 -0
- data/lib/generators/devise/orm_helpers.rb +25 -6
- data/lib/generators/devise/views_generator.rb +52 -22
- data/lib/generators/mongoid/devise_generator.rb +21 -26
- data/lib/generators/templates/README +9 -5
- data/lib/generators/templates/controllers/README +14 -0
- data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
- data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
- data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
- data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
- data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
- data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
- data/lib/generators/templates/devise.rb +80 -43
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +2 -2
- data/lib/generators/templates/markerb/password_change.markerb +3 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
- data/lib/generators/templates/markerb/unlock_instructions.markerb +2 -2
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +3 -2
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -6
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +6 -6
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +3 -2
- data/script/cached-bundle +49 -0
- data/script/s3-put +71 -0
- data/test/controllers/custom_registrations_controller_test.rb +40 -0
- data/test/controllers/helper_methods_test.rb +21 -0
- data/test/controllers/helpers_test.rb +95 -32
- data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
- data/test/controllers/internal_helpers_test.rb +39 -14
- data/test/controllers/load_hooks_controller_test.rb +19 -0
- data/test/controllers/passwords_controller_test.rb +31 -0
- data/test/controllers/sessions_controller_test.rb +66 -6
- data/test/controllers/url_helpers_test.rb +10 -4
- data/test/delegator_test.rb +1 -1
- data/test/devise_test.rb +45 -10
- data/test/failure_app_test.rb +121 -27
- data/test/generators/active_record_generator_test.rb +48 -8
- data/test/generators/controllers_generator_test.rb +48 -0
- data/test/generators/devise_generator_test.rb +2 -2
- data/test/generators/mongoid_generator_test.rb +3 -3
- data/test/generators/views_generator_test.rb +54 -3
- data/test/helpers/devise_helper_test.rb +18 -20
- data/test/integration/authenticatable_test.rb +161 -65
- data/test/integration/confirmable_test.rb +146 -77
- data/test/integration/database_authenticatable_test.rb +43 -30
- data/test/integration/http_authenticatable_test.rb +30 -22
- data/test/integration/lockable_test.rb +64 -49
- data/test/integration/omniauthable_test.rb +17 -15
- data/test/integration/recoverable_test.rb +111 -70
- data/test/integration/registerable_test.rb +114 -79
- data/test/integration/rememberable_test.rb +87 -31
- data/test/integration/timeoutable_test.rb +77 -33
- data/test/integration/trackable_test.rb +5 -5
- data/test/mailers/confirmation_instructions_test.rb +28 -8
- data/test/mailers/reset_password_instructions_test.rb +21 -8
- data/test/mailers/unlock_instructions_test.rb +20 -6
- data/test/mapping_test.rb +12 -5
- data/test/models/authenticatable_test.rb +17 -1
- data/test/models/confirmable_test.rb +216 -62
- data/test/models/database_authenticatable_test.rb +129 -49
- data/test/models/lockable_test.rb +132 -45
- data/test/models/recoverable_test.rb +100 -54
- data/test/models/rememberable_test.rb +89 -94
- data/test/models/serializable_test.rb +12 -11
- data/test/models/timeoutable_test.rb +6 -1
- data/test/models/trackable_test.rb +28 -0
- data/test/models/validatable_test.rb +31 -21
- data/test/models_test.rb +22 -48
- data/test/omniauth/config_test.rb +4 -4
- data/test/omniauth/url_helpers_test.rb +7 -4
- data/test/orm/active_record.rb +1 -0
- data/test/orm/mongoid.rb +2 -3
- data/test/parameter_sanitizer_test.rb +81 -0
- data/test/rails_app/Rakefile +0 -4
- data/test/rails_app/app/active_record/shim.rb +1 -1
- data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
- data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
- data/test/rails_app/app/active_record/user_without_email.rb +8 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/admins_controller.rb +0 -5
- data/test/rails_app/app/controllers/application_controller.rb +6 -2
- data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
- data/test/rails_app/app/controllers/custom/registrations_controller.rb +31 -0
- data/test/rails_app/app/controllers/home_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +4 -4
- data/test/rails_app/app/controllers/users_controller.rb +12 -4
- data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +1 -1
- data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
- data/test/rails_app/app/mongoid/admin.rb +12 -10
- data/test/rails_app/app/mongoid/shim.rb +4 -5
- data/test/rails_app/app/mongoid/user.rb +19 -22
- data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
- data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
- data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/home/index.html.erb +1 -1
- data/test/rails_app/app/views/home/join.html.erb +1 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
- data/test/rails_app/app/views/layouts/application.html.erb +1 -1
- data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
- data/test/rails_app/bin/bundle +3 -0
- data/test/rails_app/bin/rails +4 -0
- data/test/rails_app/bin/rake +4 -0
- data/test/rails_app/config/application.rb +4 -5
- data/test/rails_app/config/boot.rb +9 -3
- data/test/rails_app/config/environment.rb +2 -2
- data/test/rails_app/config/environments/development.rb +19 -7
- data/test/rails_app/config/environments/production.rb +68 -17
- data/test/rails_app/config/environments/test.rb +24 -16
- data/test/rails_app/config/initializers/devise.rb +22 -20
- data/test/rails_app/config/initializers/secret_token.rb +8 -2
- data/test/rails_app/config/initializers/session_store.rb +1 -0
- data/test/rails_app/config/routes.rb +71 -46
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +9 -12
- data/test/rails_app/db/schema.rb +21 -18
- data/test/rails_app/lib/shared_admin.rb +7 -4
- data/test/rails_app/lib/shared_user.rb +6 -3
- data/test/rails_app/lib/shared_user_without_email.rb +26 -0
- data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
- data/test/rails_test.rb +9 -0
- data/test/routes_test.rb +94 -78
- data/test/support/action_controller/record_identifier.rb +10 -0
- data/test/support/assertions.rb +2 -3
- data/test/support/helpers.rb +18 -32
- data/test/support/integration.rb +17 -16
- data/test/support/locale/en.yml +4 -0
- data/test/support/mongoid.yml +6 -0
- data/test/test_helper.rb +8 -1
- data/test/test_helpers_test.rb +64 -20
- data/test/test_models.rb +33 -0
- data/test/time_helpers.rb +137 -0
- metadata +172 -51
- data/app/views/devise/_links.erb +0 -3
- data/gemfiles/Gemfile.rails-3.1.x +0 -35
- data/gemfiles/Gemfile.rails-3.1.x.lock +0 -167
- data/lib/devise/models/token_authenticatable.rb +0 -77
- data/lib/devise/strategies/token_authenticatable.rb +0 -56
- data/test/indifferent_hash.rb +0 -33
- data/test/integration/token_authenticatable_test.rb +0 -161
- data/test/models/token_authenticatable_test.rb +0 -55
- data/test/rails_app/script/rails +0 -10
@@ -4,30 +4,31 @@ require 'generators/devise/orm_helpers'
|
|
4
4
|
module ActiveRecord
|
5
5
|
module Generators
|
6
6
|
class DeviseGenerator < ActiveRecord::Generators::Base
|
7
|
-
argument :attributes, :
|
7
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
8
8
|
|
9
9
|
include Devise::Generators::OrmHelpers
|
10
10
|
source_root File.expand_path("../templates", __FILE__)
|
11
11
|
|
12
12
|
def copy_devise_migration
|
13
13
|
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
|
14
|
-
migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}"
|
14
|
+
migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}.rb"
|
15
15
|
else
|
16
|
-
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
|
16
|
+
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}.rb"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def generate_model
|
21
|
-
invoke "active_record:model", [name], :
|
21
|
+
invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke
|
22
22
|
end
|
23
23
|
|
24
24
|
def inject_devise_content
|
25
|
-
content = model_contents
|
26
|
-
# Setup accessible (or protected) attributes for your model
|
27
|
-
attr_accessible :email, :password, :password_confirmation, :remember_me
|
28
|
-
CONTENT
|
25
|
+
content = model_contents
|
29
26
|
|
30
|
-
class_path =
|
27
|
+
class_path = if namespaced?
|
28
|
+
class_name.to_s.split("::")
|
29
|
+
else
|
30
|
+
[class_name]
|
31
|
+
end
|
31
32
|
|
32
33
|
indent_depth = class_path.size - 1
|
33
34
|
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
|
@@ -38,8 +39,8 @@ CONTENT
|
|
38
39
|
def migration_data
|
39
40
|
<<RUBY
|
40
41
|
## Database authenticatable
|
41
|
-
t.string :email, :
|
42
|
-
t.string :encrypted_password, :
|
42
|
+
t.string :email, null: false, default: ""
|
43
|
+
t.string :encrypted_password, null: false, default: ""
|
43
44
|
|
44
45
|
## Recoverable
|
45
46
|
t.string :reset_password_token
|
@@ -49,11 +50,11 @@ CONTENT
|
|
49
50
|
t.datetime :remember_created_at
|
50
51
|
|
51
52
|
## Trackable
|
52
|
-
t.integer :sign_in_count, :
|
53
|
+
t.integer :sign_in_count, default: 0, null: false
|
53
54
|
t.datetime :current_sign_in_at
|
54
55
|
t.datetime :last_sign_in_at
|
55
|
-
t
|
56
|
-
t
|
56
|
+
t.#{ip_column} :current_sign_in_ip
|
57
|
+
t.#{ip_column} :last_sign_in_ip
|
57
58
|
|
58
59
|
## Confirmable
|
59
60
|
# t.string :confirmation_token
|
@@ -62,14 +63,29 @@ CONTENT
|
|
62
63
|
# t.string :unconfirmed_email # Only if using reconfirmable
|
63
64
|
|
64
65
|
## Lockable
|
65
|
-
# t.integer :failed_attempts, :
|
66
|
+
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
66
67
|
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
67
68
|
# t.datetime :locked_at
|
68
|
-
|
69
|
-
## Token authenticatable
|
70
|
-
# t.string :authentication_token
|
71
69
|
RUBY
|
72
70
|
end
|
71
|
+
|
72
|
+
def ip_column
|
73
|
+
# Padded with spaces so it aligns nicely with the rest of the columns.
|
74
|
+
"%-8s" % (inet? ? "inet" : "string")
|
75
|
+
end
|
76
|
+
|
77
|
+
def inet?
|
78
|
+
rails4? && postgresql?
|
79
|
+
end
|
80
|
+
|
81
|
+
def rails4?
|
82
|
+
Rails.version.start_with? '4'
|
83
|
+
end
|
84
|
+
|
85
|
+
def postgresql?
|
86
|
+
config = ActiveRecord::Base.configurations[Rails.env]
|
87
|
+
config && config['adapter'] == 'postgresql'
|
88
|
+
end
|
73
89
|
end
|
74
90
|
end
|
75
91
|
end
|
@@ -7,13 +7,12 @@ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
7
7
|
t.<%= attribute.type %> :<%= attribute.name %>
|
8
8
|
<% end -%>
|
9
9
|
|
10
|
-
t.timestamps
|
10
|
+
t.timestamps null: false
|
11
11
|
end
|
12
12
|
|
13
|
-
add_index :<%= table_name %>, :email, :
|
14
|
-
add_index :<%= table_name %>, :reset_password_token, :
|
15
|
-
# add_index :<%= table_name %>, :confirmation_token, :
|
16
|
-
# add_index :<%= table_name %>, :unlock_token, :
|
17
|
-
# add_index :<%= table_name %>, :authentication_token, :unique => true
|
13
|
+
add_index :<%= table_name %>, :email, unique: true
|
14
|
+
add_index :<%= table_name %>, :reset_password_token, unique: true
|
15
|
+
# add_index :<%= table_name %>, :confirmation_token, unique: true
|
16
|
+
# add_index :<%= table_name %>, :unlock_token, unique: true
|
18
17
|
end
|
19
18
|
end
|
@@ -8,14 +8,13 @@ class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration
|
|
8
8
|
<% end -%>
|
9
9
|
|
10
10
|
# Uncomment below if timestamps were not included in your original model.
|
11
|
-
# t.timestamps
|
11
|
+
# t.timestamps null: false
|
12
12
|
end
|
13
13
|
|
14
|
-
add_index :<%= table_name %>, :email, :
|
15
|
-
add_index :<%= table_name %>, :reset_password_token, :
|
16
|
-
# add_index :<%= table_name %>, :confirmation_token, :
|
17
|
-
# add_index :<%= table_name %>, :unlock_token, :
|
18
|
-
# add_index :<%= table_name %>, :authentication_token, :unique => true
|
14
|
+
add_index :<%= table_name %>, :email, unique: true
|
15
|
+
add_index :<%= table_name %>, :reset_password_token, unique: true
|
16
|
+
# add_index :<%= table_name %>, :confirmation_token, unique: true
|
17
|
+
# add_index :<%= table_name %>, :unlock_token, unique: true
|
19
18
|
end
|
20
19
|
|
21
20
|
def self.down
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Generators
|
5
|
+
class ControllersGenerator < Rails::Generators::Base
|
6
|
+
CONTROLLERS = %w(confirmations passwords registrations sessions unlocks omniauth_callbacks).freeze
|
7
|
+
|
8
|
+
desc <<-DESC.strip_heredoc
|
9
|
+
Create inherited Devise controllers in your app/controllers folder.
|
10
|
+
|
11
|
+
Use -c to specify which controller you want to overwrite.
|
12
|
+
If you do no specify a controller, all controllers will be created.
|
13
|
+
For example:
|
14
|
+
|
15
|
+
rails generate devise:controllers users -c=sessions
|
16
|
+
|
17
|
+
This will create a controller class at app/controllers/users/sessions_controller.rb like this:
|
18
|
+
|
19
|
+
class Users::ConfirmationsController < Devise::ConfirmationsController
|
20
|
+
content...
|
21
|
+
end
|
22
|
+
DESC
|
23
|
+
|
24
|
+
source_root File.expand_path("../../templates/controllers", __FILE__)
|
25
|
+
argument :scope, required: true,
|
26
|
+
desc: "The scope to create controllers in, e.g. users, admins"
|
27
|
+
class_option :controllers, aliases: "-c", type: :array,
|
28
|
+
desc: "Select specific controllers to generate (#{CONTROLLERS.join(', ')})"
|
29
|
+
|
30
|
+
def create_controllers
|
31
|
+
@scope_prefix = scope.blank? ? '' : (scope.camelize + '::')
|
32
|
+
controllers = options[:controllers] || CONTROLLERS
|
33
|
+
controllers.each do |name|
|
34
|
+
template "#{name}_controller.rb",
|
35
|
+
"app/controllers/#{scope}/#{name}_controller.rb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def show_readme
|
40
|
+
readme "README" if behavior == :invoke
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
|
1
3
|
module Devise
|
2
4
|
module Generators
|
3
5
|
class DeviseGenerator < Rails::Generators::NamedBase
|
@@ -11,12 +13,12 @@ module Devise
|
|
11
13
|
|
12
14
|
hook_for :orm
|
13
15
|
|
14
|
-
class_option :routes, :
|
16
|
+
class_option :routes, desc: "Generate routes", type: :boolean, default: true
|
15
17
|
|
16
18
|
def add_devise_routes
|
17
19
|
devise_route = "devise_for :#{plural_name}"
|
18
|
-
devise_route << %Q(, :
|
19
|
-
devise_route << %Q(, :
|
20
|
+
devise_route << %Q(, class_name: "#{class_name}") if class_name.include?("::")
|
21
|
+
devise_route << %Q(, skip: :all) unless options.routes?
|
20
22
|
route devise_route
|
21
23
|
end
|
22
24
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rails/generators/base'
|
1
2
|
require 'securerandom'
|
2
3
|
|
3
4
|
module Devise
|
@@ -19,6 +20,10 @@ module Devise
|
|
19
20
|
def show_readme
|
20
21
|
readme "README" if behavior == :invoke
|
21
22
|
end
|
23
|
+
|
24
|
+
def rails_4?
|
25
|
+
Rails::VERSION::MAJOR == 4
|
26
|
+
end
|
22
27
|
end
|
23
28
|
end
|
24
29
|
end
|
@@ -2,24 +2,43 @@ module Devise
|
|
2
2
|
module Generators
|
3
3
|
module OrmHelpers
|
4
4
|
def model_contents
|
5
|
-
<<-CONTENT
|
5
|
+
buffer = <<-CONTENT
|
6
6
|
# Include default devise modules. Others available are:
|
7
|
-
# :
|
8
|
-
# :lockable, :timeoutable and :omniauthable
|
7
|
+
# :confirmable, :lockable, :timeoutable and :omniauthable
|
9
8
|
devise :database_authenticatable, :registerable,
|
10
9
|
:recoverable, :rememberable, :trackable, :validatable
|
11
10
|
|
12
11
|
CONTENT
|
12
|
+
buffer += <<-CONTENT if needs_attr_accessible?
|
13
|
+
# Setup accessible (or protected) attributes for your model
|
14
|
+
attr_accessible :email, :password, :password_confirmation, :remember_me
|
15
|
+
|
16
|
+
CONTENT
|
17
|
+
buffer
|
18
|
+
end
|
19
|
+
|
20
|
+
def needs_attr_accessible?
|
21
|
+
rails_3? && !strong_parameters_enabled?
|
22
|
+
end
|
23
|
+
|
24
|
+
def rails_3?
|
25
|
+
Rails::VERSION::MAJOR == 3
|
13
26
|
end
|
14
27
|
|
28
|
+
def strong_parameters_enabled?
|
29
|
+
defined?(ActionController::StrongParameters)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
15
34
|
def model_exists?
|
16
35
|
File.exists?(File.join(destination_root, model_path))
|
17
36
|
end
|
18
|
-
|
37
|
+
|
19
38
|
def migration_exists?(table_name)
|
20
39
|
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_devise_to_#{table_name}.rb$/).first
|
21
40
|
end
|
22
|
-
|
41
|
+
|
23
42
|
def migration_path
|
24
43
|
@migration_path ||= File.join("db", "migrate")
|
25
44
|
end
|
@@ -29,4 +48,4 @@ CONTENT
|
|
29
48
|
end
|
30
49
|
end
|
31
50
|
end
|
32
|
-
end
|
51
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
1
3
|
module Devise
|
2
4
|
module Generators
|
3
5
|
# Include this module in your generator to generate Devise views.
|
@@ -7,18 +9,19 @@ module Devise
|
|
7
9
|
extend ActiveSupport::Concern
|
8
10
|
|
9
11
|
included do
|
10
|
-
argument :scope, :
|
11
|
-
:
|
12
|
+
argument :scope, required: false, default: nil,
|
13
|
+
desc: "The scope to copy views to"
|
12
14
|
|
13
15
|
# Le sigh, ensure Thor won't handle opts as args
|
14
16
|
# It should be fixed in future Rails releases
|
15
|
-
class_option :form_builder, :
|
17
|
+
class_option :form_builder, aliases: "-b"
|
16
18
|
class_option :markerb
|
19
|
+
class_option :views, aliases: "-v", type: :array, desc: "Select specific view directories to generate (confirmations, passwords, registrations, sessions, unlocks, mailer)"
|
17
20
|
|
18
21
|
public_task :copy_views
|
19
22
|
end
|
20
23
|
|
21
|
-
# TODO: Add this to Rails
|
24
|
+
# TODO: Add this to Rails itself
|
22
25
|
module ClassMethods
|
23
26
|
def hide!
|
24
27
|
Rails::Generators.hide_namespace self.namespace
|
@@ -26,21 +29,37 @@ module Devise
|
|
26
29
|
end
|
27
30
|
|
28
31
|
def copy_views
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
if options[:views]
|
33
|
+
options[:views].each do |directory|
|
34
|
+
view_directory directory.to_sym
|
35
|
+
end
|
36
|
+
else
|
37
|
+
view_directory :confirmations
|
38
|
+
view_directory :passwords
|
39
|
+
view_directory :registrations
|
40
|
+
view_directory :sessions
|
41
|
+
view_directory :unlocks
|
42
|
+
end
|
34
43
|
end
|
35
44
|
|
36
45
|
protected
|
37
46
|
|
38
47
|
def view_directory(name, _target_path = nil)
|
39
|
-
directory name.to_s, _target_path || "#{target_path}/#{name}"
|
48
|
+
directory name.to_s, _target_path || "#{target_path}/#{name}" do |content|
|
49
|
+
if scope
|
50
|
+
content.gsub "devise/shared/links", "#{plural_scope}/shared/links"
|
51
|
+
else
|
52
|
+
content
|
53
|
+
end
|
54
|
+
end
|
40
55
|
end
|
41
56
|
|
42
57
|
def target_path
|
43
|
-
@target_path ||= "app/views/#{
|
58
|
+
@target_path ||= "app/views/#{plural_scope || :devise}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def plural_scope
|
62
|
+
@plural_scope ||= scope.presence && scope.underscore.pluralize
|
44
63
|
end
|
45
64
|
end
|
46
65
|
|
@@ -68,6 +87,13 @@ module Devise
|
|
68
87
|
source_root File.expand_path("../../templates/simple_form_for", __FILE__)
|
69
88
|
desc "Copies simple form enabled views to your application."
|
70
89
|
hide!
|
90
|
+
|
91
|
+
def copy_views
|
92
|
+
if options[:views]
|
93
|
+
options[:views].delete('mailer')
|
94
|
+
end
|
95
|
+
super
|
96
|
+
end
|
71
97
|
end
|
72
98
|
|
73
99
|
class ErbGenerator < Rails::Generators::Base #:nodoc:
|
@@ -77,7 +103,9 @@ module Devise
|
|
77
103
|
hide!
|
78
104
|
|
79
105
|
def copy_views
|
80
|
-
|
106
|
+
if !options[:views] || options[:views].include?('mailer')
|
107
|
+
view_directory :mailer
|
108
|
+
end
|
81
109
|
end
|
82
110
|
end
|
83
111
|
|
@@ -88,29 +116,31 @@ module Devise
|
|
88
116
|
hide!
|
89
117
|
|
90
118
|
def copy_views
|
91
|
-
|
119
|
+
if !options[:views] || options[:views].include?('mailer')
|
120
|
+
view_directory :markerb, target_path
|
121
|
+
end
|
92
122
|
end
|
93
123
|
|
94
124
|
def target_path
|
95
|
-
"app/views/#{
|
125
|
+
"app/views/#{plural_scope || :devise}/mailer"
|
96
126
|
end
|
97
127
|
end
|
98
128
|
|
99
129
|
class ViewsGenerator < Rails::Generators::Base
|
100
130
|
desc "Copies Devise views to your application."
|
101
131
|
|
102
|
-
argument :scope, :
|
103
|
-
:
|
132
|
+
argument :scope, required: false, default: nil,
|
133
|
+
desc: "The scope to copy views to"
|
104
134
|
|
105
135
|
invoke SharedViewsGenerator
|
106
136
|
|
107
|
-
hook_for :form_builder, :
|
108
|
-
:
|
109
|
-
:
|
137
|
+
hook_for :form_builder, aliases: "-b",
|
138
|
+
desc: "Form builder to be used",
|
139
|
+
default: defined?(SimpleForm) ? "simple_form_for" : "form_for"
|
110
140
|
|
111
|
-
hook_for :markerb, :
|
112
|
-
:
|
113
|
-
:
|
141
|
+
hook_for :markerb, desc: "Generate markerb instead of erb mail views",
|
142
|
+
default: defined?(Markerb) ? :markerb : :erb,
|
143
|
+
type: :boolean
|
114
144
|
end
|
115
145
|
end
|
116
146
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
1
2
|
require 'generators/devise/orm_helpers'
|
2
3
|
|
3
4
|
module Mongoid
|
@@ -10,51 +11,45 @@ module Mongoid
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def inject_field_types
|
13
|
-
inject_into_file model_path, migration_data, :
|
14
|
+
inject_into_file model_path, migration_data, after: "include Mongoid::Document\n" if model_exists?
|
14
15
|
end
|
15
16
|
|
16
17
|
def inject_devise_content
|
17
|
-
inject_into_file model_path, model_contents, :
|
18
|
+
inject_into_file model_path, model_contents, after: "include Mongoid::Document\n" if model_exists?
|
18
19
|
end
|
19
20
|
|
20
21
|
def migration_data
|
21
22
|
<<RUBY
|
22
23
|
## Database authenticatable
|
23
|
-
field :email, :
|
24
|
-
field :encrypted_password, :
|
24
|
+
field :email, type: String, default: ""
|
25
|
+
field :encrypted_password, type: String, default: ""
|
25
26
|
|
26
|
-
validates_presence_of :email
|
27
|
-
validates_presence_of :encrypted_password
|
28
|
-
|
29
27
|
## Recoverable
|
30
|
-
field :reset_password_token, :
|
31
|
-
field :reset_password_sent_at, :
|
28
|
+
field :reset_password_token, type: String
|
29
|
+
field :reset_password_sent_at, type: Time
|
32
30
|
|
33
31
|
## Rememberable
|
34
|
-
field :remember_created_at, :
|
32
|
+
field :remember_created_at, type: Time
|
35
33
|
|
36
34
|
## Trackable
|
37
|
-
field :sign_in_count, :
|
38
|
-
field :current_sign_in_at, :
|
39
|
-
field :last_sign_in_at, :
|
40
|
-
field :current_sign_in_ip, :
|
41
|
-
field :last_sign_in_ip, :
|
35
|
+
field :sign_in_count, type: Integer, default: 0
|
36
|
+
field :current_sign_in_at, type: Time
|
37
|
+
field :last_sign_in_at, type: Time
|
38
|
+
field :current_sign_in_ip, type: String
|
39
|
+
field :last_sign_in_ip, type: String
|
42
40
|
|
43
41
|
## Confirmable
|
44
|
-
# field :confirmation_token, :
|
45
|
-
# field :confirmed_at, :
|
46
|
-
# field :confirmation_sent_at, :
|
47
|
-
# field :unconfirmed_email, :
|
42
|
+
# field :confirmation_token, type: String
|
43
|
+
# field :confirmed_at, type: Time
|
44
|
+
# field :confirmation_sent_at, type: Time
|
45
|
+
# field :unconfirmed_email, type: String # Only if using reconfirmable
|
48
46
|
|
49
47
|
## Lockable
|
50
|
-
# field :failed_attempts, :
|
51
|
-
# field :unlock_token, :
|
52
|
-
# field :locked_at, :
|
53
|
-
|
54
|
-
## Token authenticatable
|
55
|
-
# field :authentication_token, :type => String
|
48
|
+
# field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
|
49
|
+
# field :unlock_token, type: String # Only if unlock strategy is :email or :both
|
50
|
+
# field :locked_at, type: Time
|
56
51
|
RUBY
|
57
52
|
end
|
58
53
|
end
|
59
54
|
end
|
60
|
-
end
|
55
|
+
end
|