loyal_devise 2.1.2
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 +881 -0
- data/CONTRIBUTING.md +12 -0
- data/Gemfile +31 -0
- data/Gemfile.lock +154 -0
- data/MIT-LICENSE +20 -0
- data/README.md +388 -0
- data/Rakefile +34 -0
- data/app/controllers/devise/confirmations_controller.rb +44 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +31 -0
- data/app/controllers/devise/passwords_controller.rb +57 -0
- data/app/controllers/devise/registrations_controller.rb +120 -0
- data/app/controllers/devise/sessions_controller.rb +51 -0
- data/app/controllers/devise/unlocks_controller.rb +45 -0
- data/app/controllers/devise_controller.rb +193 -0
- data/app/helpers/devise_helper.rb +26 -0
- data/app/mailers/devise/mailer.rb +16 -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 +59 -0
- data/devise.gemspec +26 -0
- data/gemfiles/Gemfile.rails-3.1.x +35 -0
- data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
- data/lib/devise/controllers/helpers.rb +273 -0
- data/lib/devise/controllers/rememberable.rb +53 -0
- data/lib/devise/controllers/scoped_views.rb +18 -0
- data/lib/devise/controllers/url_helpers.rb +68 -0
- data/lib/devise/delegator.rb +17 -0
- data/lib/devise/failure_app.rb +188 -0
- data/lib/devise/hooks/activatable.rb +12 -0
- data/lib/devise/hooks/forgetable.rb +10 -0
- data/lib/devise/hooks/lockable.rb +8 -0
- data/lib/devise/hooks/rememberable.rb +7 -0
- data/lib/devise/hooks/timeoutable.rb +26 -0
- data/lib/devise/hooks/trackable.rb +10 -0
- data/lib/devise/mailers/helpers.rb +92 -0
- data/lib/devise/mapping.rb +173 -0
- data/lib/devise/models/authenticatable.rb +269 -0
- data/lib/devise/models/confirmable.rb +271 -0
- data/lib/devise/models/database_authenticatable.rb +127 -0
- data/lib/devise/models/lockable.rb +194 -0
- data/lib/devise/models/omniauthable.rb +28 -0
- data/lib/devise/models/recoverable.rb +141 -0
- data/lib/devise/models/registerable.rb +26 -0
- data/lib/devise/models/rememberable.rb +126 -0
- data/lib/devise/models/timeoutable.rb +50 -0
- data/lib/devise/models/token_authenticatable.rb +90 -0
- data/lib/devise/models/trackable.rb +36 -0
- data/lib/devise/models/validatable.rb +67 -0
- data/lib/devise/models.rb +129 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/omniauth/config.rb +46 -0
- data/lib/devise/omniauth/url_helpers.rb +19 -0
- data/lib/devise/omniauth.rb +29 -0
- data/lib/devise/orm/active_record.rb +4 -0
- data/lib/devise/orm/mongoid.rb +4 -0
- data/lib/devise/param_filter.rb +42 -0
- data/lib/devise/rails/routes.rb +447 -0
- data/lib/devise/rails/warden_compat.rb +44 -0
- data/lib/devise/rails.rb +55 -0
- data/lib/devise/strategies/authenticatable.rb +177 -0
- data/lib/devise/strategies/base.rb +21 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +56 -0
- data/lib/devise/strategies/token_authenticatable.rb +57 -0
- data/lib/devise/test_helpers.rb +132 -0
- data/lib/devise/time_inflector.rb +15 -0
- data/lib/devise/version.rb +4 -0
- data/lib/devise.rb +445 -0
- data/lib/generators/active_record/devise_generator.rb +80 -0
- data/lib/generators/active_record/templates/migration.rb +20 -0
- data/lib/generators/active_record/templates/migration_existing.rb +27 -0
- data/lib/generators/devise/devise_generator.rb +25 -0
- data/lib/generators/devise/install_generator.rb +25 -0
- data/lib/generators/devise/orm_helpers.rb +33 -0
- data/lib/generators/devise/views_generator.rb +117 -0
- data/lib/generators/mongoid/devise_generator.rb +58 -0
- data/lib/generators/templates/README +35 -0
- data/lib/generators/templates/devise.rb +241 -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 +63 -0
- data/test/controllers/helpers_test.rb +254 -0
- data/test/controllers/internal_helpers_test.rb +111 -0
- data/test/controllers/sessions_controller_test.rb +58 -0
- data/test/controllers/url_helpers_test.rb +60 -0
- data/test/delegator_test.rb +20 -0
- data/test/devise_test.rb +73 -0
- data/test/failure_app_test.rb +222 -0
- data/test/generators/active_record_generator_test.rb +76 -0
- data/test/generators/devise_generator_test.rb +40 -0
- data/test/generators/install_generator_test.rb +14 -0
- data/test/generators/mongoid_generator_test.rb +24 -0
- data/test/generators/views_generator_test.rb +53 -0
- data/test/helpers/devise_helper_test.rb +52 -0
- data/test/indifferent_hash.rb +34 -0
- data/test/integration/authenticatable_test.rb +634 -0
- data/test/integration/confirmable_test.rb +299 -0
- data/test/integration/database_authenticatable_test.rb +83 -0
- data/test/integration/http_authenticatable_test.rb +98 -0
- data/test/integration/lockable_test.rb +243 -0
- data/test/integration/omniauthable_test.rb +134 -0
- data/test/integration/recoverable_test.rb +307 -0
- data/test/integration/registerable_test.rb +346 -0
- data/test/integration/rememberable_test.rb +159 -0
- data/test/integration/timeoutable_test.rb +141 -0
- data/test/integration/token_authenticatable_test.rb +162 -0
- data/test/integration/trackable_test.rb +93 -0
- data/test/mailers/confirmation_instructions_test.rb +103 -0
- data/test/mailers/reset_password_instructions_test.rb +84 -0
- data/test/mailers/unlock_instructions_test.rb +78 -0
- data/test/mapping_test.rb +128 -0
- data/test/models/authenticatable_test.rb +8 -0
- data/test/models/confirmable_test.rb +392 -0
- data/test/models/database_authenticatable_test.rb +190 -0
- data/test/models/lockable_test.rb +274 -0
- data/test/models/omniauthable_test.rb +8 -0
- data/test/models/recoverable_test.rb +206 -0
- data/test/models/registerable_test.rb +8 -0
- data/test/models/rememberable_test.rb +175 -0
- data/test/models/serializable_test.rb +49 -0
- data/test/models/timeoutable_test.rb +47 -0
- data/test/models/token_authenticatable_test.rb +56 -0
- data/test/models/trackable_test.rb +14 -0
- data/test/models/validatable_test.rb +117 -0
- data/test/models_test.rb +180 -0
- data/test/omniauth/config_test.rb +58 -0
- data/test/omniauth/url_helpers_test.rb +52 -0
- data/test/orm/active_record.rb +10 -0
- data/test/orm/mongoid.rb +15 -0
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/app/active_record/shim.rb +3 -0
- data/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +12 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/home_controller.rb +26 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +3 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +3 -0
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +15 -0
- data/test/rails_app/app/controllers/users_controller.rb +24 -0
- data/test/rails_app/app/helpers/application_helper.rb +4 -0
- data/test/rails_app/app/mailers/users/mailer.rb +9 -0
- data/test/rails_app/app/mongoid/admin.rb +28 -0
- data/test/rails_app/app/mongoid/shim.rb +25 -0
- data/test/rails_app/app/mongoid/user.rb +43 -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/application.rb +42 -0
- data/test/rails_app/config/boot.rb +9 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +6 -0
- data/test/rails_app/config/environments/development.rb +19 -0
- data/test/rails_app/config/environments/production.rb +34 -0
- data/test/rails_app/config/environments/test.rb +34 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +8 -0
- data/test/rails_app/config/initializers/devise.rb +179 -0
- data/test/rails_app/config/initializers/inflections.rb +3 -0
- data/test/rails_app/config/initializers/secret_token.rb +3 -0
- data/test/rails_app/config/routes.rb +101 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +75 -0
- data/test/rails_app/db/schema.rb +53 -0
- data/test/rails_app/lib/shared_admin.rb +15 -0
- data/test/rails_app/lib/shared_user.rb +27 -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 +249 -0
- data/test/support/assertions.rb +41 -0
- data/test/support/helpers.rb +92 -0
- data/test/support/integration.rb +93 -0
- data/test/support/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +25 -0
- data/test/test_helper.rb +28 -0
- data/test/test_helpers_test.rb +152 -0
- metadata +407 -0
@@ -0,0 +1,117 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Devise
|
3
|
+
module Generators
|
4
|
+
# Include this module in your generator to generate Devise views.
|
5
|
+
# `copy_views` is the main method and by default copies all views
|
6
|
+
# with forms.
|
7
|
+
module ViewPathTemplates #:nodoc:
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
argument :scope, :required => false, :default => nil,
|
12
|
+
:desc => "The scope to copy views to"
|
13
|
+
|
14
|
+
# Le sigh, ensure Thor won't handle opts as args
|
15
|
+
# It should be fixed in future Rails releases
|
16
|
+
class_option :form_builder, :aliases => "-b"
|
17
|
+
class_option :markerb
|
18
|
+
|
19
|
+
public_task :copy_views
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO: Add this to Rails itslef
|
23
|
+
module ClassMethods
|
24
|
+
def hide!
|
25
|
+
Rails::Generators.hide_namespace self.namespace
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def copy_views
|
30
|
+
view_directory :confirmations
|
31
|
+
view_directory :passwords
|
32
|
+
view_directory :registrations
|
33
|
+
view_directory :sessions
|
34
|
+
view_directory :unlocks
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def view_directory(name, _target_path = nil)
|
40
|
+
directory name.to_s, _target_path || "#{target_path}/#{name}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def target_path
|
44
|
+
@target_path ||= "app/views/#{scope || :devise}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class SharedViewsGenerator < Rails::Generators::Base #:nodoc:
|
49
|
+
include ViewPathTemplates
|
50
|
+
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
51
|
+
desc "Copies shared Devise views to your application."
|
52
|
+
hide!
|
53
|
+
|
54
|
+
# Override copy_views to just copy mailer and shared.
|
55
|
+
def copy_views
|
56
|
+
view_directory :shared
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class FormForGenerator < Rails::Generators::Base #:nodoc:
|
61
|
+
include ViewPathTemplates
|
62
|
+
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
63
|
+
desc "Copies default Devise views to your application."
|
64
|
+
hide!
|
65
|
+
end
|
66
|
+
|
67
|
+
class SimpleFormForGenerator < Rails::Generators::Base #:nodoc:
|
68
|
+
include ViewPathTemplates
|
69
|
+
source_root File.expand_path("../../templates/simple_form_for", __FILE__)
|
70
|
+
desc "Copies simple form enabled views to your application."
|
71
|
+
hide!
|
72
|
+
end
|
73
|
+
|
74
|
+
class ErbGenerator < Rails::Generators::Base #:nodoc:
|
75
|
+
include ViewPathTemplates
|
76
|
+
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
77
|
+
desc "Copies Devise mail erb views to your application."
|
78
|
+
hide!
|
79
|
+
|
80
|
+
def copy_views
|
81
|
+
view_directory :mailer
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class MarkerbGenerator < Rails::Generators::Base #:nodoc:
|
86
|
+
include ViewPathTemplates
|
87
|
+
source_root File.expand_path("../../templates", __FILE__)
|
88
|
+
desc "Copies Devise mail markerb views to your application."
|
89
|
+
hide!
|
90
|
+
|
91
|
+
def copy_views
|
92
|
+
view_directory :markerb, target_path
|
93
|
+
end
|
94
|
+
|
95
|
+
def target_path
|
96
|
+
"app/views/#{scope || :devise}/mailer"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class ViewsGenerator < Rails::Generators::Base
|
101
|
+
desc "Copies Devise views to your application."
|
102
|
+
|
103
|
+
argument :scope, :required => false, :default => nil,
|
104
|
+
:desc => "The scope to copy views to"
|
105
|
+
|
106
|
+
invoke SharedViewsGenerator
|
107
|
+
|
108
|
+
hook_for :form_builder, :aliases => "-b",
|
109
|
+
:desc => "Form builder to be used",
|
110
|
+
:default => defined?(SimpleForm) ? "simple_form_for" : "form_for"
|
111
|
+
|
112
|
+
hook_for :markerb, :desc => "Generate markerb instead of erb mail views",
|
113
|
+
:default => defined?(Markerb) ? :markerb : :erb,
|
114
|
+
:type => :boolean
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'generators/devise/orm_helpers'
|
3
|
+
|
4
|
+
module Mongoid
|
5
|
+
module Generators
|
6
|
+
class DeviseGenerator < Rails::Generators::NamedBase
|
7
|
+
include Devise::Generators::OrmHelpers
|
8
|
+
|
9
|
+
def generate_model
|
10
|
+
invoke "mongoid:model", [name] unless model_exists? && behavior == :invoke
|
11
|
+
end
|
12
|
+
|
13
|
+
def inject_field_types
|
14
|
+
inject_into_file model_path, migration_data, :after => "include Mongoid::Document\n" if model_exists?
|
15
|
+
end
|
16
|
+
|
17
|
+
def inject_devise_content
|
18
|
+
inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n" if model_exists?
|
19
|
+
end
|
20
|
+
|
21
|
+
def migration_data
|
22
|
+
<<RUBY
|
23
|
+
## Database authenticatable
|
24
|
+
field :email, :type => String, :default => ""
|
25
|
+
field :encrypted_password, :type => String, :default => ""
|
26
|
+
|
27
|
+
## Recoverable
|
28
|
+
field :reset_password_token, :type => String
|
29
|
+
field :reset_password_sent_at, :type => Time
|
30
|
+
|
31
|
+
## Rememberable
|
32
|
+
field :remember_created_at, :type => Time
|
33
|
+
|
34
|
+
## Trackable
|
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
|
40
|
+
|
41
|
+
## Confirmable
|
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
|
46
|
+
|
47
|
+
## Lockable
|
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
|
51
|
+
|
52
|
+
## Token authenticatable
|
53
|
+
# field :authentication_token, :type => String
|
54
|
+
RUBY
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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
|
+
5. You can copy Devise views (for customization) to your app by running:
|
32
|
+
|
33
|
+
rails g devise:views
|
34
|
+
|
35
|
+
===============================================================================
|
@@ -0,0 +1,241 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# Use this hook to configure devise mailer, warden hooks and so forth.
|
3
|
+
# Many of these configuration options can be set straight in your model.
|
4
|
+
Devise.setup do |config|
|
5
|
+
# ==> Mailer Configuration
|
6
|
+
# Configure the e-mail address which will be shown in Devise::Mailer,
|
7
|
+
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
|
8
|
+
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
|
9
|
+
|
10
|
+
# Configure the class responsible to send e-mails.
|
11
|
+
# config.mailer = "Devise::Mailer"
|
12
|
+
|
13
|
+
# ==> ORM configuration
|
14
|
+
# Load and configure the ORM. Supports :active_record (default) and
|
15
|
+
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
16
|
+
# available as additional gems.
|
17
|
+
require 'devise/orm/<%= options[:orm] %>'
|
18
|
+
|
19
|
+
# ==> Configuration for any authentication mechanism
|
20
|
+
# Configure which keys are used when authenticating a user. The default is
|
21
|
+
# just :email. You can configure it to use [:username, :subdomain], so for
|
22
|
+
# authenticating a user, both parameters are required. Remember that those
|
23
|
+
# parameters are used only when authenticating and not when retrieving from
|
24
|
+
# session. If you need permissions, you should implement that in a before filter.
|
25
|
+
# You can also supply a hash where the value is a boolean determining whether
|
26
|
+
# or not authentication should be aborted when the value is not present.
|
27
|
+
# config.authentication_keys = [ :email ]
|
28
|
+
|
29
|
+
# Configure parameters from the request object used for authentication. Each entry
|
30
|
+
# given should be a request method and it will automatically be passed to the
|
31
|
+
# find_for_authentication method and considered in your model lookup. For instance,
|
32
|
+
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
|
33
|
+
# The same considerations mentioned for authentication_keys also apply to request_keys.
|
34
|
+
# config.request_keys = []
|
35
|
+
|
36
|
+
# Configure which authentication keys should be case-insensitive.
|
37
|
+
# These keys will be downcased upon creating or modifying a user and when used
|
38
|
+
# to authenticate or find a user. Default is :email.
|
39
|
+
config.case_insensitive_keys = [ :email ]
|
40
|
+
|
41
|
+
# Configure which authentication keys should have whitespace stripped.
|
42
|
+
# These keys will have whitespace before and after removed upon creating or
|
43
|
+
# modifying a user and when used to authenticate or find a user. Default is :email.
|
44
|
+
config.strip_whitespace_keys = [ :email ]
|
45
|
+
|
46
|
+
# Tell if authentication through request.params is enabled. True by default.
|
47
|
+
# It can be set to an array that will enable params authentication only for the
|
48
|
+
# given strategies, for example, `config.params_authenticatable = [:database]` will
|
49
|
+
# enable it only for database (email + password) authentication.
|
50
|
+
# config.params_authenticatable = true
|
51
|
+
|
52
|
+
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
53
|
+
# It can be set to an array that will enable http authentication only for the
|
54
|
+
# given strategies, for example, `config.http_authenticatable = [:token]` will
|
55
|
+
# enable it only for token authentication.
|
56
|
+
# config.http_authenticatable = false
|
57
|
+
|
58
|
+
# If http headers should be returned for AJAX requests. True by default.
|
59
|
+
# config.http_authenticatable_on_xhr = true
|
60
|
+
|
61
|
+
# The realm used in Http Basic Authentication. "Application" by default.
|
62
|
+
# config.http_authentication_realm = "Application"
|
63
|
+
|
64
|
+
# It will change confirmation, password recovery and other workflows
|
65
|
+
# to behave the same regardless if the e-mail provided was right or wrong.
|
66
|
+
# Does not affect registerable.
|
67
|
+
# config.paranoid = true
|
68
|
+
|
69
|
+
# By default Devise will store the user in session. You can skip storage for
|
70
|
+
# :http_auth and :token_auth by adding those symbols to the array below.
|
71
|
+
# Notice that if you are skipping storage for all authentication paths, you
|
72
|
+
# may want to disable generating routes to Devise's sessions controller by
|
73
|
+
# passing :skip => :sessions to `devise_for` in your config/routes.rb
|
74
|
+
config.skip_session_storage = [:http_auth]
|
75
|
+
|
76
|
+
# ==> Configuration for :database_authenticatable
|
77
|
+
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
78
|
+
# using other encryptors, it sets how many times you want the password re-encrypted.
|
79
|
+
#
|
80
|
+
# Limiting the stretches to just one in testing will increase the performance of
|
81
|
+
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
|
82
|
+
# a value less than 10 in other environments.
|
83
|
+
config.stretches = Rails.env.test? ? 1 : 10
|
84
|
+
|
85
|
+
# Setup a pepper to generate the encrypted password.
|
86
|
+
# config.pepper = <%= SecureRandom.hex(64).inspect %>
|
87
|
+
|
88
|
+
# ==> Configuration for :confirmable
|
89
|
+
# A period that the user is allowed to access the website even without
|
90
|
+
# confirming his account. For instance, if set to 2.days, the user will be
|
91
|
+
# able to access the website for two days without confirming his account,
|
92
|
+
# access will be blocked just in the third day. Default is 0.days, meaning
|
93
|
+
# the user cannot access the website without confirming his account.
|
94
|
+
# config.allow_unconfirmed_access_for = 2.days
|
95
|
+
|
96
|
+
# A period that the user is allowed to confirm their account before their
|
97
|
+
# token becomes invalid. For example, if set to 3.days, the user can confirm
|
98
|
+
# their account within 3 days after the mail was sent, but on the fourth day
|
99
|
+
# their account can't be confirmed with the token any more.
|
100
|
+
# Default is nil, meaning there is no restriction on how long a user can take
|
101
|
+
# before confirming their account.
|
102
|
+
# config.confirm_within = 3.days
|
103
|
+
|
104
|
+
# If true, requires any email changes to be confirmed (exactly the same way as
|
105
|
+
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
106
|
+
# db field (see migrations). Until confirmed new email is stored in
|
107
|
+
# unconfirmed email column, and copied to email column on successful confirmation.
|
108
|
+
config.reconfirmable = true
|
109
|
+
|
110
|
+
# Defines which key will be used when confirming an account
|
111
|
+
# config.confirmation_keys = [ :email ]
|
112
|
+
|
113
|
+
# ==> Configuration for :rememberable
|
114
|
+
# The time the user will be remembered without asking for credentials again.
|
115
|
+
# config.remember_for = 2.weeks
|
116
|
+
|
117
|
+
# If true, extends the user's remember period when remembered via cookie.
|
118
|
+
# config.extend_remember_period = false
|
119
|
+
|
120
|
+
# Options to be passed to the created cookie. For instance, you can set
|
121
|
+
# :secure => true in order to force SSL only cookies.
|
122
|
+
# config.rememberable_options = {}
|
123
|
+
|
124
|
+
# ==> Configuration for :validatable
|
125
|
+
# Range for password length. Default is 8..128.
|
126
|
+
config.password_length = 8..128
|
127
|
+
|
128
|
+
# Email regex used to validate email formats. It simply asserts that
|
129
|
+
# an one (and only one) @ exists in the given string. This is mainly
|
130
|
+
# to give user feedback and not to assert the e-mail validity.
|
131
|
+
# config.email_regexp = /\A[^@]+@[^@]+\z/
|
132
|
+
|
133
|
+
# ==> Configuration for :timeoutable
|
134
|
+
# The time you want to timeout the user session without activity. After this
|
135
|
+
# time the user will be asked for credentials again. Default is 30 minutes.
|
136
|
+
# config.timeout_in = 30.minutes
|
137
|
+
|
138
|
+
# If true, expires auth token on session timeout.
|
139
|
+
# config.expire_auth_token_on_timeout = false
|
140
|
+
|
141
|
+
# ==> Configuration for :lockable
|
142
|
+
# Defines which strategy will be used to lock an account.
|
143
|
+
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
|
144
|
+
# :none = No lock strategy. You should handle locking by yourself.
|
145
|
+
# config.lock_strategy = :failed_attempts
|
146
|
+
|
147
|
+
# Defines which key will be used when locking and unlocking an account
|
148
|
+
# config.unlock_keys = [ :email ]
|
149
|
+
|
150
|
+
# Defines which strategy will be used to unlock an account.
|
151
|
+
# :email = Sends an unlock link to the user email
|
152
|
+
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
153
|
+
# :both = Enables both strategies
|
154
|
+
# :none = No unlock strategy. You should handle unlocking by yourself.
|
155
|
+
# config.unlock_strategy = :both
|
156
|
+
|
157
|
+
# Number of authentication tries before locking an account if lock_strategy
|
158
|
+
# is failed attempts.
|
159
|
+
# config.maximum_attempts = 20
|
160
|
+
|
161
|
+
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
162
|
+
# config.unlock_in = 1.hour
|
163
|
+
|
164
|
+
# ==> Configuration for :recoverable
|
165
|
+
#
|
166
|
+
# Defines which key will be used when recovering the password for an account
|
167
|
+
# config.reset_password_keys = [ :email ]
|
168
|
+
|
169
|
+
# Time interval you can reset your password with a reset password key.
|
170
|
+
# Don't put a too small interval or your users won't have the time to
|
171
|
+
# change their passwords.
|
172
|
+
config.reset_password_within = 6.hours
|
173
|
+
|
174
|
+
# ==> Configuration for :encryptable
|
175
|
+
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
176
|
+
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
177
|
+
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
|
178
|
+
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
|
179
|
+
# REST_AUTH_SITE_KEY to pepper)
|
180
|
+
# config.encryptor = :sha512
|
181
|
+
|
182
|
+
# ==> Configuration for :token_authenticatable
|
183
|
+
# Defines name of the authentication token params key
|
184
|
+
# config.token_authentication_key = :auth_token
|
185
|
+
|
186
|
+
# ==> Scopes configuration
|
187
|
+
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
188
|
+
# "users/sessions/new". It's turned off by default because it's slower if you
|
189
|
+
# are using only default views.
|
190
|
+
# config.scoped_views = false
|
191
|
+
|
192
|
+
# Configure the default scope given to Warden. By default it's the first
|
193
|
+
# devise role declared in your routes (usually :user).
|
194
|
+
# config.default_scope = :user
|
195
|
+
|
196
|
+
# Set this configuration to false if you want /users/sign_out to sign out
|
197
|
+
# only the current scope. By default, Devise signs out all scopes.
|
198
|
+
# config.sign_out_all_scopes = true
|
199
|
+
|
200
|
+
# ==> Navigation configuration
|
201
|
+
# Lists the formats that should be treated as navigational. Formats like
|
202
|
+
# :html, should redirect to the sign in page when the user does not have
|
203
|
+
# access, but formats like :xml or :json, should return 401.
|
204
|
+
#
|
205
|
+
# If you have any extra navigational formats, like :iphone or :mobile, you
|
206
|
+
# should add them to the navigational formats lists.
|
207
|
+
#
|
208
|
+
# The "*/*" below is required to match Internet Explorer requests.
|
209
|
+
# config.navigational_formats = ["*/*", :html]
|
210
|
+
|
211
|
+
# The default HTTP method used to sign out a resource. Default is :delete.
|
212
|
+
config.sign_out_via = :delete
|
213
|
+
|
214
|
+
# ==> OmniAuth
|
215
|
+
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
216
|
+
# up on your models and hooks.
|
217
|
+
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
|
218
|
+
|
219
|
+
# ==> Warden configuration
|
220
|
+
# If you want to use other strategies, that are not supported by Devise, or
|
221
|
+
# change the failure app, you can configure them inside the config.warden block.
|
222
|
+
#
|
223
|
+
# config.warden do |manager|
|
224
|
+
# manager.intercept_401 = false
|
225
|
+
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
226
|
+
# end
|
227
|
+
|
228
|
+
# ==> Mountable engine configurations
|
229
|
+
# When using Devise inside an engine, let's call it `MyEngine`, and this engine
|
230
|
+
# is mountable, there are some extra configurations to be taken into account.
|
231
|
+
# The following options are available, assuming the engine is mounted as:
|
232
|
+
#
|
233
|
+
# mount MyEngine, at: "/my_engine"
|
234
|
+
#
|
235
|
+
# The router that invoked `devise_for`, in the example above, would be:
|
236
|
+
# config.router_name = :my_engine
|
237
|
+
#
|
238
|
+
# When using omniauth, Devise cannot automatically set Omniauth path,
|
239
|
+
# so you need to do it manually. For the users scope, it would be:
|
240
|
+
# config.omniauth_path_prefix = "/my_engine/users/auth"
|
241
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Hello <%= @resource.email %>!
|
2
|
+
|
3
|
+
Someone has requested a link to change your password, and you can do this through the link below.
|
4
|
+
|
5
|
+
<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>
|
6
|
+
|
7
|
+
If you didn't request this, please ignore this email.
|
8
|
+
Your password won't change until you access the link above and create a new one.
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Hello <%= @resource.email %>!
|
2
|
+
|
3
|
+
Your account has been locked due to an excessive number of unsuccessful sign in attempts.
|
4
|
+
|
5
|
+
Click the link below to unlock your account:
|
6
|
+
|
7
|
+
<%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<h2>Resend confirmation instructions</h2>
|
2
|
+
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
|
4
|
+
<%= f.error_notification %>
|
5
|
+
|
6
|
+
<div class="form-inputs">
|
7
|
+
<%= f.input :email, :required => true, :autofocus => true %>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div class="form-actions">
|
11
|
+
<%= f.button :submit, "Resend confirmation instructions" %>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<%= render "devise/shared/links" %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<h2>Change your password</h2>
|
2
|
+
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
|
4
|
+
<%= f.error_notification %>
|
5
|
+
|
6
|
+
<%= f.input :reset_password_token, :as => :hidden %>
|
7
|
+
<%= f.full_error :reset_password_token %>
|
8
|
+
|
9
|
+
<div class="form-inputs">
|
10
|
+
<%= f.input :password, :label => "New password", :required => true, :autofocus => true %>
|
11
|
+
<%= f.input :password_confirmation, :label => "Confirm your new password", :required => true %>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class="form-actions">
|
15
|
+
<%= f.button :submit, "Change my password" %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<%= render "devise/shared/links" %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<h2>Forgot your password?</h2>
|
2
|
+
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
|
4
|
+
<%= f.error_notification %>
|
5
|
+
|
6
|
+
<div class="form-inputs">
|
7
|
+
<%= f.input :email, :required => true, :autofocus => true %>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div class="form-actions">
|
11
|
+
<%= f.button :submit, "Send me reset password instructions" %>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<%= render "devise/shared/links" %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<h2>Edit <%= resource_name.to_s.humanize %></h2>
|
2
|
+
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
|
4
|
+
<%= f.error_notification %>
|
5
|
+
|
6
|
+
<div class="form-inputs">
|
7
|
+
<%= f.input :email, :required => true, :autofocus => true %>
|
8
|
+
<%= f.input :password, :autocomplete => "off", :hint => "leave it blank if you don't want to change it", :required => false %>
|
9
|
+
<%= f.input :password_confirmation, :required => false %>
|
10
|
+
<%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true %>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<div class="form-actions">
|
14
|
+
<%= f.button :submit, "Update" %>
|
15
|
+
</div>
|
16
|
+
<% end %>
|
17
|
+
|
18
|
+
<h3>Cancel my account</h3>
|
19
|
+
|
20
|
+
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %>.</p>
|
21
|
+
|
22
|
+
<%= link_to "Back", :back %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<h2>Sign up</h2>
|
2
|
+
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
|
4
|
+
<%= f.error_notification %>
|
5
|
+
|
6
|
+
<div class="form-inputs">
|
7
|
+
<%= f.input :email, :required => true, :autofocus => true %>
|
8
|
+
<%= f.input :password, :required => true %>
|
9
|
+
<%= f.input :password_confirmation, :required => true %>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<div class="form-actions">
|
13
|
+
<%= f.button :submit, "Sign up" %>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<%= render "devise/shared/links" %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<h2>Sign in</h2>
|
2
|
+
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
|
4
|
+
<div class="form-inputs">
|
5
|
+
<%= f.input :email, :required => false, :autofocus => true %>
|
6
|
+
<%= f.input :password, :required => false %>
|
7
|
+
<%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div class="form-actions">
|
11
|
+
<%= f.button :submit, "Sign in" %>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<%= render "devise/shared/links" %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<h2>Resend unlock instructions</h2>
|
2
|
+
|
3
|
+
<%= simple_form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
|
4
|
+
<%= f.error_notification %>
|
5
|
+
|
6
|
+
<div class="form-inputs">
|
7
|
+
<%= f.input :email, :required => true, :autofocus => true %>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div class="form-actions">
|
11
|
+
<%= f.button :submit, "Resend unlock instructions" %>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
<%= render "devise/shared/links" %>
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'test_helper'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'warden/strategies/base'
|
5
|
+
require 'devise/test_helpers'
|
6
|
+
|
7
|
+
class CustomStrategyController < ActionController::Base
|
8
|
+
def new
|
9
|
+
warden.authenticate!(:custom_strategy)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# These tests are to prove that a warden strategy can successfully
|
14
|
+
# return a custom response, including a specific status code and
|
15
|
+
# custom http response headers. This does work in production,
|
16
|
+
# however, at the time of writing this, the Devise test helpers do
|
17
|
+
# not recognise the custom response and proceed to calling the
|
18
|
+
# Failure App. This makes it impossible to write tests for a
|
19
|
+
# strategy that return a custom response with Devise.
|
20
|
+
class CustomStrategy < Warden::Strategies::Base
|
21
|
+
def authenticate!
|
22
|
+
custom_headers = { "X-FOO" => "BAR" }
|
23
|
+
response = Rack::Response.new("BAD REQUEST", 400, custom_headers)
|
24
|
+
custom! response.finish
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class CustomStrategyTest < ActionController::TestCase
|
29
|
+
tests CustomStrategyController
|
30
|
+
|
31
|
+
include Devise::TestHelpers
|
32
|
+
|
33
|
+
setup do
|
34
|
+
Warden::Strategies.add(:custom_strategy, CustomStrategy)
|
35
|
+
end
|
36
|
+
|
37
|
+
teardown do
|
38
|
+
Warden::Strategies._strategies.delete(:custom_strategy)
|
39
|
+
end
|
40
|
+
|
41
|
+
test "custom strategy can return its own status code" do
|
42
|
+
ret = get :new
|
43
|
+
|
44
|
+
# check the returned rack array
|
45
|
+
assert ret.is_a?(Array)
|
46
|
+
assert_equal 400, ret.first
|
47
|
+
|
48
|
+
# check the saved response as well. This is purely so that the response is available to the testing framework
|
49
|
+
# for verification. In production, the above array would be delivered directly to Rack.
|
50
|
+
assert_response 400
|
51
|
+
end
|
52
|
+
|
53
|
+
test "custom strategy can return custom headers" do
|
54
|
+
ret = get :new
|
55
|
+
|
56
|
+
# check the returned rack array
|
57
|
+
assert ret.is_a?(Array)
|
58
|
+
assert_equal ret.third['X-FOO'], 'BAR'
|
59
|
+
|
60
|
+
# check the saved response headers as well.
|
61
|
+
assert_equal response.headers['X-FOO'], 'BAR'
|
62
|
+
end
|
63
|
+
end
|