glennr-devise 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. data/CHANGELOG.rdoc +334 -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 +42 -0
  8. data/app/controllers/registrations_controller.rb +55 -0
  9. data/app/controllers/sessions_controller.rb +45 -0
  10. data/app/controllers/unlocks_controller.rb +33 -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 +18 -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/init.rb +2 -0
  35. data/lib/devise.rb +256 -0
  36. data/lib/devise/controllers/helpers.rb +200 -0
  37. data/lib/devise/controllers/internal_helpers.rb +129 -0
  38. data/lib/devise/controllers/url_helpers.rb +41 -0
  39. data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
  40. data/lib/devise/encryptors/base.rb +20 -0
  41. data/lib/devise/encryptors/bcrypt.rb +21 -0
  42. data/lib/devise/encryptors/clearance_sha1.rb +19 -0
  43. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  44. data/lib/devise/encryptors/sha1.rb +27 -0
  45. data/lib/devise/encryptors/sha512.rb +27 -0
  46. data/lib/devise/failure_app.rb +65 -0
  47. data/lib/devise/hooks/activatable.rb +15 -0
  48. data/lib/devise/hooks/rememberable.rb +30 -0
  49. data/lib/devise/hooks/timeoutable.rb +18 -0
  50. data/lib/devise/hooks/trackable.rb +18 -0
  51. data/lib/devise/locales/en.yml +35 -0
  52. data/lib/devise/mapping.rb +131 -0
  53. data/lib/devise/models.rb +112 -0
  54. data/lib/devise/models/activatable.rb +16 -0
  55. data/lib/devise/models/authenticatable.rb +146 -0
  56. data/lib/devise/models/confirmable.rb +172 -0
  57. data/lib/devise/models/http_authenticatable.rb +21 -0
  58. data/lib/devise/models/lockable.rb +160 -0
  59. data/lib/devise/models/recoverable.rb +80 -0
  60. data/lib/devise/models/registerable.rb +8 -0
  61. data/lib/devise/models/rememberable.rb +92 -0
  62. data/lib/devise/models/timeoutable.rb +28 -0
  63. data/lib/devise/models/token_authenticatable.rb +89 -0
  64. data/lib/devise/models/trackable.rb +16 -0
  65. data/lib/devise/models/validatable.rb +48 -0
  66. data/lib/devise/orm/active_record.rb +41 -0
  67. data/lib/devise/orm/data_mapper.rb +83 -0
  68. data/lib/devise/orm/mongo_mapper.rb +50 -0
  69. data/lib/devise/rails.rb +14 -0
  70. data/lib/devise/rails/routes.rb +125 -0
  71. data/lib/devise/rails/warden_compat.rb +25 -0
  72. data/lib/devise/schema.rb +65 -0
  73. data/lib/devise/strategies/authenticatable.rb +36 -0
  74. data/lib/devise/strategies/base.rb +16 -0
  75. data/lib/devise/strategies/http_authenticatable.rb +49 -0
  76. data/lib/devise/strategies/rememberable.rb +37 -0
  77. data/lib/devise/strategies/token_authenticatable.rb +37 -0
  78. data/lib/devise/test_helpers.rb +86 -0
  79. data/lib/devise/version.rb +3 -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 +69 -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 +44 -0
  89. data/test/integration/lockable_test.rb +83 -0
  90. data/test/integration/recoverable_test.rb +141 -0
  91. data/test/integration/registerable_test.rb +130 -0
  92. data/test/integration/rememberable_test.rb +63 -0
  93. data/test/integration/timeoutable_test.rb +68 -0
  94. data/test/integration/token_authenticatable_test.rb +55 -0
  95. data/test/integration/trackable_test.rb +64 -0
  96. data/test/mailers/confirmation_instructions_test.rb +80 -0
  97. data/test/mailers/reset_password_instructions_test.rb +68 -0
  98. data/test/mailers/unlock_instructions_test.rb +62 -0
  99. data/test/mapping_test.rb +153 -0
  100. data/test/models/authenticatable_test.rb +180 -0
  101. data/test/models/confirmable_test.rb +228 -0
  102. data/test/models/lockable_test.rb +202 -0
  103. data/test/models/recoverable_test.rb +138 -0
  104. data/test/models/rememberable_test.rb +135 -0
  105. data/test/models/timeoutable_test.rb +28 -0
  106. data/test/models/token_authenticatable_test.rb +51 -0
  107. data/test/models/trackable_test.rb +5 -0
  108. data/test/models/validatable_test.rb +106 -0
  109. data/test/models_test.rb +56 -0
  110. data/test/orm/active_record.rb +31 -0
  111. data/test/orm/mongo_mapper.rb +20 -0
  112. data/test/rails_app/app/active_record/admin.rb +7 -0
  113. data/test/rails_app/app/active_record/user.rb +7 -0
  114. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  115. data/test/rails_app/app/controllers/application_controller.rb +10 -0
  116. data/test/rails_app/app/controllers/home_controller.rb +4 -0
  117. data/test/rails_app/app/controllers/users_controller.rb +16 -0
  118. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  119. data/test/rails_app/app/mongo_mapper/admin.rb +9 -0
  120. data/test/rails_app/app/mongo_mapper/user.rb +8 -0
  121. data/test/rails_app/config/boot.rb +110 -0
  122. data/test/rails_app/config/environment.rb +42 -0
  123. data/test/rails_app/config/environments/development.rb +17 -0
  124. data/test/rails_app/config/environments/production.rb +28 -0
  125. data/test/rails_app/config/environments/test.rb +28 -0
  126. data/test/rails_app/config/initializers/devise.rb +82 -0
  127. data/test/rails_app/config/initializers/inflections.rb +2 -0
  128. data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
  129. data/test/rails_app/config/initializers/session_store.rb +15 -0
  130. data/test/rails_app/config/routes.rb +21 -0
  131. data/test/routes_test.rb +110 -0
  132. data/test/support/assertions_helper.rb +37 -0
  133. data/test/support/integration_tests_helper.rb +71 -0
  134. data/test/support/test_silencer.rb +5 -0
  135. data/test/support/tests_helper.rb +39 -0
  136. data/test/test_helper.rb +21 -0
  137. data/test/test_helpers_test.rb +57 -0
  138. metadata +202 -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.authenticatable :encryptor => :sha1, :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, :lockable, :timeoutable and :activatable
4
+ devise :registerable, :authenticatable, :confirmable, :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,18 @@
1
+
2
+ ===============================================================================
3
+
4
+ Some setup you must do manually if you haven't yet:
5
+
6
+ 1. Setup default url options for your specific environment. Here is an
7
+ example of development environment:
8
+
9
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
10
+
11
+ This is a required Rails configuration. In production is must be the
12
+ actual host of your application
13
+
14
+ 2. Ensure you have defined root_url to *something* in your config/routes.rb:
15
+
16
+ map.root :controller => 'home'
17
+
18
+ ===============================================================================
@@ -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
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # We need to load devise here to ensure routes extensions are loaded.
2
+ require 'devise'
data/lib/devise.rb ADDED
@@ -0,0 +1,256 @@
1
+ module Devise
2
+ autoload :FailureApp, 'devise/failure_app'
3
+ autoload :Schema, 'devise/schema'
4
+ autoload :TestHelpers, 'devise/test_helpers'
5
+
6
+ module Controllers
7
+ autoload :Helpers, 'devise/controllers/helpers'
8
+ autoload :InternalHelpers, 'devise/controllers/internal_helpers'
9
+ autoload :UrlHelpers, 'devise/controllers/url_helpers'
10
+ end
11
+
12
+ module Encryptors
13
+ autoload :Base, 'devise/encryptors/base'
14
+ autoload :Bcrypt, 'devise/encryptors/bcrypt'
15
+ autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
16
+ autoload :ClearanceSha1, 'devise/encryptors/clearance_sha1'
17
+ autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
18
+ autoload :Sha512, 'devise/encryptors/sha512'
19
+ autoload :Sha1, 'devise/encryptors/sha1'
20
+ end
21
+
22
+ module Orm
23
+ autoload :ActiveRecord, 'devise/orm/active_record'
24
+ autoload :DataMapper, 'devise/orm/data_mapper'
25
+ autoload :MongoMapper, 'devise/orm/mongo_mapper'
26
+ end
27
+
28
+ ALL = []
29
+
30
+ # Authentication ones first
31
+ ALL.push :authenticatable, :http_authenticatable, :token_authenticatable, :rememberable
32
+
33
+ # Misc after
34
+ ALL.push :recoverable, :registerable, :validatable
35
+
36
+ # The ones which can sign out after
37
+ ALL.push :activatable, :confirmable, :lockable, :timeoutable
38
+
39
+ # Stats for last, so we make sure the user is really signed in
40
+ ALL.push :trackable
41
+
42
+ # Maps controller names to devise modules.
43
+ CONTROLLERS = {
44
+ :sessions => [:authenticatable, :token_authenticatable],
45
+ :passwords => [:recoverable],
46
+ :confirmations => [:confirmable],
47
+ :registrations => [:registerable],
48
+ :unlocks => [:lockable]
49
+ }
50
+
51
+ # Routes for generating url helpers.
52
+ ROUTES = [:session, :password, :confirmation, :registration, :unlock]
53
+
54
+ STRATEGIES = [:rememberable, :http_authenticatable, :token_authenticatable, :authenticatable]
55
+
56
+ TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
57
+
58
+ # Maps the messages types that are used in flash message.
59
+ FLASH_MESSAGES = [:unauthenticated, :unconfirmed, :invalid, :invalid_token, :timeout, :inactive, :locked]
60
+
61
+ # Declare encryptors length which are used in migrations.
62
+ ENCRYPTORS_LENGTH = {
63
+ :sha1 => 40,
64
+ :sha512 => 128,
65
+ :clearance_sha1 => 40,
66
+ :restful_authentication_sha1 => 40,
67
+ :authlogic_sha512 => 128,
68
+ :bcrypt => 60
69
+ }
70
+
71
+ # Email regex used to validate email formats. Adapted from authlogic.
72
+ EMAIL_REGEX = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
73
+
74
+ # Used to encrypt password. Please generate one with rake secret.
75
+ mattr_accessor :pepper
76
+ @@pepper = nil
77
+
78
+ # The number of times to encrypt password.
79
+ mattr_accessor :stretches
80
+ @@stretches = 10
81
+
82
+ # Keys used when authenticating an user.
83
+ mattr_accessor :authentication_keys
84
+ @@authentication_keys = [ :email ]
85
+
86
+ # Time interval where the remember me token is valid.
87
+ mattr_accessor :remember_for
88
+ @@remember_for = 2.weeks
89
+
90
+ # Time interval you can access your account before confirming your account.
91
+ mattr_accessor :confirm_within
92
+ @@confirm_within = 0.days
93
+
94
+ # Time interval to timeout the user session without activity.
95
+ mattr_accessor :timeout_in
96
+ @@timeout_in = 30.minutes
97
+
98
+ # Used to define the password encryption algorithm.
99
+ mattr_accessor :encryptor
100
+ @@encryptor = :sha1
101
+
102
+ # Store scopes mappings.
103
+ mattr_accessor :mappings
104
+ @@mappings = ActiveSupport::OrderedHash.new
105
+
106
+ # Stores the chosen ORM.
107
+ mattr_accessor :orm
108
+ @@orm = :active_record
109
+
110
+ # TODO Remove
111
+ mattr_accessor :all
112
+ @@all = []
113
+
114
+ # Tells if devise should apply the schema in ORMs where devise declaration
115
+ # and schema belongs to the same class (as Datamapper and MongoMapper).
116
+ mattr_accessor :apply_schema
117
+ @@apply_schema = true
118
+
119
+ # Scoped views. Since it relies on fallbacks to render default views, it's
120
+ # turned off by default.
121
+ mattr_accessor :scoped_views
122
+ @@scoped_views = false
123
+
124
+ # Number of authentication tries before locking an account
125
+ mattr_accessor :maximum_attempts
126
+ @@maximum_attempts = 20
127
+
128
+ # Defines which strategy can be used to unlock an account.
129
+ # Values: :email, :time, :both
130
+ mattr_accessor :unlock_strategy
131
+ @@unlock_strategy = :both
132
+
133
+ # Time interval to unlock the account if :time is defined as unlock_strategy.
134
+ mattr_accessor :unlock_in
135
+ @@unlock_in = 1.hour
136
+
137
+ # Tell when to use the default scope, if one cannot be found from routes.
138
+ mattr_accessor :use_default_scope
139
+ @@use_default_scope = false
140
+
141
+ # The default scope which is used by warden.
142
+ mattr_accessor :default_scope
143
+ @@default_scope = nil
144
+
145
+ # Address which sends Devise e-mails.
146
+ mattr_accessor :mailer_sender
147
+ @@mailer_sender = nil
148
+
149
+ # Content Type of Devise e-mails.
150
+ mattr_accessor :mailer_content_type
151
+ @@mailer_content_type = 'text/html'
152
+
153
+ # Authentication token params key name of choice. E.g. /users/sign_in?some_key=...
154
+ mattr_accessor :token_authentication_key
155
+ @@token_authentication_key = :auth_token
156
+
157
+ # The realm used in Http Basic Authentication
158
+ mattr_accessor :http_authentication_realm
159
+ @@http_authentication_realm = "Application"
160
+
161
+ class << self
162
+ # Default way to setup Devise. Run script/generate devise_install to create
163
+ # a fresh initializer with all configuration values.
164
+ def setup
165
+ yield self
166
+ end
167
+
168
+ # Sets warden configuration using a block that will be invoked on warden
169
+ # initialization.
170
+ #
171
+ # Devise.initialize do |config|
172
+ # config.confirm_within = 2.days
173
+ #
174
+ # config.warden do |manager|
175
+ # # Configure warden to use other strategies, like oauth.
176
+ # manager.oauth(:twitter)
177
+ # end
178
+ # end
179
+ def warden(&block)
180
+ @warden_config = block
181
+ end
182
+
183
+ # Configure default url options to be used within Devise and ActionController.
184
+ def default_url_options(&block)
185
+ Devise::Mapping.metaclass.send :define_method, :default_url_options, &block
186
+ end
187
+
188
+ # A method used internally to setup warden manager from the Rails initialize
189
+ # block.
190
+ def configure_warden(config) #:nodoc:
191
+ config.default_strategies *Devise::STRATEGIES
192
+ config.failure_app = Devise::FailureApp
193
+ config.silence_missing_strategies!
194
+ config.default_scope = Devise.default_scope
195
+
196
+ # If the user provided a warden hook, call it now.
197
+ @warden_config.try :call, config
198
+ end
199
+
200
+ # The class of the configured ORM
201
+ def orm_class
202
+ Devise::Orm.const_get(@@orm.to_s.camelize.to_sym)
203
+ end
204
+
205
+ # Generate a friendly string randomically to be used as token.
206
+ def friendly_token
207
+ ActiveSupport::SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
208
+ end
209
+
210
+ # Make Devise aware of an 3rd party Devise-module. For convenience.
211
+ #
212
+ # == Options:
213
+ #
214
+ # +strategy+ - Boolean value representing if this module got a custom *strategy*.
215
+ # Default is +false+. Note: Devise will auto-detect this in such case if this is true.
216
+ # +model+ - String representing a load path to a custom *model* for this module (to autoload).
217
+ # Default is +nil+ (i.e. +false+).
218
+ # +controller+ - Symbol representing a name of an exisiting or custom *controller* for this module.
219
+ # Default is +nil+ (i.e. +false+).
220
+ #
221
+ # == Examples:
222
+ #
223
+ # Devise.add_module(:party_module)
224
+ # Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
225
+ # Devise.add_module(:party_module, :model => 'party_module/model')
226
+ #
227
+ def add_module(module_name, options = {})
228
+ Devise::ALL.unshift module_name unless Devise::ALL.include?(module_name)
229
+ Devise::STRATEGIES.unshift module_name if options[:strategy] && !Devise::STRATEGIES.include?(module_name)
230
+
231
+ if options[:controller]
232
+ controller = options[:controller].to_sym
233
+ Devise::CONTROLLERS[controller] ||= []
234
+ Devise::CONTROLLERS[controller].unshift module_name unless Devise::CONTROLLERS[controller].include?(module_name)
235
+ end
236
+
237
+ if options[:model]
238
+ Devise::Models.module_eval do
239
+ autoload :"#{module_name.to_s.classify}", options[:model]
240
+ end
241
+ end
242
+
243
+ Devise::Mapping.register module_name
244
+ end
245
+ end
246
+ end
247
+
248
+ begin
249
+ require 'warden'
250
+ rescue
251
+ gem 'warden'
252
+ require 'warden'
253
+ end
254
+
255
+ require 'devise/mapping'
256
+ require 'devise/rails'