upstream-devise 2.1.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.rdoc +846 -0
- data/Gemfile +35 -0
- data/Gemfile.lock +165 -0
- data/MIT-LICENSE +20 -0
- data/README.md +384 -0
- data/Rakefile +34 -0
- data/app/controllers/devise/confirmations_controller.rb +43 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +24 -0
- data/app/controllers/devise/passwords_controller.rb +47 -0
- data/app/controllers/devise/registrations_controller.rb +107 -0
- data/app/controllers/devise/sessions_controller.rb +49 -0
- data/app/controllers/devise/unlocks_controller.rb +44 -0
- data/app/controllers/devise_controller.rb +177 -0
- data/app/helpers/devise_helper.rb +25 -0
- data/app/mailers/devise/mailer.rb +15 -0
- data/app/views/devise/_links.erb +3 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/app/views/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/app/views/devise/registrations/edit.html.erb +25 -0
- data/app/views/devise/registrations/new.html.erb +18 -0
- data/app/views/devise/sessions/new.html.erb +17 -0
- data/app/views/devise/shared/_links.erb +25 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/config/locales/en.yml +57 -0
- data/devise.gemspec +25 -0
- data/gemfiles/Gemfile.rails-3.1.x +35 -0
- data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
- data/lib/devise.rb +455 -0
- data/lib/devise/controllers/helpers.rb +269 -0
- data/lib/devise/controllers/rememberable.rb +52 -0
- data/lib/devise/controllers/scoped_views.rb +17 -0
- data/lib/devise/controllers/url_helpers.rb +67 -0
- data/lib/devise/delegator.rb +17 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
- data/lib/devise/encryptors/base.rb +24 -0
- data/lib/devise/encryptors/clearance_sha1.rb +17 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +25 -0
- data/lib/devise/encryptors/sha512.rb +25 -0
- data/lib/devise/failure_app.rb +185 -0
- data/lib/devise/hooks/activatable.rb +11 -0
- data/lib/devise/hooks/forgetable.rb +9 -0
- data/lib/devise/hooks/lockable.rb +7 -0
- data/lib/devise/hooks/rememberable.rb +6 -0
- data/lib/devise/hooks/timeoutable.rb +22 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mailers/helpers.rb +86 -0
- data/lib/devise/mapping.rb +172 -0
- data/lib/devise/models.rb +123 -0
- data/lib/devise/models/authenticatable.rb +231 -0
- data/lib/devise/models/confirmable.rb +242 -0
- data/lib/devise/models/database_authenticatable.rb +126 -0
- data/lib/devise/models/encryptable.rb +86 -0
- data/lib/devise/models/lockable.rb +185 -0
- data/lib/devise/models/omniauthable.rb +27 -0
- data/lib/devise/models/recoverable.rb +140 -0
- data/lib/devise/models/registerable.rb +25 -0
- data/lib/devise/models/rememberable.rb +125 -0
- data/lib/devise/models/timeoutable.rb +49 -0
- data/lib/devise/models/token_authenticatable.rb +77 -0
- data/lib/devise/models/trackable.rb +35 -0
- data/lib/devise/models/validatable.rb +66 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/omniauth.rb +28 -0
- data/lib/devise/omniauth/config.rb +45 -0
- data/lib/devise/omniauth/url_helpers.rb +33 -0
- data/lib/devise/orm/active_record.rb +3 -0
- data/lib/devise/orm/mongoid.rb +3 -0
- data/lib/devise/param_filter.rb +41 -0
- data/lib/devise/rails.rb +54 -0
- data/lib/devise/rails/routes.rb +412 -0
- data/lib/devise/rails/warden_compat.rb +43 -0
- data/lib/devise/strategies/authenticatable.rb +165 -0
- data/lib/devise/strategies/base.rb +15 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +53 -0
- data/lib/devise/strategies/token_authenticatable.rb +57 -0
- data/lib/devise/test_helpers.rb +130 -0
- data/lib/devise/version.rb +3 -0
- data/lib/generators/active_record/devise_generator.rb +78 -0
- data/lib/generators/active_record/templates/migration.rb +19 -0
- data/lib/generators/active_record/templates/migration_existing.rb +26 -0
- data/lib/generators/devise/devise_generator.rb +24 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +32 -0
- data/lib/generators/devise/views_generator.rb +110 -0
- data/lib/generators/mongoid/devise_generator.rb +60 -0
- data/lib/generators/templates/README +31 -0
- data/lib/generators/templates/devise.rb +216 -0
- data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
- data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
- data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
- data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
- data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
- data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
- data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
- data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
- data/test/controllers/custom_strategy_test.rb +62 -0
- data/test/controllers/helpers_test.rb +254 -0
- data/test/controllers/internal_helpers_test.rb +97 -0
- data/test/controllers/sessions_controller_test.rb +36 -0
- data/test/controllers/url_helpers_test.rb +59 -0
- data/test/delegator_test.rb +19 -0
- data/test/devise_test.rb +72 -0
- data/test/encryptors_test.rb +30 -0
- data/test/failure_app_test.rb +211 -0
- data/test/generators/active_record_generator_test.rb +69 -0
- data/test/generators/devise_generator_test.rb +39 -0
- data/test/generators/install_generator_test.rb +13 -0
- data/test/generators/mongoid_generator_test.rb +23 -0
- data/test/generators/views_generator_test.rb +52 -0
- data/test/helpers/devise_helper_test.rb +51 -0
- data/test/indifferent_hash.rb +33 -0
- data/test/integration/authenticatable_test.rb +587 -0
- data/test/integration/confirmable_test.rb +255 -0
- data/test/integration/database_authenticatable_test.rb +82 -0
- data/test/integration/http_authenticatable_test.rb +97 -0
- data/test/integration/lockable_test.rb +224 -0
- data/test/integration/omniauthable_test.rb +133 -0
- data/test/integration/recoverable_test.rb +300 -0
- data/test/integration/registerable_test.rb +324 -0
- data/test/integration/rememberable_test.rb +158 -0
- data/test/integration/timeoutable_test.rb +114 -0
- data/test/integration/token_authenticatable_test.rb +161 -0
- data/test/integration/trackable_test.rb +92 -0
- data/test/mailers/confirmation_instructions_test.rb +95 -0
- data/test/mailers/reset_password_instructions_test.rb +83 -0
- data/test/mailers/unlock_instructions_test.rb +77 -0
- data/test/mapping_test.rb +127 -0
- data/test/models/authenticatable_test.rb +7 -0
- data/test/models/confirmable_test.rb +357 -0
- data/test/models/database_authenticatable_test.rb +189 -0
- data/test/models/encryptable_test.rb +73 -0
- data/test/models/lockable_test.rb +263 -0
- data/test/models/omniauthable_test.rb +7 -0
- data/test/models/recoverable_test.rb +205 -0
- data/test/models/registerable_test.rb +7 -0
- data/test/models/rememberable_test.rb +174 -0
- data/test/models/serializable_test.rb +48 -0
- data/test/models/timeoutable_test.rb +46 -0
- data/test/models/token_authenticatable_test.rb +55 -0
- data/test/models/trackable_test.rb +13 -0
- data/test/models/validatable_test.rb +117 -0
- data/test/models_test.rb +179 -0
- data/test/omniauth/config_test.rb +57 -0
- data/test/omniauth/url_helpers_test.rb +58 -0
- data/test/orm/active_record.rb +9 -0
- data/test/orm/mongoid.rb +14 -0
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/active_record/admin.rb +6 -0
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +6 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +8 -0
- data/test/rails_app/app/controllers/home_controller.rb +25 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
- data/test/rails_app/app/controllers/users_controller.rb +23 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mailers/users/mailer.rb +3 -0
- data/test/rails_app/app/mongoid/admin.rb +30 -0
- data/test/rails_app/app/mongoid/shim.rb +24 -0
- data/test/rails_app/app/mongoid/user.rb +45 -0
- data/test/rails_app/app/views/admins/index.html.erb +1 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/home/index.html.erb +1 -0
- data/test/rails_app/app/views/home/join.html.erb +1 -0
- data/test/rails_app/app/views/home/private.html.erb +1 -0
- data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +24 -0
- data/test/rails_app/app/views/users/index.html.erb +1 -0
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
- data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +41 -0
- data/test/rails_app/config/boot.rb +8 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +18 -0
- data/test/rails_app/config/environments/production.rb +33 -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 +186 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +90 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +77 -0
- data/test/rails_app/db/schema.rb +52 -0
- data/test/rails_app/lib/shared_admin.rb +14 -0
- data/test/rails_app/lib/shared_user.rb +26 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +10 -0
- data/test/routes_test.rb +248 -0
- data/test/support/assertions.rb +42 -0
- data/test/support/helpers.rb +91 -0
- data/test/support/integration.rb +90 -0
- data/test/support/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +24 -0
- data/test/test_helper.rb +27 -0
- data/test/test_helpers_test.rb +134 -0
- metadata +451 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'generators/devise/orm_helpers'
|
3
|
+
|
4
|
+
module ActiveRecord
|
5
|
+
module Generators
|
6
|
+
class DeviseGenerator < ActiveRecord::Generators::Base
|
7
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
8
|
+
|
9
|
+
include Devise::Generators::OrmHelpers
|
10
|
+
source_root File.expand_path("../templates", __FILE__)
|
11
|
+
|
12
|
+
def copy_devise_migration
|
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}"
|
15
|
+
else
|
16
|
+
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_model
|
21
|
+
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
22
|
+
end
|
23
|
+
|
24
|
+
def inject_devise_content
|
25
|
+
content = model_contents + <<CONTENT
|
26
|
+
# Setup accessible (or protected) attributes for your model
|
27
|
+
attr_accessible :email, :password, :password_confirmation, :remember_me
|
28
|
+
CONTENT
|
29
|
+
|
30
|
+
class_path = class_name.to_s.split("::")
|
31
|
+
|
32
|
+
indent_depth = class_path.size - 1
|
33
|
+
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n")
|
34
|
+
|
35
|
+
inject_into_class(model_path, class_path.last, content) if model_exists?
|
36
|
+
end
|
37
|
+
|
38
|
+
def migration_data
|
39
|
+
<<RUBY
|
40
|
+
## Database authenticatable
|
41
|
+
t.string :email, :null => false, :default => ""
|
42
|
+
t.string :encrypted_password, :null => false, :default => ""
|
43
|
+
|
44
|
+
## Recoverable
|
45
|
+
t.string :reset_password_token
|
46
|
+
t.datetime :reset_password_sent_at
|
47
|
+
|
48
|
+
## Rememberable
|
49
|
+
t.datetime :remember_created_at
|
50
|
+
|
51
|
+
## Trackable
|
52
|
+
t.integer :sign_in_count, :default => 0
|
53
|
+
t.datetime :current_sign_in_at
|
54
|
+
t.datetime :last_sign_in_at
|
55
|
+
t.string :current_sign_in_ip
|
56
|
+
t.string :last_sign_in_ip
|
57
|
+
|
58
|
+
## Encryptable
|
59
|
+
# t.string :password_salt
|
60
|
+
|
61
|
+
## Confirmable
|
62
|
+
# t.string :confirmation_token
|
63
|
+
# t.datetime :confirmed_at
|
64
|
+
# t.datetime :confirmation_sent_at
|
65
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
66
|
+
|
67
|
+
## Lockable
|
68
|
+
# t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
|
69
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
70
|
+
# t.datetime :locked_at
|
71
|
+
|
72
|
+
## Token authenticatable
|
73
|
+
# t.string :authentication_token
|
74
|
+
RUBY
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table(:<%= table_name %>) do |t|
|
4
|
+
<%= migration_data -%>
|
5
|
+
|
6
|
+
<% attributes.each do |attribute| -%>
|
7
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
+
<% end -%>
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
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
|
17
|
+
# add_index :<%= table_name %>, :authentication_token, :unique => true
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_table(:<%= table_name %>) do |t|
|
4
|
+
<%= migration_data -%>
|
5
|
+
|
6
|
+
<% attributes.each do |attribute| -%>
|
7
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
+
<% end -%>
|
9
|
+
|
10
|
+
# Uncomment below if timestamps were not included in your original model.
|
11
|
+
# t.timestamps
|
12
|
+
end
|
13
|
+
|
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
|
18
|
+
# add_index :<%= table_name %>, :authentication_token, :unique => true
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.down
|
22
|
+
# By default, we don't want to make any assumption about how to roll back a migration when your
|
23
|
+
# model already existed. Please edit below which fields you would like to remove in this migration.
|
24
|
+
raise ActiveRecord::IrreversibleMigration
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Devise
|
2
|
+
module Generators
|
3
|
+
class DeviseGenerator < Rails::Generators::NamedBase
|
4
|
+
include Rails::Generators::ResourceHelpers
|
5
|
+
|
6
|
+
namespace "devise"
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
8
|
+
|
9
|
+
desc "Generates a model with the given NAME (if one does not exist) with devise " <<
|
10
|
+
"configuration plus a migration file and devise routes."
|
11
|
+
|
12
|
+
hook_for :orm
|
13
|
+
|
14
|
+
class_option :routes, :desc => "Generate routes", :type => :boolean, :default => true
|
15
|
+
|
16
|
+
def add_devise_routes
|
17
|
+
devise_route = "devise_for :#{plural_name}"
|
18
|
+
devise_route << %Q(, :class_name => "#{class_name}") if class_name.include?("::")
|
19
|
+
devise_route << %Q(, :skip => :all) unless options.routes?
|
20
|
+
route devise_route
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
7
|
+
|
8
|
+
desc "Creates a Devise initializer and copy locale files to your application."
|
9
|
+
class_option :orm
|
10
|
+
|
11
|
+
def copy_initializer
|
12
|
+
template "devise.rb", "config/initializers/devise.rb"
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy_locale
|
16
|
+
copy_file "../../../config/locales/en.yml", "config/locales/devise.en.yml"
|
17
|
+
end
|
18
|
+
|
19
|
+
def show_readme
|
20
|
+
readme "README" if behavior == :invoke
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Devise
|
2
|
+
module Generators
|
3
|
+
module OrmHelpers
|
4
|
+
def model_contents
|
5
|
+
<<-CONTENT
|
6
|
+
# Include default devise modules. Others available are:
|
7
|
+
# :token_authenticatable, :encryptable, :confirmable,
|
8
|
+
# :lockable, :timeoutable and :omniauthable
|
9
|
+
devise :database_authenticatable, :registerable,
|
10
|
+
:recoverable, :rememberable, :trackable, :validatable
|
11
|
+
|
12
|
+
CONTENT
|
13
|
+
end
|
14
|
+
|
15
|
+
def model_exists?
|
16
|
+
File.exists?(File.join(destination_root, model_path))
|
17
|
+
end
|
18
|
+
|
19
|
+
def migration_exists?(table_name)
|
20
|
+
Dir.glob("#{File.join(destination_root, migration_path)}/[0-9]*_*.rb").grep(/\d+_add_devise_to_#{table_name}.rb$/).first
|
21
|
+
end
|
22
|
+
|
23
|
+
def migration_path
|
24
|
+
@migration_path ||= File.join("db", "migrate")
|
25
|
+
end
|
26
|
+
|
27
|
+
def model_path
|
28
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module Devise
|
2
|
+
module Generators
|
3
|
+
# Include this module in your generator to generate Devise views.
|
4
|
+
# `copy_views` is the main method and by default copies all views
|
5
|
+
# with forms.
|
6
|
+
module ViewPathTemplates #:nodoc:
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
argument :scope, :required => false, :default => nil,
|
11
|
+
:desc => "The scope to copy views to"
|
12
|
+
|
13
|
+
public_task :copy_views
|
14
|
+
end
|
15
|
+
|
16
|
+
# TODO: Add this to Rails itslef
|
17
|
+
module ClassMethods
|
18
|
+
def hide!
|
19
|
+
Rails::Generators.hide_namespace self.namespace
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def copy_views
|
24
|
+
view_directory :confirmations
|
25
|
+
view_directory :passwords
|
26
|
+
view_directory :registrations
|
27
|
+
view_directory :sessions
|
28
|
+
view_directory :unlocks
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def view_directory(name, _target_path = nil)
|
34
|
+
directory name.to_s, _target_path || "#{target_path}/#{name}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def target_path
|
38
|
+
@target_path ||= "app/views/#{scope || :devise}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class SharedViewsGenerator < Rails::Generators::Base #:nodoc:
|
43
|
+
include ViewPathTemplates
|
44
|
+
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
45
|
+
desc "Copies shared Devise views to your application."
|
46
|
+
hide!
|
47
|
+
|
48
|
+
# Override copy_views to just copy mailer and shared.
|
49
|
+
def copy_views
|
50
|
+
view_directory :shared
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class FormForGenerator < Rails::Generators::Base #:nodoc:
|
55
|
+
include ViewPathTemplates
|
56
|
+
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
57
|
+
desc "Copies default Devise views to your application."
|
58
|
+
hide!
|
59
|
+
end
|
60
|
+
|
61
|
+
class SimpleFormForGenerator < Rails::Generators::Base #:nodoc:
|
62
|
+
include ViewPathTemplates
|
63
|
+
source_root File.expand_path("../../templates/simple_form_for", __FILE__)
|
64
|
+
desc "Copies simple form enabled views to your application."
|
65
|
+
hide!
|
66
|
+
end
|
67
|
+
|
68
|
+
class ErbGenerator < Rails::Generators::Base #:nodoc:
|
69
|
+
include ViewPathTemplates
|
70
|
+
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
71
|
+
desc "Copies Devise mail erb views to your application."
|
72
|
+
hide!
|
73
|
+
|
74
|
+
def copy_views
|
75
|
+
view_directory :mailer
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class MarkerbGenerator < Rails::Generators::Base #:nodoc:
|
80
|
+
include ViewPathTemplates
|
81
|
+
source_root File.expand_path("../../templates", __FILE__)
|
82
|
+
desc "Copies Devise mail markerb views to your application."
|
83
|
+
hide!
|
84
|
+
|
85
|
+
def copy_views
|
86
|
+
view_directory :markerb, target_path
|
87
|
+
end
|
88
|
+
|
89
|
+
def target_path
|
90
|
+
"app/views/#{scope || :devise}/mailer"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class ViewsGenerator < Rails::Generators::Base
|
95
|
+
desc "Copies Devise views to your application."
|
96
|
+
|
97
|
+
argument :scope, :required => false, :default => nil,
|
98
|
+
:desc => "The scope to copy views to"
|
99
|
+
|
100
|
+
invoke SharedViewsGenerator
|
101
|
+
hook_for :form_builder, :aliases => "-b",
|
102
|
+
:desc => "Form builder to be used",
|
103
|
+
:default => defined?(SimpleForm) ? "simple_form_for" : "form_for"
|
104
|
+
|
105
|
+
hook_for :markerb, :desc => "Generate markerb instead of erb mail views",
|
106
|
+
:default => defined?(Markerb) ? :markerb : :erb,
|
107
|
+
:type => :boolean
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'generators/devise/orm_helpers'
|
2
|
+
|
3
|
+
module Mongoid
|
4
|
+
module Generators
|
5
|
+
class DeviseGenerator < Rails::Generators::NamedBase
|
6
|
+
include Devise::Generators::OrmHelpers
|
7
|
+
|
8
|
+
def generate_model
|
9
|
+
invoke "mongoid:model", [name] unless model_exists? && behavior == :invoke
|
10
|
+
end
|
11
|
+
|
12
|
+
def inject_field_types
|
13
|
+
inject_into_file model_path, migration_data, :after => "include Mongoid::Document\n" if model_exists?
|
14
|
+
end
|
15
|
+
|
16
|
+
def inject_devise_content
|
17
|
+
inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n" if model_exists?
|
18
|
+
end
|
19
|
+
|
20
|
+
def migration_data
|
21
|
+
<<RUBY
|
22
|
+
## Database authenticatable
|
23
|
+
field :email, :type => String, :null => false, :default => ""
|
24
|
+
field :encrypted_password, :type => String, :null => false, :default => ""
|
25
|
+
|
26
|
+
## Recoverable
|
27
|
+
field :reset_password_token, :type => String
|
28
|
+
field :reset_password_sent_at, :type => Time
|
29
|
+
|
30
|
+
## Rememberable
|
31
|
+
field :remember_created_at, :type => Time
|
32
|
+
|
33
|
+
## Trackable
|
34
|
+
field :sign_in_count, :type => Integer, :default => 0
|
35
|
+
field :current_sign_in_at, :type => Time
|
36
|
+
field :last_sign_in_at, :type => Time
|
37
|
+
field :current_sign_in_ip, :type => String
|
38
|
+
field :last_sign_in_ip, :type => String
|
39
|
+
|
40
|
+
## Encryptable
|
41
|
+
# field :password_salt, :type => String
|
42
|
+
|
43
|
+
## Confirmable
|
44
|
+
# field :confirmation_token, :type => String
|
45
|
+
# field :confirmed_at, :type => Time
|
46
|
+
# field :confirmation_sent_at, :type => Time
|
47
|
+
# field :unconfirmed_email, :type => String # Only if using reconfirmable
|
48
|
+
|
49
|
+
## Lockable
|
50
|
+
# field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts
|
51
|
+
# field :unlock_token, :type => String # Only if unlock strategy is :email or :both
|
52
|
+
# field :locked_at, :type => Time
|
53
|
+
|
54
|
+
## Token authenticatable
|
55
|
+
# field :authentication_token, :type => String
|
56
|
+
RUBY
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
===============================================================================
|
2
|
+
|
3
|
+
Some setup you must do manually if you haven't yet:
|
4
|
+
|
5
|
+
1. Ensure you have defined default url options in your environments files. Here
|
6
|
+
is an example of default_url_options appropriate for a development environment
|
7
|
+
in config/environments/development.rb:
|
8
|
+
|
9
|
+
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
10
|
+
|
11
|
+
In production, :host should be set to the actual host of your application.
|
12
|
+
|
13
|
+
2. Ensure you have defined root_url to *something* in your config/routes.rb.
|
14
|
+
For example:
|
15
|
+
|
16
|
+
root :to => "home#index"
|
17
|
+
|
18
|
+
3. Ensure you have flash messages in app/views/layouts/application.html.erb.
|
19
|
+
For example:
|
20
|
+
|
21
|
+
<p class="notice"><%= notice %></p>
|
22
|
+
<p class="alert"><%= alert %></p>
|
23
|
+
|
24
|
+
4. If you are deploying Rails 3.1 on Heroku, you may want to set:
|
25
|
+
|
26
|
+
config.assets.initialize_on_precompile = false
|
27
|
+
|
28
|
+
On config/application.rb forcing your application to not access the DB
|
29
|
+
or load models when precompiling your assets.
|
30
|
+
|
31
|
+
===============================================================================
|
@@ -0,0 +1,216 @@
|
|
1
|
+
# Use this hook to configure devise mailer, warden hooks and so forth.
|
2
|
+
# Many of these configuration options can be set straight in your model.
|
3
|
+
Devise.setup do |config|
|
4
|
+
# ==> Mailer Configuration
|
5
|
+
# Configure the e-mail address which will be shown in Devise::Mailer,
|
6
|
+
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
|
7
|
+
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
|
8
|
+
|
9
|
+
# Configure the class responsible to send e-mails.
|
10
|
+
# config.mailer = "Devise::Mailer"
|
11
|
+
|
12
|
+
# ==> ORM configuration
|
13
|
+
# Load and configure the ORM. Supports :active_record (default) and
|
14
|
+
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
15
|
+
# available as additional gems.
|
16
|
+
require 'devise/orm/<%= options[:orm] %>'
|
17
|
+
|
18
|
+
# ==> Configuration for any authentication mechanism
|
19
|
+
# Configure which keys are used when authenticating a user. The default is
|
20
|
+
# just :email. You can configure it to use [:username, :subdomain], so for
|
21
|
+
# authenticating a user, both parameters are required. Remember that those
|
22
|
+
# parameters are used only when authenticating and not when retrieving from
|
23
|
+
# session. If you need permissions, you should implement that in a before filter.
|
24
|
+
# You can also supply a hash where the value is a boolean determining whether
|
25
|
+
# or not authentication should be aborted when the value is not present.
|
26
|
+
# config.authentication_keys = [ :email ]
|
27
|
+
|
28
|
+
# Configure parameters from the request object used for authentication. Each entry
|
29
|
+
# given should be a request method and it will automatically be passed to the
|
30
|
+
# find_for_authentication method and considered in your model lookup. For instance,
|
31
|
+
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
|
32
|
+
# The same considerations mentioned for authentication_keys also apply to request_keys.
|
33
|
+
# config.request_keys = []
|
34
|
+
|
35
|
+
# Configure which authentication keys should be case-insensitive.
|
36
|
+
# These keys will be downcased upon creating or modifying a user and when used
|
37
|
+
# to authenticate or find a user. Default is :email.
|
38
|
+
config.case_insensitive_keys = [ :email ]
|
39
|
+
|
40
|
+
# Configure which authentication keys should have whitespace stripped.
|
41
|
+
# These keys will have whitespace before and after removed upon creating or
|
42
|
+
# modifying a user and when used to authenticate or find a user. Default is :email.
|
43
|
+
config.strip_whitespace_keys = [ :email ]
|
44
|
+
|
45
|
+
# Tell if authentication through request.params is enabled. True by default.
|
46
|
+
# It can be set to an array that will enable params authentication only for the
|
47
|
+
# given strategies, for example, `config.params_authenticatable = [:database]` will
|
48
|
+
# enable it only for database (email + password) authentication.
|
49
|
+
# config.params_authenticatable = true
|
50
|
+
|
51
|
+
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
52
|
+
# It can be set to an array that will enable http authentication only for the
|
53
|
+
# given strategies, for example, `config.http_authenticatable = [:token]` will
|
54
|
+
# enable it only for token authentication.
|
55
|
+
# config.http_authenticatable = false
|
56
|
+
|
57
|
+
# If http headers should be returned for AJAX requests. True by default.
|
58
|
+
# config.http_authenticatable_on_xhr = true
|
59
|
+
|
60
|
+
# The realm used in Http Basic Authentication. "Application" by default.
|
61
|
+
# config.http_authentication_realm = "Application"
|
62
|
+
|
63
|
+
# It will change confirmation, password recovery and other workflows
|
64
|
+
# to behave the same regardless if the e-mail provided was right or wrong.
|
65
|
+
# Does not affect registerable.
|
66
|
+
# config.paranoid = true
|
67
|
+
|
68
|
+
# By default Devise will store the user in session. You can skip storage for
|
69
|
+
# :http_auth and :token_auth by adding those symbols to the array below.
|
70
|
+
# Notice that if you are skipping storage for all authentication paths, you
|
71
|
+
# may want to disable generating routes to Devise's sessions controller by
|
72
|
+
# passing :skip => :sessions to `devise_for` in your config/routes.rb
|
73
|
+
config.skip_session_storage = [:http_auth]
|
74
|
+
|
75
|
+
# ==> Configuration for :database_authenticatable
|
76
|
+
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
77
|
+
# using other encryptors, it sets how many times you want the password re-encrypted.
|
78
|
+
#
|
79
|
+
# Limiting the stretches to just one in testing will increase the performance of
|
80
|
+
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
|
81
|
+
# a value less than 10 in other environments.
|
82
|
+
config.stretches = Rails.env.test? ? 1 : 10
|
83
|
+
|
84
|
+
# Setup a pepper to generate the encrypted password.
|
85
|
+
# config.pepper = <%= SecureRandom.hex(64).inspect %>
|
86
|
+
|
87
|
+
# ==> Configuration for :confirmable
|
88
|
+
# A period that the user is allowed to access the website even without
|
89
|
+
# confirming his account. For instance, if set to 2.days, the user will be
|
90
|
+
# able to access the website for two days without confirming his account,
|
91
|
+
# access will be blocked just in the third day. Default is 0.days, meaning
|
92
|
+
# the user cannot access the website without confirming his account.
|
93
|
+
# config.allow_unconfirmed_access_for = 2.days
|
94
|
+
|
95
|
+
# If true, requires any email changes to be confirmed (exactly the same way as
|
96
|
+
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
97
|
+
# db field (see migrations). Until confirmed new email is stored in
|
98
|
+
# unconfirmed email column, and copied to email column on successful confirmation.
|
99
|
+
config.reconfirmable = true
|
100
|
+
|
101
|
+
# Defines which key will be used when confirming an account
|
102
|
+
# config.confirmation_keys = [ :email ]
|
103
|
+
|
104
|
+
# ==> Configuration for :rememberable
|
105
|
+
# The time the user will be remembered without asking for credentials again.
|
106
|
+
# config.remember_for = 2.weeks
|
107
|
+
|
108
|
+
# If true, extends the user's remember period when remembered via cookie.
|
109
|
+
# config.extend_remember_period = false
|
110
|
+
|
111
|
+
# Options to be passed to the created cookie. For instance, you can set
|
112
|
+
# :secure => true in order to force SSL only cookies.
|
113
|
+
# config.rememberable_options = {}
|
114
|
+
|
115
|
+
# ==> Configuration for :validatable
|
116
|
+
# Range for password length. Default is 6..128.
|
117
|
+
# config.password_length = 6..128
|
118
|
+
|
119
|
+
# Email regex used to validate email formats. It simply asserts that
|
120
|
+
# an one (and only one) @ exists in the given string. This is mainly
|
121
|
+
# to give user feedback and not to assert the e-mail validity.
|
122
|
+
# config.email_regexp = /\A[^@]+@[^@]+\z/
|
123
|
+
|
124
|
+
# ==> Configuration for :timeoutable
|
125
|
+
# The time you want to timeout the user session without activity. After this
|
126
|
+
# time the user will be asked for credentials again. Default is 30 minutes.
|
127
|
+
# config.timeout_in = 30.minutes
|
128
|
+
|
129
|
+
# ==> Configuration for :lockable
|
130
|
+
# Defines which strategy will be used to lock an account.
|
131
|
+
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
|
132
|
+
# :none = No lock strategy. You should handle locking by yourself.
|
133
|
+
# config.lock_strategy = :failed_attempts
|
134
|
+
|
135
|
+
# Defines which key will be used when locking and unlocking an account
|
136
|
+
# config.unlock_keys = [ :email ]
|
137
|
+
|
138
|
+
# Defines which strategy will be used to unlock an account.
|
139
|
+
# :email = Sends an unlock link to the user email
|
140
|
+
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
141
|
+
# :both = Enables both strategies
|
142
|
+
# :none = No unlock strategy. You should handle unlocking by yourself.
|
143
|
+
# config.unlock_strategy = :both
|
144
|
+
|
145
|
+
# Number of authentication tries before locking an account if lock_strategy
|
146
|
+
# is failed attempts.
|
147
|
+
# config.maximum_attempts = 20
|
148
|
+
|
149
|
+
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
150
|
+
# config.unlock_in = 1.hour
|
151
|
+
|
152
|
+
# ==> Configuration for :recoverable
|
153
|
+
#
|
154
|
+
# Defines which key will be used when recovering the password for an account
|
155
|
+
# config.reset_password_keys = [ :email ]
|
156
|
+
|
157
|
+
# Time interval you can reset your password with a reset password key.
|
158
|
+
# Don't put a too small interval or your users won't have the time to
|
159
|
+
# change their passwords.
|
160
|
+
config.reset_password_within = 6.hours
|
161
|
+
|
162
|
+
# ==> Configuration for :encryptable
|
163
|
+
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
164
|
+
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
165
|
+
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
|
166
|
+
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
|
167
|
+
# REST_AUTH_SITE_KEY to pepper)
|
168
|
+
# config.encryptor = :sha512
|
169
|
+
|
170
|
+
# ==> Configuration for :token_authenticatable
|
171
|
+
# Defines name of the authentication token params key
|
172
|
+
# config.token_authentication_key = :auth_token
|
173
|
+
|
174
|
+
# ==> Scopes configuration
|
175
|
+
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
176
|
+
# "users/sessions/new". It's turned off by default because it's slower if you
|
177
|
+
# are using only default views.
|
178
|
+
# config.scoped_views = false
|
179
|
+
|
180
|
+
# Configure the default scope given to Warden. By default it's the first
|
181
|
+
# devise role declared in your routes (usually :user).
|
182
|
+
# config.default_scope = :user
|
183
|
+
|
184
|
+
# Configure sign_out behavior.
|
185
|
+
# Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
|
186
|
+
# The default is true, which means any logout action will sign out all active scopes.
|
187
|
+
# config.sign_out_all_scopes = true
|
188
|
+
|
189
|
+
# ==> Navigation configuration
|
190
|
+
# Lists the formats that should be treated as navigational. Formats like
|
191
|
+
# :html, should redirect to the sign in page when the user does not have
|
192
|
+
# access, but formats like :xml or :json, should return 401.
|
193
|
+
#
|
194
|
+
# If you have any extra navigational formats, like :iphone or :mobile, you
|
195
|
+
# should add them to the navigational formats lists.
|
196
|
+
#
|
197
|
+
# The "*/*" below is required to match Internet Explorer requests.
|
198
|
+
# config.navigational_formats = ["*/*", :html]
|
199
|
+
|
200
|
+
# The default HTTP method used to sign out a resource. Default is :delete.
|
201
|
+
config.sign_out_via = :delete
|
202
|
+
|
203
|
+
# ==> OmniAuth
|
204
|
+
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
205
|
+
# up on your models and hooks.
|
206
|
+
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
|
207
|
+
|
208
|
+
# ==> Warden configuration
|
209
|
+
# If you want to use other strategies, that are not supported by Devise, or
|
210
|
+
# change the failure app, you can configure them inside the config.warden block.
|
211
|
+
#
|
212
|
+
# config.warden do |manager|
|
213
|
+
# manager.intercept_401 = false
|
214
|
+
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
215
|
+
# end
|
216
|
+
end
|