af-devise 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +15 -0
  3. data/CHANGELOG.rdoc +885 -0
  4. data/CONTRIBUTING.md +14 -0
  5. data/Gemfile +29 -0
  6. data/Gemfile.lock +155 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +394 -0
  9. data/Rakefile +34 -0
  10. data/app/controllers/devise/confirmations_controller.rb +43 -0
  11. data/app/controllers/devise/omniauth_callbacks_controller.rb +30 -0
  12. data/app/controllers/devise/passwords_controller.rb +65 -0
  13. data/app/controllers/devise/registrations_controller.rb +119 -0
  14. data/app/controllers/devise/sessions_controller.rb +50 -0
  15. data/app/controllers/devise/unlocks_controller.rb +44 -0
  16. data/app/controllers/devise_controller.rb +184 -0
  17. data/app/helpers/devise_helper.rb +25 -0
  18. data/app/mailers/devise/mailer.rb +15 -0
  19. data/app/views/devise/_links.erb +3 -0
  20. data/app/views/devise/confirmations/new.html.erb +12 -0
  21. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  22. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  23. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  24. data/app/views/devise/passwords/edit.html.erb +16 -0
  25. data/app/views/devise/passwords/new.html.erb +12 -0
  26. data/app/views/devise/registrations/edit.html.erb +25 -0
  27. data/app/views/devise/registrations/new.html.erb +18 -0
  28. data/app/views/devise/sessions/new.html.erb +17 -0
  29. data/app/views/devise/shared/_links.erb +25 -0
  30. data/app/views/devise/unlocks/new.html.erb +12 -0
  31. data/config/locales/en.yml +59 -0
  32. data/devise.gemspec +25 -0
  33. data/gemfiles/Gemfile.rails-3.1.x +35 -0
  34. data/gemfiles/Gemfile.rails-3.1.x.lock +167 -0
  35. data/lib/devise.rb +444 -0
  36. data/lib/devise/controllers/helpers.rb +285 -0
  37. data/lib/devise/controllers/rememberable.rb +52 -0
  38. data/lib/devise/controllers/scoped_views.rb +17 -0
  39. data/lib/devise/controllers/url_helpers.rb +67 -0
  40. data/lib/devise/delegator.rb +16 -0
  41. data/lib/devise/failure_app.rb +187 -0
  42. data/lib/devise/hooks/activatable.rb +11 -0
  43. data/lib/devise/hooks/forgetable.rb +9 -0
  44. data/lib/devise/hooks/lockable.rb +7 -0
  45. data/lib/devise/hooks/rememberable.rb +6 -0
  46. data/lib/devise/hooks/timeoutable.rb +25 -0
  47. data/lib/devise/hooks/trackable.rb +9 -0
  48. data/lib/devise/mailers/helpers.rb +91 -0
  49. data/lib/devise/mapping.rb +172 -0
  50. data/lib/devise/models.rb +128 -0
  51. data/lib/devise/models/authenticatable.rb +268 -0
  52. data/lib/devise/models/confirmable.rb +270 -0
  53. data/lib/devise/models/database_authenticatable.rb +127 -0
  54. data/lib/devise/models/lockable.rb +193 -0
  55. data/lib/devise/models/omniauthable.rb +27 -0
  56. data/lib/devise/models/recoverable.rb +140 -0
  57. data/lib/devise/models/registerable.rb +25 -0
  58. data/lib/devise/models/rememberable.rb +125 -0
  59. data/lib/devise/models/timeoutable.rb +49 -0
  60. data/lib/devise/models/token_authenticatable.rb +89 -0
  61. data/lib/devise/models/trackable.rb +35 -0
  62. data/lib/devise/models/validatable.rb +66 -0
  63. data/lib/devise/modules.rb +29 -0
  64. data/lib/devise/omniauth.rb +28 -0
  65. data/lib/devise/omniauth/config.rb +45 -0
  66. data/lib/devise/omniauth/url_helpers.rb +18 -0
  67. data/lib/devise/orm/active_record.rb +3 -0
  68. data/lib/devise/orm/mongoid.rb +3 -0
  69. data/lib/devise/param_filter.rb +41 -0
  70. data/lib/devise/rails.rb +54 -0
  71. data/lib/devise/rails/routes.rb +446 -0
  72. data/lib/devise/rails/warden_compat.rb +43 -0
  73. data/lib/devise/strategies/authenticatable.rb +176 -0
  74. data/lib/devise/strategies/base.rb +20 -0
  75. data/lib/devise/strategies/database_authenticatable.rb +20 -0
  76. data/lib/devise/strategies/rememberable.rb +55 -0
  77. data/lib/devise/strategies/token_authenticatable.rb +56 -0
  78. data/lib/devise/test_helpers.rb +131 -0
  79. data/lib/devise/time_inflector.rb +14 -0
  80. data/lib/devise/version.rb +3 -0
  81. data/lib/generators/active_record/devise_generator.rb +79 -0
  82. data/lib/generators/active_record/templates/migration.rb +19 -0
  83. data/lib/generators/active_record/templates/migration_existing.rb +26 -0
  84. data/lib/generators/devise/devise_generator.rb +24 -0
  85. data/lib/generators/devise/install_generator.rb +24 -0
  86. data/lib/generators/devise/orm_helpers.rb +32 -0
  87. data/lib/generators/devise/views_generator.rb +116 -0
  88. data/lib/generators/mongoid/devise_generator.rb +57 -0
  89. data/lib/generators/templates/README +35 -0
  90. data/lib/generators/templates/devise.rb +240 -0
  91. data/lib/generators/templates/markerb/confirmation_instructions.markerb +5 -0
  92. data/lib/generators/templates/markerb/reset_password_instructions.markerb +8 -0
  93. data/lib/generators/templates/markerb/unlock_instructions.markerb +7 -0
  94. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +15 -0
  95. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +19 -0
  96. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +15 -0
  97. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +22 -0
  98. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +17 -0
  99. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +15 -0
  100. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +15 -0
  101. data/test/controllers/custom_strategy_test.rb +62 -0
  102. data/test/controllers/helpers_test.rb +253 -0
  103. data/test/controllers/internal_helpers_test.rb +110 -0
  104. data/test/controllers/sessions_controller_test.rb +85 -0
  105. data/test/controllers/url_helpers_test.rb +59 -0
  106. data/test/delegator_test.rb +19 -0
  107. data/test/devise_test.rb +72 -0
  108. data/test/failure_app_test.rb +221 -0
  109. data/test/generators/active_record_generator_test.rb +75 -0
  110. data/test/generators/devise_generator_test.rb +39 -0
  111. data/test/generators/install_generator_test.rb +13 -0
  112. data/test/generators/mongoid_generator_test.rb +23 -0
  113. data/test/generators/views_generator_test.rb +52 -0
  114. data/test/helpers/devise_helper_test.rb +51 -0
  115. data/test/integration/authenticatable_test.rb +633 -0
  116. data/test/integration/confirmable_test.rb +298 -0
  117. data/test/integration/database_authenticatable_test.rb +82 -0
  118. data/test/integration/http_authenticatable_test.rb +97 -0
  119. data/test/integration/lockable_test.rb +242 -0
  120. data/test/integration/omniauthable_test.rb +133 -0
  121. data/test/integration/recoverable_test.rb +334 -0
  122. data/test/integration/registerable_test.rb +345 -0
  123. data/test/integration/rememberable_test.rb +158 -0
  124. data/test/integration/timeoutable_test.rb +140 -0
  125. data/test/integration/token_authenticatable_test.rb +161 -0
  126. data/test/integration/trackable_test.rb +92 -0
  127. data/test/mailers/confirmation_instructions_test.rb +102 -0
  128. data/test/mailers/reset_password_instructions_test.rb +83 -0
  129. data/test/mailers/unlock_instructions_test.rb +77 -0
  130. data/test/mapping_test.rb +127 -0
  131. data/test/models/authenticatable_test.rb +7 -0
  132. data/test/models/confirmable_test.rb +391 -0
  133. data/test/models/database_authenticatable_test.rb +196 -0
  134. data/test/models/lockable_test.rb +273 -0
  135. data/test/models/omniauthable_test.rb +7 -0
  136. data/test/models/recoverable_test.rb +205 -0
  137. data/test/models/registerable_test.rb +7 -0
  138. data/test/models/rememberable_test.rb +174 -0
  139. data/test/models/serializable_test.rb +49 -0
  140. data/test/models/timeoutable_test.rb +46 -0
  141. data/test/models/token_authenticatable_test.rb +55 -0
  142. data/test/models/trackable_test.rb +13 -0
  143. data/test/models/validatable_test.rb +117 -0
  144. data/test/models_test.rb +179 -0
  145. data/test/omniauth/config_test.rb +57 -0
  146. data/test/omniauth/url_helpers_test.rb +51 -0
  147. data/test/orm/active_record.rb +9 -0
  148. data/test/orm/mongoid.rb +13 -0
  149. data/test/rails_app/Rakefile +10 -0
  150. data/test/rails_app/app/active_record/admin.rb +6 -0
  151. data/test/rails_app/app/active_record/shim.rb +2 -0
  152. data/test/rails_app/app/active_record/user.rb +6 -0
  153. data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
  154. data/test/rails_app/app/controllers/admins_controller.rb +11 -0
  155. data/test/rails_app/app/controllers/application_controller.rb +8 -0
  156. data/test/rails_app/app/controllers/home_controller.rb +25 -0
  157. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  158. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  159. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +14 -0
  160. data/test/rails_app/app/controllers/users_controller.rb +23 -0
  161. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  162. data/test/rails_app/app/mailers/users/mailer.rb +8 -0
  163. data/test/rails_app/app/mongoid/admin.rb +29 -0
  164. data/test/rails_app/app/mongoid/shim.rb +24 -0
  165. data/test/rails_app/app/mongoid/user.rb +42 -0
  166. data/test/rails_app/app/views/admins/index.html.erb +1 -0
  167. data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
  168. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -0
  169. data/test/rails_app/app/views/home/index.html.erb +1 -0
  170. data/test/rails_app/app/views/home/join.html.erb +1 -0
  171. data/test/rails_app/app/views/home/private.html.erb +1 -0
  172. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -0
  173. data/test/rails_app/app/views/layouts/application.html.erb +24 -0
  174. data/test/rails_app/app/views/users/index.html.erb +1 -0
  175. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
  176. data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
  177. data/test/rails_app/config.ru +4 -0
  178. data/test/rails_app/config/application.rb +41 -0
  179. data/test/rails_app/config/boot.rb +8 -0
  180. data/test/rails_app/config/database.yml +18 -0
  181. data/test/rails_app/config/environment.rb +5 -0
  182. data/test/rails_app/config/environments/development.rb +18 -0
  183. data/test/rails_app/config/environments/production.rb +33 -0
  184. data/test/rails_app/config/environments/test.rb +33 -0
  185. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  186. data/test/rails_app/config/initializers/devise.rb +178 -0
  187. data/test/rails_app/config/initializers/inflections.rb +2 -0
  188. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  189. data/test/rails_app/config/routes.rb +100 -0
  190. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +74 -0
  191. data/test/rails_app/db/schema.rb +52 -0
  192. data/test/rails_app/lib/shared_admin.rb +14 -0
  193. data/test/rails_app/lib/shared_user.rb +26 -0
  194. data/test/rails_app/public/404.html +26 -0
  195. data/test/rails_app/public/422.html +26 -0
  196. data/test/rails_app/public/500.html +26 -0
  197. data/test/rails_app/public/favicon.ico +0 -0
  198. data/test/rails_app/script/rails +10 -0
  199. data/test/routes_test.rb +248 -0
  200. data/test/support/assertions.rb +40 -0
  201. data/test/support/helpers.rb +91 -0
  202. data/test/support/integration.rb +92 -0
  203. data/test/support/locale/en.yml +4 -0
  204. data/test/support/webrat/integrations/rails.rb +24 -0
  205. data/test/test_helper.rb +27 -0
  206. data/test/test_helpers_test.rb +151 -0
  207. metadata +421 -0
@@ -0,0 +1,14 @@
1
+ require "active_support/core_ext/module/delegation"
2
+
3
+ module Devise
4
+ class TimeInflector
5
+ include ActionView::Helpers::DateHelper
6
+
7
+ class << self
8
+ attr_reader :instance
9
+ delegate :time_ago_in_words, :to => :instance
10
+ end
11
+
12
+ @instance = new
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Devise
2
+ VERSION = "2.1.2".freeze
3
+ end
@@ -0,0 +1,79 @@
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 = if namespaced?
31
+ class_name.to_s.split("::")
32
+ else
33
+ [class_name]
34
+ end
35
+
36
+ indent_depth = class_path.size - 1
37
+ content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
38
+
39
+ inject_into_class(model_path, class_path.last, content) if model_exists?
40
+ end
41
+
42
+ def migration_data
43
+ <<RUBY
44
+ ## Database authenticatable
45
+ t.string :email, :null => false, :default => ""
46
+ t.string :encrypted_password, :null => false, :default => ""
47
+
48
+ ## Recoverable
49
+ t.string :reset_password_token
50
+ t.datetime :reset_password_sent_at
51
+
52
+ ## Rememberable
53
+ t.datetime :remember_created_at
54
+
55
+ ## Trackable
56
+ t.integer :sign_in_count, :default => 0
57
+ t.datetime :current_sign_in_at
58
+ t.datetime :last_sign_in_at
59
+ t.string :current_sign_in_ip
60
+ t.string :last_sign_in_ip
61
+
62
+ ## Confirmable
63
+ # t.string :confirmation_token
64
+ # t.datetime :confirmed_at
65
+ # t.datetime :confirmation_sent_at
66
+ # t.string :unconfirmed_email # Only if using reconfirmable
67
+
68
+ ## Lockable
69
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
70
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
71
+ # t.datetime :locked_at
72
+
73
+ ## Token authenticatable
74
+ # t.string :authentication_token
75
+ RUBY
76
+ end
77
+ end
78
+ end
79
+ 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, :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,116 @@
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
+ # Le sigh, ensure Thor won't handle opts as args
14
+ # It should be fixed in future Rails releases
15
+ class_option :form_builder, :aliases => "-b"
16
+ class_option :markerb
17
+
18
+ public_task :copy_views
19
+ end
20
+
21
+ # TODO: Add this to Rails itslef
22
+ module ClassMethods
23
+ def hide!
24
+ Rails::Generators.hide_namespace self.namespace
25
+ end
26
+ end
27
+
28
+ def copy_views
29
+ view_directory :confirmations
30
+ view_directory :passwords
31
+ view_directory :registrations
32
+ view_directory :sessions
33
+ view_directory :unlocks
34
+ end
35
+
36
+ protected
37
+
38
+ def view_directory(name, _target_path = nil)
39
+ directory name.to_s, _target_path || "#{target_path}/#{name}"
40
+ end
41
+
42
+ def target_path
43
+ @target_path ||= "app/views/#{scope || :devise}"
44
+ end
45
+ end
46
+
47
+ class SharedViewsGenerator < Rails::Generators::Base #:nodoc:
48
+ include ViewPathTemplates
49
+ source_root File.expand_path("../../../../app/views/devise", __FILE__)
50
+ desc "Copies shared Devise views to your application."
51
+ hide!
52
+
53
+ # Override copy_views to just copy mailer and shared.
54
+ def copy_views
55
+ view_directory :shared
56
+ end
57
+ end
58
+
59
+ class FormForGenerator < Rails::Generators::Base #:nodoc:
60
+ include ViewPathTemplates
61
+ source_root File.expand_path("../../../../app/views/devise", __FILE__)
62
+ desc "Copies default Devise views to your application."
63
+ hide!
64
+ end
65
+
66
+ class SimpleFormForGenerator < Rails::Generators::Base #:nodoc:
67
+ include ViewPathTemplates
68
+ source_root File.expand_path("../../templates/simple_form_for", __FILE__)
69
+ desc "Copies simple form enabled views to your application."
70
+ hide!
71
+ end
72
+
73
+ class ErbGenerator < Rails::Generators::Base #:nodoc:
74
+ include ViewPathTemplates
75
+ source_root File.expand_path("../../../../app/views/devise", __FILE__)
76
+ desc "Copies Devise mail erb views to your application."
77
+ hide!
78
+
79
+ def copy_views
80
+ view_directory :mailer
81
+ end
82
+ end
83
+
84
+ class MarkerbGenerator < Rails::Generators::Base #:nodoc:
85
+ include ViewPathTemplates
86
+ source_root File.expand_path("../../templates", __FILE__)
87
+ desc "Copies Devise mail markerb views to your application."
88
+ hide!
89
+
90
+ def copy_views
91
+ view_directory :markerb, target_path
92
+ end
93
+
94
+ def target_path
95
+ "app/views/#{scope || :devise}/mailer"
96
+ end
97
+ end
98
+
99
+ class ViewsGenerator < Rails::Generators::Base
100
+ desc "Copies Devise views to your application."
101
+
102
+ argument :scope, :required => false, :default => nil,
103
+ :desc => "The scope to copy views to"
104
+
105
+ invoke SharedViewsGenerator
106
+
107
+ hook_for :form_builder, :aliases => "-b",
108
+ :desc => "Form builder to be used",
109
+ :default => defined?(SimpleForm) ? "simple_form_for" : "form_for"
110
+
111
+ hook_for :markerb, :desc => "Generate markerb instead of erb mail views",
112
+ :default => defined?(Markerb) ? :markerb : :erb,
113
+ :type => :boolean
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,57 @@
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, :default => ""
24
+ field :encrypted_password, :type => String, :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
+ ## Confirmable
41
+ # field :confirmation_token, :type => String
42
+ # field :confirmed_at, :type => Time
43
+ # field :confirmation_sent_at, :type => Time
44
+ # field :unconfirmed_email, :type => String # Only if using reconfirmable
45
+
46
+ ## Lockable
47
+ # field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts
48
+ # field :unlock_token, :type => String # Only if unlock strategy is :email or :both
49
+ # field :locked_at, :type => Time
50
+
51
+ ## Token authenticatable
52
+ # field :authentication_token, :type => String
53
+ RUBY
54
+ end
55
+ end
56
+ end
57
+ 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,240 @@
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
+ # A period that the user is allowed to confirm their account before their
96
+ # token becomes invalid. For example, if set to 3.days, the user can confirm
97
+ # their account within 3 days after the mail was sent, but on the fourth day
98
+ # their account can't be confirmed with the token any more.
99
+ # Default is nil, meaning there is no restriction on how long a user can take
100
+ # before confirming their account.
101
+ # config.confirm_within = 3.days
102
+
103
+ # If true, requires any email changes to be confirmed (exactly the same way as
104
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
105
+ # db field (see migrations). Until confirmed new email is stored in
106
+ # unconfirmed email column, and copied to email column on successful confirmation.
107
+ config.reconfirmable = true
108
+
109
+ # Defines which key will be used when confirming an account
110
+ # config.confirmation_keys = [ :email ]
111
+
112
+ # ==> Configuration for :rememberable
113
+ # The time the user will be remembered without asking for credentials again.
114
+ # config.remember_for = 2.weeks
115
+
116
+ # If true, extends the user's remember period when remembered via cookie.
117
+ # config.extend_remember_period = false
118
+
119
+ # Options to be passed to the created cookie. For instance, you can set
120
+ # :secure => true in order to force SSL only cookies.
121
+ # config.rememberable_options = {}
122
+
123
+ # ==> Configuration for :validatable
124
+ # Range for password length. Default is 8..128.
125
+ config.password_length = 8..128
126
+
127
+ # Email regex used to validate email formats. It simply asserts that
128
+ # an one (and only one) @ exists in the given string. This is mainly
129
+ # to give user feedback and not to assert the e-mail validity.
130
+ # config.email_regexp = /\A[^@]+@[^@]+\z/
131
+
132
+ # ==> Configuration for :timeoutable
133
+ # The time you want to timeout the user session without activity. After this
134
+ # time the user will be asked for credentials again. Default is 30 minutes.
135
+ # config.timeout_in = 30.minutes
136
+
137
+ # If true, expires auth token on session timeout.
138
+ # config.expire_auth_token_on_timeout = false
139
+
140
+ # ==> Configuration for :lockable
141
+ # Defines which strategy will be used to lock an account.
142
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
143
+ # :none = No lock strategy. You should handle locking by yourself.
144
+ # config.lock_strategy = :failed_attempts
145
+
146
+ # Defines which key will be used when locking and unlocking an account
147
+ # config.unlock_keys = [ :email ]
148
+
149
+ # Defines which strategy will be used to unlock an account.
150
+ # :email = Sends an unlock link to the user email
151
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
152
+ # :both = Enables both strategies
153
+ # :none = No unlock strategy. You should handle unlocking by yourself.
154
+ # config.unlock_strategy = :both
155
+
156
+ # Number of authentication tries before locking an account if lock_strategy
157
+ # is failed attempts.
158
+ # config.maximum_attempts = 20
159
+
160
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
161
+ # config.unlock_in = 1.hour
162
+
163
+ # ==> Configuration for :recoverable
164
+ #
165
+ # Defines which key will be used when recovering the password for an account
166
+ # config.reset_password_keys = [ :email ]
167
+
168
+ # Time interval you can reset your password with a reset password key.
169
+ # Don't put a too small interval or your users won't have the time to
170
+ # change their passwords.
171
+ config.reset_password_within = 6.hours
172
+
173
+ # ==> Configuration for :encryptable
174
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
175
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
176
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
177
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
178
+ # REST_AUTH_SITE_KEY to pepper)
179
+ # config.encryptor = :sha512
180
+
181
+ # ==> Configuration for :token_authenticatable
182
+ # Defines name of the authentication token params key
183
+ # config.token_authentication_key = :auth_token
184
+
185
+ # ==> Scopes configuration
186
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
187
+ # "users/sessions/new". It's turned off by default because it's slower if you
188
+ # are using only default views.
189
+ # config.scoped_views = false
190
+
191
+ # Configure the default scope given to Warden. By default it's the first
192
+ # devise role declared in your routes (usually :user).
193
+ # config.default_scope = :user
194
+
195
+ # Set this configuration to false if you want /users/sign_out to sign out
196
+ # only the current scope. By default, Devise signs out all scopes.
197
+ # config.sign_out_all_scopes = true
198
+
199
+ # ==> Navigation configuration
200
+ # Lists the formats that should be treated as navigational. Formats like
201
+ # :html, should redirect to the sign in page when the user does not have
202
+ # access, but formats like :xml or :json, should return 401.
203
+ #
204
+ # If you have any extra navigational formats, like :iphone or :mobile, you
205
+ # should add them to the navigational formats lists.
206
+ #
207
+ # The "*/*" below is required to match Internet Explorer requests.
208
+ # config.navigational_formats = ["*/*", :html]
209
+
210
+ # The default HTTP method used to sign out a resource. Default is :delete.
211
+ config.sign_out_via = :delete
212
+
213
+ # ==> OmniAuth
214
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
215
+ # up on your models and hooks.
216
+ # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
217
+
218
+ # ==> Warden configuration
219
+ # If you want to use other strategies, that are not supported by Devise, or
220
+ # change the failure app, you can configure them inside the config.warden block.
221
+ #
222
+ # config.warden do |manager|
223
+ # manager.intercept_401 = false
224
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
225
+ # end
226
+
227
+ # ==> Mountable engine configurations
228
+ # When using Devise inside an engine, let's call it `MyEngine`, and this engine
229
+ # is mountable, there are some extra configurations to be taken into account.
230
+ # The following options are available, assuming the engine is mounted as:
231
+ #
232
+ # mount MyEngine, at: "/my_engine"
233
+ #
234
+ # The router that invoked `devise_for`, in the example above, would be:
235
+ # config.router_name = :my_engine
236
+ #
237
+ # When using omniauth, Devise cannot automatically set Omniauth path,
238
+ # so you need to do it manually. For the users scope, it would be:
239
+ # config.omniauth_path_prefix = "/my_engine/users/auth"
240
+ end