dcu-devise 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. data/CHANGELOG.rdoc +378 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +260 -0
  4. data/Rakefile +53 -0
  5. data/TODO +2 -0
  6. data/app/controllers/confirmations_controller.rb +33 -0
  7. data/app/controllers/passwords_controller.rb +41 -0
  8. data/app/controllers/registrations_controller.rb +53 -0
  9. data/app/controllers/sessions_controller.rb +44 -0
  10. data/app/controllers/unlocks_controller.rb +41 -0
  11. data/app/models/devise_mailer.rb +68 -0
  12. data/app/views/confirmations/new.html.erb +12 -0
  13. data/app/views/devise_mailer/confirmation_instructions.html.erb +5 -0
  14. data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
  15. data/app/views/devise_mailer/unlock_instructions.html.erb +7 -0
  16. data/app/views/passwords/edit.html.erb +16 -0
  17. data/app/views/passwords/new.html.erb +12 -0
  18. data/app/views/registrations/edit.html.erb +25 -0
  19. data/app/views/registrations/new.html.erb +17 -0
  20. data/app/views/sessions/new.html.erb +17 -0
  21. data/app/views/shared/_devise_links.erb +19 -0
  22. data/app/views/unlocks/new.html.erb +12 -0
  23. data/generators/devise/USAGE +5 -0
  24. data/generators/devise/devise_generator.rb +15 -0
  25. data/generators/devise/lib/route_devise.rb +32 -0
  26. data/generators/devise/templates/migration.rb +23 -0
  27. data/generators/devise/templates/model.rb +9 -0
  28. data/generators/devise_install/USAGE +3 -0
  29. data/generators/devise_install/devise_install_generator.rb +15 -0
  30. data/generators/devise_install/templates/README +23 -0
  31. data/generators/devise_install/templates/devise.rb +105 -0
  32. data/generators/devise_views/USAGE +3 -0
  33. data/generators/devise_views/devise_views_generator.rb +21 -0
  34. data/lib/devise.rb +264 -0
  35. data/lib/devise/controllers/helpers.rb +200 -0
  36. data/lib/devise/controllers/internal_helpers.rb +129 -0
  37. data/lib/devise/controllers/url_helpers.rb +41 -0
  38. data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
  39. data/lib/devise/encryptors/base.rb +20 -0
  40. data/lib/devise/encryptors/bcrypt.rb +21 -0
  41. data/lib/devise/encryptors/clearance_sha1.rb +19 -0
  42. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  43. data/lib/devise/encryptors/sha1.rb +27 -0
  44. data/lib/devise/encryptors/sha512.rb +27 -0
  45. data/lib/devise/failure_app.rb +65 -0
  46. data/lib/devise/hooks/activatable.rb +15 -0
  47. data/lib/devise/hooks/rememberable.rb +32 -0
  48. data/lib/devise/hooks/timeoutable.rb +18 -0
  49. data/lib/devise/hooks/trackable.rb +18 -0
  50. data/lib/devise/locales/en.yml +35 -0
  51. data/lib/devise/mapping.rb +128 -0
  52. data/lib/devise/models.rb +117 -0
  53. data/lib/devise/models/activatable.rb +16 -0
  54. data/lib/devise/models/confirmable.rb +162 -0
  55. data/lib/devise/models/database_authenticatable.rb +144 -0
  56. data/lib/devise/models/http_authenticatable.rb +21 -0
  57. data/lib/devise/models/lockable.rb +150 -0
  58. data/lib/devise/models/recoverable.rb +80 -0
  59. data/lib/devise/models/registerable.rb +8 -0
  60. data/lib/devise/models/rememberable.rb +92 -0
  61. data/lib/devise/models/timeoutable.rb +28 -0
  62. data/lib/devise/models/token_authenticatable.rb +89 -0
  63. data/lib/devise/models/trackable.rb +16 -0
  64. data/lib/devise/models/validatable.rb +39 -0
  65. data/lib/devise/orm/active_record.rb +41 -0
  66. data/lib/devise/orm/data_mapper.rb +83 -0
  67. data/lib/devise/orm/mongo_mapper.rb +47 -0
  68. data/lib/devise/rails.rb +14 -0
  69. data/lib/devise/rails/routes.rb +125 -0
  70. data/lib/devise/rails/warden_compat.rb +25 -0
  71. data/lib/devise/schema.rb +73 -0
  72. data/lib/devise/strategies/base.rb +16 -0
  73. data/lib/devise/strategies/database_authenticatable.rb +36 -0
  74. data/lib/devise/strategies/http_authenticatable.rb +59 -0
  75. data/lib/devise/strategies/rememberable.rb +37 -0
  76. data/lib/devise/strategies/token_authenticatable.rb +37 -0
  77. data/lib/devise/test_helpers.rb +90 -0
  78. data/lib/devise/version.rb +3 -0
  79. data/rails/init.rb +2 -0
  80. data/test/controllers/helpers_test.rb +177 -0
  81. data/test/controllers/internal_helpers_test.rb +55 -0
  82. data/test/controllers/url_helpers_test.rb +47 -0
  83. data/test/devise_test.rb +74 -0
  84. data/test/encryptors_test.rb +31 -0
  85. data/test/failure_app_test.rb +44 -0
  86. data/test/integration/authenticatable_test.rb +271 -0
  87. data/test/integration/confirmable_test.rb +97 -0
  88. data/test/integration/http_authenticatable_test.rb +52 -0
  89. data/test/integration/lockable_test.rb +102 -0
  90. data/test/integration/rack_middleware_test.rb +47 -0
  91. data/test/integration/recoverable_test.rb +141 -0
  92. data/test/integration/registerable_test.rb +144 -0
  93. data/test/integration/rememberable_test.rb +71 -0
  94. data/test/integration/timeoutable_test.rb +68 -0
  95. data/test/integration/token_authenticatable_test.rb +55 -0
  96. data/test/integration/trackable_test.rb +64 -0
  97. data/test/mailers/confirmation_instructions_test.rb +86 -0
  98. data/test/mailers/reset_password_instructions_test.rb +68 -0
  99. data/test/mailers/unlock_instructions_test.rb +62 -0
  100. data/test/mapping_test.rb +148 -0
  101. data/test/models/authenticatable_test.rb +180 -0
  102. data/test/models/confirmable_test.rb +212 -0
  103. data/test/models/lockable_test.rb +202 -0
  104. data/test/models/recoverable_test.rb +138 -0
  105. data/test/models/rememberable_test.rb +135 -0
  106. data/test/models/timeoutable_test.rb +28 -0
  107. data/test/models/token_authenticatable_test.rb +51 -0
  108. data/test/models/trackable_test.rb +5 -0
  109. data/test/models/validatable_test.rb +106 -0
  110. data/test/models_test.rb +70 -0
  111. data/test/orm/active_record.rb +31 -0
  112. data/test/orm/mongo_mapper.rb +20 -0
  113. data/test/rails_app/app/active_record/admin.rb +7 -0
  114. data/test/rails_app/app/active_record/user.rb +7 -0
  115. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  116. data/test/rails_app/app/controllers/application_controller.rb +12 -0
  117. data/test/rails_app/app/controllers/home_controller.rb +4 -0
  118. data/test/rails_app/app/controllers/users_controller.rb +16 -0
  119. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  120. data/test/rails_app/app/mongo_mapper/admin.rb +13 -0
  121. data/test/rails_app/app/mongo_mapper/user.rb +14 -0
  122. data/test/rails_app/config/boot.rb +110 -0
  123. data/test/rails_app/config/environment.rb +42 -0
  124. data/test/rails_app/config/environments/development.rb +17 -0
  125. data/test/rails_app/config/environments/production.rb +28 -0
  126. data/test/rails_app/config/environments/test.rb +28 -0
  127. data/test/rails_app/config/initializers/devise.rb +82 -0
  128. data/test/rails_app/config/initializers/inflections.rb +2 -0
  129. data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
  130. data/test/rails_app/config/initializers/session_store.rb +15 -0
  131. data/test/rails_app/config/routes.rb +21 -0
  132. data/test/routes_test.rb +110 -0
  133. data/test/support/assertions_helper.rb +37 -0
  134. data/test/support/integration_tests_helper.rb +71 -0
  135. data/test/support/test_silencer.rb +5 -0
  136. data/test/support/tests_helper.rb +39 -0
  137. data/test/test_helper.rb +21 -0
  138. data/test/test_helpers_test.rb +57 -0
  139. metadata +213 -0
@@ -0,0 +1,17 @@
1
+ <h2>Sign in</h2>
2
+
3
+ <% form_for resource_name, resource, :url => session_path(resource_name) do |f| -%>
4
+ <p><%= f.label :email %></p>
5
+ <p><%= f.text_field :email %></p>
6
+
7
+ <p><%= f.label :password %></p>
8
+ <p><%= f.password_field :password %></p>
9
+
10
+ <% if devise_mapping.rememberable? -%>
11
+ <p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
12
+ <% end -%>
13
+
14
+ <p><%= f.submit "Sign in" %></p>
15
+ <% end -%>
16
+
17
+ <%= render :partial => "shared/devise_links" %>
@@ -0,0 +1,19 @@
1
+ <%- if controller_name != 'sessions' %>
2
+ <%= link_to t('devise.sessions.link'), new_session_path(resource_name) %><br />
3
+ <% end -%>
4
+
5
+ <%- if devise_mapping.registerable? && controller_name != 'registrations' %>
6
+ <%= link_to t('devise.registrations.link'), new_registration_path(resource_name) %><br />
7
+ <% end -%>
8
+
9
+ <%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
10
+ <%= link_to t('devise.passwords.link'), new_password_path(resource_name) %><br />
11
+ <% end -%>
12
+
13
+ <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
14
+ <%= link_to t('devise.confirmations.link'), new_confirmation_path(resource_name) %><br />
15
+ <% end -%>
16
+
17
+ <%- if devise_mapping.lockable? && controller_name != 'unlocks' %>
18
+ <%= link_to t('devise.unlocks.link'), new_unlock_path(resource_name) %><br />
19
+ <% end -%>
@@ -0,0 +1,12 @@
1
+ <h2>Resend unlock instructions</h2>
2
+
3
+ <% form_for resource_name, resource, :url => unlock_path(resource_name) do |f| %>
4
+ <%= f.error_messages %>
5
+
6
+ <p><%= f.label :email %></p>
7
+ <p><%= f.text_field :email %></p>
8
+
9
+ <p><%= f.submit "Resend unlock instructions" %></p>
10
+ <% end %>
11
+
12
+ <%= render :partial => "shared/devise_links" %>
@@ -0,0 +1,5 @@
1
+ To create a devise resource user:
2
+
3
+ script/generate devise User
4
+
5
+ This will generate a model named User, a route map for devise called :users, and a migration file for table :users with all devise modules.
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/route_devise.rb")
2
+
3
+ class DeviseGenerator < Rails::Generator::NamedBase
4
+
5
+ def manifest
6
+ record do |m|
7
+ m.directory(File.join('app', 'models', class_path))
8
+ m.template 'model.rb', File.join('app', 'models', "#{file_path}.rb")
9
+
10
+ m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "devise_create_#{table_name}"
11
+ m.route_devise table_name
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,32 @@
1
+ module Rails
2
+ module Generator
3
+ module Commands
4
+ class Create < Base
5
+
6
+ # Create devise route. Based on route_resources
7
+ def route_devise(*resources)
8
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
9
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
10
+
11
+ logger.route "map.devise_for #{resource_list}"
12
+ unless options[:pretend]
13
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
14
+ "#{match}\n map.devise_for #{resource_list}\n"
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ class Destroy < RewindBase
21
+
22
+ # Destroy devise route. Based on route_resources
23
+ def route_devise(*resources)
24
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
25
+ look_for = "\n map.devise_for #{resource_list}\n"
26
+ logger.route "map.devise_for #{resource_list}"
27
+ gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table(:<%= table_name %>) do |t|
4
+ t.database_authenticatable :null => false
5
+ t.confirmable
6
+ t.recoverable
7
+ t.rememberable
8
+ t.trackable
9
+ # t.lockable
10
+
11
+ t.timestamps
12
+ end
13
+
14
+ add_index :<%= table_name %>, :email, :unique => true
15
+ add_index :<%= table_name %>, :confirmation_token, :unique => true
16
+ add_index :<%= table_name %>, :reset_password_token, :unique => true
17
+ # add_index :<%= table_name %>, :unlock_token, :unique => true
18
+ end
19
+
20
+ def self.down
21
+ drop_table :<%= table_name %>
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ # Include default devise modules. Others available are:
3
+ # :http_authenticatable, :token_authenticatable, :confirmable, :lockable, :timeoutable and :activatable
4
+ devise :registerable, :authenticatable, :recoverable,
5
+ :rememberable, :trackable, :validatable
6
+
7
+ # Setup accessible (or protected) attributes for your model
8
+ attr_accessible :email, :password, :password_confirmation
9
+ end
@@ -0,0 +1,3 @@
1
+ To copy a Devise initializer to your Rails App, with some configuration values, just do:
2
+
3
+ script/generate devise_install
@@ -0,0 +1,15 @@
1
+ class DeviseInstallGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ m.directory "config/initializers"
6
+ m.template "devise.rb", "config/initializers/devise.rb"
7
+
8
+ m.directory "config/locales"
9
+ m.file "../../../lib/devise/locales/en.yml", "config/locales/devise.en.yml"
10
+
11
+ m.readme "README"
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,23 @@
1
+ ===============================================================================
2
+
3
+ Some setup you must do manually if you haven't yet:
4
+
5
+ 1. Setup default url options for your specific environment. Here is an
6
+ example of development environment:
7
+
8
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
9
+
10
+ This is a required Rails configuration. In production is must be the
11
+ actual host of your application
12
+
13
+ 2. Ensure you have defined root_url to *something* in your config/routes.rb:
14
+
15
+ map.root :controller => 'home'
16
+
17
+ 3. Ensure you have a default layout in app/views/layouts and it shows
18
+ flash messages. For example:
19
+
20
+ <p class="notice"><%= flash[:notice] %></p>
21
+ <p class="alert"><%= flash[:alert] %></p>
22
+
23
+ ===============================================================================
@@ -0,0 +1,105 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth. The first
2
+ # four configuration values can also be set straight in your models.
3
+ Devise.setup do |config|
4
+ # Configure the e-mail address which will be shown in DeviseMailer.
5
+ config.mailer_sender = "please-change-me@config-initializers-devise.com"
6
+
7
+ # Configure the content type of DeviseMailer mails (defaults to text/html")
8
+ # config.mailer_content_type = "text/plain"
9
+
10
+ # ==> Configuration for :authenticatable
11
+ # Invoke `rake secret` and use the printed value to setup a pepper to generate
12
+ # the encrypted password. By default no pepper is used.
13
+ # config.pepper = "rake secret output"
14
+
15
+ # Configure how many times you want the password is reencrypted. Default is 10.
16
+ # config.stretches = 10
17
+
18
+ # Define which will be the encryption algorithm. Supported algorithms are :sha1
19
+ # (default), :sha512 and :bcrypt. Devise also supports encryptors from others
20
+ # authentication tools as :clearance_sha1, :authlogic_sha512 (then you should set
21
+ # stretches above to 20 for default behavior) and :restful_authentication_sha1
22
+ # (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
23
+ # config.encryptor = :sha1
24
+
25
+ # Configure which keys are used when authenticating an user. By default is
26
+ # just :email. You can configure it to use [:username, :subdomain], so for
27
+ # authenticating an user, both parameters are required. Remember that those
28
+ # parameters are used only when authenticating and not when retrieving from
29
+ # session. If you need permissions, you should implement that in a before filter.
30
+ # config.authentication_keys = [ :email ]
31
+
32
+ # The realm used in Http Basic Authentication
33
+ # config.http_authentication_realm = "Application"
34
+
35
+ # ==> Configuration for :confirmable
36
+ # The time you want give to your user to confirm his account. During this time
37
+ # he will be able to access your application without confirming. Default is nil.
38
+ # config.confirm_within = 2.days
39
+
40
+ # ==> Configuration for :rememberable
41
+ # The time the user will be remembered without asking for credentials again.
42
+ # config.remember_for = 2.weeks
43
+
44
+ # ==> Configuration for :timeoutable
45
+ # The time you want to timeout the user session without activity. After this
46
+ # time the user will be asked for credentials again.
47
+ # config.timeout_in = 10.minutes
48
+
49
+ # ==> Configuration for :lockable
50
+ # Number of authentication tries before locking an account.
51
+ # config.maximum_attempts = 20
52
+
53
+ # Defines which strategy will be used to unlock an account.
54
+ # :email = Sends an unlock link to the user email
55
+ # :time = Reanables login after a certain ammount of time (see :unlock_in below)
56
+ # :both = enables both strategies
57
+ # config.unlock_strategy = :both
58
+
59
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
60
+ # config.unlock_in = 1.hour
61
+
62
+ # ==> Configuration for :token_authenticatable
63
+ # Defines name of the authentication token params key
64
+ # config.token_authentication_key = :auth_token
65
+
66
+ # ==> General configuration
67
+ # Load and configure the ORM. Supports :active_record (default), :mongo_mapper
68
+ # (requires mongo_ext installed) and :data_mapper (experimental).
69
+ # require 'devise/orm/mongo_mapper'
70
+ # config.orm = :mongo_mapper
71
+
72
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
73
+ # "sessions/users/new". It's turned off by default because it's slower if you
74
+ # are using only default views.
75
+ # config.scoped_views = true
76
+
77
+ # By default, devise detects the role accessed based on the url. So whenever
78
+ # accessing "/users/sign_in", it knows you are accessing an User. This makes
79
+ # routes as "/sign_in" not possible, unless you tell Devise to use the default
80
+ # scope, setting true below.
81
+ # config.use_default_scope = true
82
+
83
+ # Configure the default scope used by Devise. By default it's the first devise
84
+ # role declared in your routes.
85
+ # config.default_scope = :user
86
+
87
+ # If you want to use other strategies, that are not (yet) supported by Devise,
88
+ # you can configure them inside the config.warden block. The example below
89
+ # allows you to setup OAuth, using http://github.com/roman/warden_oauth
90
+ #
91
+ # config.warden do |manager|
92
+ # manager.oauth(:twitter) do |twitter|
93
+ # twitter.consumer_secret = <YOUR CONSUMER SECRET>
94
+ # twitter.consumer_key = <YOUR CONSUMER KEY>
95
+ # twitter.options :site => 'http://twitter.com'
96
+ # end
97
+ # manager.default_strategies.unshift :twitter_oauth
98
+ # end
99
+
100
+ # Configure default_url_options if you are using dynamic segments in :path_prefix
101
+ # for devise_for.
102
+ # config.default_url_options do
103
+ # { :locale => I18n.locale }
104
+ # end
105
+ end
@@ -0,0 +1,3 @@
1
+ To copy all session, password, confirmation and mailer views from devise to your app just run the following command:
2
+
3
+ script/generate devise_views
@@ -0,0 +1,21 @@
1
+ class DeviseViewsGenerator < Rails::Generator::Base
2
+
3
+ def initialize(*args)
4
+ super
5
+ @source_root = options[:source] || File.join(spec.path, '..', '..')
6
+ end
7
+
8
+ def manifest
9
+ record do |m|
10
+ m.directory "app/views"
11
+
12
+ Dir[File.join(@source_root, "app", "views", "**/*.erb")].each do |file|
13
+ file = file.gsub(@source_root, "")[1..-1]
14
+
15
+ m.directory File.dirname(file)
16
+ m.file file, file
17
+ end
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,264 @@
1
+ module Devise
2
+ autoload :FailureApp, 'devise/failure_app'
3
+ autoload :Models, 'devise/models'
4
+ autoload :Schema, 'devise/schema'
5
+ autoload :TestHelpers, 'devise/test_helpers'
6
+
7
+ module Controllers
8
+ autoload :Helpers, 'devise/controllers/helpers'
9
+ autoload :InternalHelpers, 'devise/controllers/internal_helpers'
10
+ autoload :UrlHelpers, 'devise/controllers/url_helpers'
11
+ end
12
+
13
+ module Encryptors
14
+ autoload :Base, 'devise/encryptors/base'
15
+ autoload :Bcrypt, 'devise/encryptors/bcrypt'
16
+ autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
17
+ autoload :ClearanceSha1, 'devise/encryptors/clearance_sha1'
18
+ autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
19
+ autoload :Sha512, 'devise/encryptors/sha512'
20
+ autoload :Sha1, 'devise/encryptors/sha1'
21
+ end
22
+
23
+ module Orm
24
+ autoload :ActiveRecord, 'devise/orm/active_record'
25
+ autoload :DataMapper, 'devise/orm/data_mapper'
26
+ autoload :MongoMapper, 'devise/orm/mongo_mapper'
27
+ end
28
+
29
+ ALL = []
30
+
31
+ # Authentication ones first
32
+ ALL.push :database_authenticatable, :http_authenticatable, :token_authenticatable, :rememberable
33
+
34
+ # Misc after
35
+ ALL.push :recoverable, :registerable, :validatable
36
+
37
+ # The ones which can sign out after
38
+ ALL.push :activatable, :confirmable, :lockable, :timeoutable
39
+
40
+ # Stats for last, so we make sure the user is really signed in
41
+ ALL.push :trackable
42
+
43
+ # Maps controller names to devise modules.
44
+ CONTROLLERS = {
45
+ :sessions => [:database_authenticatable, :token_authenticatable],
46
+ :passwords => [:recoverable],
47
+ :confirmations => [:confirmable],
48
+ :registrations => [:registerable],
49
+ :unlocks => [:lockable]
50
+ }
51
+
52
+ # Routes for generating url helpers.
53
+ ROUTES = [:session, :password, :confirmation, :registration, :unlock]
54
+
55
+ STRATEGIES = [:rememberable, :http_authenticatable, :token_authenticatable, :database_authenticatable]
56
+
57
+ TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
58
+
59
+ # Maps the messages types that are used in flash message.
60
+ FLASH_MESSAGES = [:unauthenticated, :unconfirmed, :invalid, :invalid_token, :timeout, :inactive, :locked]
61
+
62
+ # Declare encryptors length which are used in migrations.
63
+ ENCRYPTORS_LENGTH = {
64
+ :sha1 => 40,
65
+ :sha512 => 128,
66
+ :clearance_sha1 => 40,
67
+ :restful_authentication_sha1 => 40,
68
+ :authlogic_sha512 => 128,
69
+ :bcrypt => 60
70
+ }
71
+
72
+ # Email regex used to validate email formats. Adapted from authlogic.
73
+ EMAIL_REGEX = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
74
+
75
+ # Used to encrypt password. Please generate one with rake secret.
76
+ mattr_accessor :pepper
77
+ @@pepper = nil
78
+
79
+ # The number of times to encrypt password.
80
+ mattr_accessor :stretches
81
+ @@stretches = 10
82
+
83
+ # Keys used when authenticating an user.
84
+ mattr_accessor :authentication_keys
85
+ @@authentication_keys = [ :email ]
86
+
87
+ # Time interval where the remember me token is valid.
88
+ mattr_accessor :remember_for
89
+ @@remember_for = 2.weeks
90
+
91
+ # Time interval you can access your account before confirming your account.
92
+ mattr_accessor :confirm_within
93
+ @@confirm_within = 0.days
94
+
95
+ # Time interval to timeout the user session without activity.
96
+ mattr_accessor :timeout_in
97
+ @@timeout_in = 30.minutes
98
+
99
+ # Used to define the password encryption algorithm.
100
+ mattr_accessor :encryptor
101
+ @@encryptor = :sha1
102
+
103
+ # Store scopes mappings.
104
+ mattr_accessor :mappings
105
+ @@mappings = ActiveSupport::OrderedHash.new
106
+
107
+ # Stores the chosen ORM.
108
+ mattr_accessor :orm
109
+ @@orm = :active_record
110
+
111
+ # TODO Remove
112
+ mattr_accessor :all
113
+ @@all = []
114
+
115
+ # Tells if devise should apply the schema in ORMs where devise declaration
116
+ # and schema belongs to the same class (as Datamapper and MongoMapper).
117
+ mattr_accessor :apply_schema
118
+ @@apply_schema = true
119
+
120
+ # Scoped views. Since it relies on fallbacks to render default views, it's
121
+ # turned off by default.
122
+ mattr_accessor :scoped_views
123
+ @@scoped_views = false
124
+
125
+ # Number of authentication tries before locking an account
126
+ mattr_accessor :maximum_attempts
127
+ @@maximum_attempts = 20
128
+
129
+ # Defines which strategy can be used to unlock an account.
130
+ # Values: :email, :time, :both
131
+ mattr_accessor :unlock_strategy
132
+ @@unlock_strategy = :both
133
+
134
+ # Time interval to unlock the account if :time is defined as unlock_strategy.
135
+ mattr_accessor :unlock_in
136
+ @@unlock_in = 1.hour
137
+
138
+ # Tell when to use the default scope, if one cannot be found from routes.
139
+ mattr_accessor :use_default_scope
140
+ @@use_default_scope = false
141
+
142
+ # The default scope which is used by warden.
143
+ mattr_accessor :default_scope
144
+ @@default_scope = nil
145
+
146
+ # Address which sends Devise e-mails.
147
+ mattr_accessor :mailer_sender
148
+ @@mailer_sender = nil
149
+
150
+ # Content Type of Devise e-mails.
151
+ mattr_accessor :mailer_content_type
152
+ @@mailer_content_type = 'text/html'
153
+
154
+ # Authentication token params key name of choice. E.g. /users/sign_in?some_key=...
155
+ mattr_accessor :token_authentication_key
156
+ @@token_authentication_key = :auth_token
157
+
158
+ # The realm used in Http Basic Authentication
159
+ mattr_accessor :http_authentication_realm
160
+ @@http_authentication_realm = "Application"
161
+
162
+ class << self
163
+ # Default way to setup Devise. Run script/generate devise_install to create
164
+ # a fresh initializer with all configuration values.
165
+ def setup
166
+ yield self
167
+ end
168
+
169
+ # Sets warden configuration using a block that will be invoked on warden
170
+ # initialization.
171
+ #
172
+ # Devise.initialize do |config|
173
+ # config.confirm_within = 2.days
174
+ #
175
+ # config.warden do |manager|
176
+ # # Configure warden to use other strategies, like oauth.
177
+ # manager.oauth(:twitter)
178
+ # end
179
+ # end
180
+ def warden(&block)
181
+ @warden_config = block
182
+ end
183
+
184
+ # Configure default url options to be used within Devise and ActionController.
185
+ def default_url_options(&block)
186
+ Devise::Mapping.metaclass.send :define_method, :default_url_options, &block
187
+ end
188
+
189
+ # A method used internally to setup warden manager from the Rails initialize
190
+ # block.
191
+ def configure_warden(config) #:nodoc:
192
+ config.default_strategies *Devise::STRATEGIES
193
+ config.failure_app = Devise::FailureApp
194
+ config.silence_missing_strategies!
195
+ config.default_scope = Devise.default_scope
196
+
197
+ # If the user provided a warden hook, call it now.
198
+ @warden_config.try :call, config
199
+ end
200
+
201
+ # The class of the configured ORM
202
+ def orm_class
203
+ Devise::Orm.const_get(@@orm.to_s.camelize.to_sym)
204
+ end
205
+
206
+ # Generate a friendly string randomically to be used as token.
207
+ def friendly_token
208
+ ActiveSupport::SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
209
+ end
210
+
211
+ # Make Devise aware of an 3rd party Devise-module. For convenience.
212
+ #
213
+ # == Options:
214
+ #
215
+ # +strategy+ - Boolean value representing if this module got a custom *strategy*.
216
+ # Default is +false+. Note: Devise will auto-detect this in such case if this is true.
217
+ # +model+ - String representing a load path to a custom *model* for this module (to autoload).
218
+ # Default is +nil+ (i.e. +false+).
219
+ # +controller+ - Symbol representing a name of an exisiting or custom *controller* for this module.
220
+ # Default is +nil+ (i.e. +false+).
221
+ # +route+ - Symbol representing the name of a *route* related to this module which a set of
222
+ # route view helpers should be created for.
223
+ # Default is +nil+ (i.e. +false+).
224
+ #
225
+ # == Examples:
226
+ #
227
+ # Devise.add_module(:party_module)
228
+ # Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
229
+ # Devise.add_module(:party_module, :model => 'party_module/model')
230
+ #
231
+ def add_module(module_name, options = {})
232
+ Devise::ALL << module_name unless Devise::ALL.include?(module_name)
233
+ Devise::STRATEGIES.unshift module_name if options[:strategy] && !Devise::STRATEGIES.include?(module_name)
234
+
235
+ if options[:controller]
236
+ controller = options[:controller].to_sym
237
+ Devise::CONTROLLERS[controller] ||= []
238
+ Devise::CONTROLLERS[controller].unshift module_name unless Devise::CONTROLLERS[controller].include?(module_name)
239
+ end
240
+
241
+ if options[:route]
242
+ Devise::ROUTES.unshift options[:route] unless Devise::ROUTES.include?(options[:route])
243
+ end
244
+
245
+ if options[:model]
246
+ Devise::Models.module_eval do
247
+ autoload :"#{module_name.to_s.classify}", options[:model]
248
+ end
249
+ end
250
+
251
+ Devise::Mapping.register module_name
252
+ end
253
+ end
254
+ end
255
+
256
+ begin
257
+ require 'warden'
258
+ rescue
259
+ gem 'warden'
260
+ require 'warden'
261
+ end
262
+
263
+ require 'devise/mapping'
264
+ require 'devise/rails'