devise 1.0.11 → 1.1.0

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 (176) hide show
  1. data/CHANGELOG.rdoc +59 -13
  2. data/Gemfile +23 -0
  3. data/Gemfile.lock +118 -0
  4. data/README.rdoc +116 -77
  5. data/Rakefile +4 -2
  6. data/TODO +3 -2
  7. data/app/controllers/{confirmations_controller.rb → devise/confirmations_controller.rb} +1 -1
  8. data/app/controllers/{passwords_controller.rb → devise/passwords_controller.rb} +1 -1
  9. data/app/controllers/{registrations_controller.rb → devise/registrations_controller.rb} +12 -8
  10. data/app/controllers/devise/sessions_controller.rb +23 -0
  11. data/app/controllers/{unlocks_controller.rb → devise/unlocks_controller.rb} +1 -8
  12. data/app/helpers/devise_helper.rb +17 -0
  13. data/app/mailers/devise/mailer.rb +71 -0
  14. data/app/views/devise/confirmations/new.html.erb +12 -0
  15. data/app/views/devise/passwords/edit.html.erb +16 -0
  16. data/app/views/devise/passwords/new.html.erb +12 -0
  17. data/app/views/devise/registrations/edit.html.erb +25 -0
  18. data/app/views/devise/registrations/new.html.erb +18 -0
  19. data/app/views/devise/sessions/new.html.erb +17 -0
  20. data/app/views/devise/shared/_links.erb +19 -0
  21. data/app/views/devise/unlocks/new.html.erb +12 -0
  22. data/{lib/devise → config}/locales/en.yml +16 -12
  23. data/lib/devise/controllers/helpers.rb +57 -52
  24. data/lib/devise/controllers/internal_helpers.rb +19 -50
  25. data/lib/devise/controllers/scoped_views.rb +35 -0
  26. data/lib/devise/controllers/url_helpers.rb +1 -1
  27. data/lib/devise/encryptors/authlogic_sha512.rb +0 -2
  28. data/lib/devise/encryptors/base.rb +1 -1
  29. data/lib/devise/encryptors/bcrypt.rb +2 -4
  30. data/lib/devise/encryptors/clearance_sha1.rb +0 -2
  31. data/lib/devise/encryptors/sha1.rb +6 -8
  32. data/lib/devise/encryptors/sha512.rb +6 -8
  33. data/lib/devise/failure_app.rb +76 -41
  34. data/lib/devise/hooks/activatable.rb +6 -10
  35. data/lib/devise/hooks/forgetable.rb +11 -0
  36. data/lib/devise/hooks/rememberable.rb +40 -30
  37. data/lib/devise/hooks/timeoutable.rb +7 -3
  38. data/lib/devise/hooks/trackable.rb +5 -14
  39. data/lib/devise/mapping.rb +35 -62
  40. data/lib/devise/models/authenticatable.rb +126 -0
  41. data/lib/devise/models/confirmable.rb +19 -22
  42. data/lib/devise/models/database_authenticatable.rb +26 -60
  43. data/lib/devise/models/lockable.rb +43 -28
  44. data/lib/devise/models/recoverable.rb +11 -10
  45. data/lib/devise/models/rememberable.rb +56 -26
  46. data/lib/devise/models/timeoutable.rb +1 -3
  47. data/lib/devise/models/token_authenticatable.rb +14 -43
  48. data/lib/devise/models/trackable.rb +14 -0
  49. data/lib/devise/models/validatable.rb +16 -2
  50. data/lib/devise/models.rb +16 -53
  51. data/lib/devise/modules.rb +23 -0
  52. data/lib/devise/orm/active_record.rb +10 -15
  53. data/lib/devise/orm/mongoid.rb +29 -0
  54. data/lib/devise/path_checker.rb +18 -0
  55. data/lib/devise/rails/routes.rb +232 -117
  56. data/lib/devise/rails/warden_compat.rb +17 -41
  57. data/lib/devise/rails.rb +64 -9
  58. data/lib/devise/schema.rb +47 -23
  59. data/lib/devise/strategies/authenticatable.rb +123 -0
  60. data/lib/devise/strategies/base.rb +2 -3
  61. data/lib/devise/strategies/database_authenticatable.rb +7 -22
  62. data/lib/devise/strategies/rememberable.rb +21 -7
  63. data/lib/devise/strategies/token_authenticatable.rb +31 -19
  64. data/lib/devise/test_helpers.rb +6 -6
  65. data/lib/devise/version.rb +1 -1
  66. data/lib/devise.rb +174 -157
  67. data/lib/generators/active_record/devise_generator.rb +28 -0
  68. data/{generators/devise → lib/generators/active_record}/templates/migration.rb +9 -3
  69. data/lib/generators/devise/devise_generator.rb +17 -0
  70. data/lib/generators/devise/install_generator.rb +24 -0
  71. data/lib/generators/devise/orm_helpers.rb +23 -0
  72. data/{generators/devise_install → lib/generators/devise}/templates/README +9 -7
  73. data/lib/generators/devise/templates/devise.rb +142 -0
  74. data/lib/generators/devise/views_generator.rb +63 -0
  75. data/lib/generators/devise_install_generator.rb +4 -0
  76. data/lib/generators/devise_views_generator.rb +4 -0
  77. data/lib/generators/mongoid/devise_generator.rb +17 -0
  78. data/test/controllers/helpers_test.rb +48 -19
  79. data/test/controllers/internal_helpers_test.rb +12 -16
  80. data/test/controllers/url_helpers_test.rb +21 -10
  81. data/test/devise_test.rb +16 -25
  82. data/test/encryptors_test.rb +2 -3
  83. data/test/failure_app_test.rb +106 -27
  84. data/test/integration/authenticatable_test.rb +135 -131
  85. data/test/integration/confirmable_test.rb +22 -15
  86. data/test/integration/database_authenticatable_test.rb +38 -0
  87. data/test/integration/http_authenticatable_test.rb +9 -12
  88. data/test/integration/lockable_test.rb +22 -15
  89. data/test/integration/recoverable_test.rb +6 -6
  90. data/test/integration/registerable_test.rb +42 -33
  91. data/test/integration/rememberable_test.rb +84 -22
  92. data/test/integration/timeoutable_test.rb +16 -4
  93. data/test/integration/token_authenticatable_test.rb +45 -12
  94. data/test/integration/trackable_test.rb +1 -1
  95. data/test/mailers/confirmation_instructions_test.rb +11 -17
  96. data/test/mailers/reset_password_instructions_test.rb +7 -7
  97. data/test/mailers/unlock_instructions_test.rb +7 -7
  98. data/test/mapping_test.rb +22 -95
  99. data/test/models/confirmable_test.rb +12 -19
  100. data/test/models/{authenticatable_test.rb → database_authenticatable_test.rb} +24 -56
  101. data/test/models/lockable_test.rb +32 -46
  102. data/test/models/recoverable_test.rb +7 -7
  103. data/test/models/rememberable_test.rb +118 -35
  104. data/test/models/timeoutable_test.rb +1 -1
  105. data/test/models/token_authenticatable_test.rb +5 -19
  106. data/test/models/trackable_test.rb +1 -1
  107. data/test/models/validatable_test.rb +20 -27
  108. data/test/models_test.rb +12 -5
  109. data/test/orm/active_record.rb +1 -23
  110. data/test/orm/mongoid.rb +10 -0
  111. data/test/rails_app/app/active_record/admin.rb +1 -5
  112. data/test/rails_app/app/active_record/shim.rb +2 -0
  113. data/test/rails_app/app/active_record/user.rb +3 -3
  114. data/test/rails_app/app/controllers/application_controller.rb +2 -5
  115. data/test/rails_app/app/controllers/home_controller.rb +3 -0
  116. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  117. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  118. data/test/rails_app/app/controllers/sessions_controller.rb +6 -0
  119. data/test/rails_app/app/controllers/users_controller.rb +7 -5
  120. data/test/rails_app/app/mongoid/admin.rb +6 -0
  121. data/test/rails_app/app/mongoid/shim.rb +16 -0
  122. data/test/rails_app/app/mongoid/user.rb +10 -0
  123. data/test/rails_app/config/application.rb +35 -0
  124. data/test/rails_app/config/boot.rb +10 -107
  125. data/test/rails_app/config/environment.rb +4 -41
  126. data/test/rails_app/config/environments/development.rb +15 -13
  127. data/test/rails_app/config/environments/production.rb +25 -20
  128. data/test/rails_app/config/environments/test.rb +33 -28
  129. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  130. data/test/rails_app/config/initializers/devise.rb +95 -38
  131. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  132. data/test/rails_app/config/routes.rb +47 -25
  133. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +27 -0
  134. data/test/rails_app/db/schema.rb +86 -0
  135. data/test/routes_test.rb +62 -47
  136. data/test/support/{assertions_helper.rb → assertions.rb} +2 -15
  137. data/test/support/{tests_helper.rb → helpers.rb} +18 -3
  138. data/test/support/{integration_tests_helper.rb → integration.rb} +24 -7
  139. data/test/support/webrat/integrations/rails.rb +32 -0
  140. data/test/test_helper.rb +11 -11
  141. data/test/test_helpers_test.rb +30 -15
  142. metadata +107 -66
  143. data/app/controllers/sessions_controller.rb +0 -42
  144. data/app/models/devise_mailer.rb +0 -68
  145. data/app/views/confirmations/new.html.erb +0 -12
  146. data/app/views/passwords/edit.html.erb +0 -16
  147. data/app/views/passwords/new.html.erb +0 -12
  148. data/app/views/registrations/edit.html.erb +0 -25
  149. data/app/views/registrations/new.html.erb +0 -17
  150. data/app/views/sessions/new.html.erb +0 -17
  151. data/app/views/shared/_devise_links.erb +0 -19
  152. data/app/views/unlocks/new.html.erb +0 -12
  153. data/generators/devise/USAGE +0 -5
  154. data/generators/devise/devise_generator.rb +0 -15
  155. data/generators/devise/lib/route_devise.rb +0 -32
  156. data/generators/devise/templates/model.rb +0 -9
  157. data/generators/devise_install/USAGE +0 -3
  158. data/generators/devise_install/devise_install_generator.rb +0 -15
  159. data/generators/devise_install/templates/devise.rb +0 -105
  160. data/generators/devise_views/USAGE +0 -3
  161. data/generators/devise_views/devise_views_generator.rb +0 -21
  162. data/lib/devise/models/activatable.rb +0 -16
  163. data/lib/devise/models/http_authenticatable.rb +0 -23
  164. data/lib/devise/orm/data_mapper.rb +0 -83
  165. data/lib/devise/orm/mongo_mapper.rb +0 -52
  166. data/lib/devise/strategies/http_authenticatable.rb +0 -59
  167. data/rails/init.rb +0 -2
  168. data/test/integration/rack_middleware_test.rb +0 -47
  169. data/test/orm/mongo_mapper.rb +0 -20
  170. data/test/rails_app/app/mongo_mapper/admin.rb +0 -13
  171. data/test/rails_app/app/mongo_mapper/user.rb +0 -14
  172. data/test/rails_app/config/initializers/new_rails_defaults.rb +0 -24
  173. data/test/rails_app/config/initializers/session_store.rb +0 -15
  174. /data/app/views/{devise_mailer → devise/mailer}/confirmation_instructions.html.erb +0 -0
  175. /data/app/views/{devise_mailer → devise/mailer}/reset_password_instructions.html.erb +0 -0
  176. /data/app/views/{devise_mailer → devise/mailer}/unlock_instructions.html.erb +0 -0
data/CHANGELOG.rdoc CHANGED
@@ -1,25 +1,72 @@
1
- == 1.0.11
1
+ == 1.1.0
2
+
3
+ * enhancements
4
+ * Rememberable module allows user to be remembered across browsers and is enabled by default (by github.com/trevorturk)
5
+ * Rememberable module allows you to activate the period the remember me token is extended (by github.com/trevorturk)
6
+ * devise_for can now be used together with scope method in routes but with a few limitations (check the documentation)
7
+ * Support `as` or `devise_scope` in the router to specify controller access scope
8
+ * HTTP Basic Auth can now be disabled/enabled for xhr(ajax) requests using http_authenticatable_on_xhr option (by github.com/pellja)
2
9
 
3
10
  * bug fix
4
- * Make sure xhr requests do not store urls for redirect
5
- * Squeeze break lines from cookies to avoid duplicated break lines
11
+ * Fix a bug in Devise::TestHelpers where current_user was returning a Response object for non active accounts
12
+ * Devise should respect script_name and path_info contracts
13
+ * Fix a bug when accessing a path with (.:format) (by github.com/klacointe)
14
+ * Do not add unlock routes unless unlock strategy is email or both
15
+ * Email should be case insensitive
16
+ * Store classes as string in session, to avoid serialization and stale data issues
17
+
18
+ * deprecations
19
+ * use_default_scope is deprecated and has no effect. Use :as or :devise_scope in the router instead
20
+
21
+ == 1.1.rc2
6
22
 
7
- == 1.0.10
23
+ * enhancements
24
+ * Allow to set cookie domain for the remember token. (by github.com/mantas)
25
+ * Added navigational formats to specify when it should return a 302 and when a 401.
26
+ * Added authenticate(scope) support in routes (by github.com/wildchild)
27
+ * Added after_update_path_for to registrations controller (by github.com/thedelchop)
28
+ * Allow the mailer object to be replaced through config.mailer = "MyOwnMailer"
8
29
 
9
30
  * bug fix
10
- * Use secure compare when comparing passwords
11
- * Improve email regexp
12
- * Implement handle_unverified_request for Rails 2.3.11
31
+ * Fix a bug where session was timing out on sign out
13
32
 
14
- == 1.0.9
33
+ * deprecations
34
+ * bcrypt is now the default encryptor
35
+ * devise.mailer.confirmations_instructions now should be devise.mailer.confirmations_instructions.subject
36
+ * devise.mailer.user.confirmations_instructions now should be devise.mailer.confirmations_instructions.user_subject
37
+ * Generators now use Rails 3 syntax (devise:install) instead of devise_install
38
+
39
+ == 1.1.rc1
15
40
 
16
41
  * enhancements
17
- * Extracted redirect path from Devise failure app to a new method, allowing override in custom failure apps
18
- * Added sign_out_via
42
+ * Rails 3 compatibility
43
+ * All controllers and views are namespaced, for example: Devise::SessionsController and "devise/sessions"
44
+ * Devise.orm is deprecated. This reduces the required API to hook your ORM with devise
45
+ * Use metal for failure app
46
+ * HTML e-mails now have proper formatting
47
+ * Allow to give :skip and :controllers in routes
48
+ * Move trackable logic to the model
49
+ * E-mails now use any template available in the filesystem. Easy to create multipart e-mails
50
+ * E-mails asks headers_for in the model to set the proper headers
51
+ * Allow to specify haml in devise_views
52
+ * Compatibility with Mongoid
53
+ * Make config.devise available on config/application.rb
54
+ * TokenAuthenticatable now works with HTTP Basic Auth
55
+ * Allow :unlock_strategy to be :none and add :lock_strategy which can be :failed_attempts or none. Setting those values to :none means that you want to handle lock and unlocking by yourself
56
+ * No need to append ?unauthenticated=true in URLs anymore since Flash was moved to a middleware in Rails 3
57
+ * :activatable is included by default in your models
19
58
 
20
59
  * bug fix
21
- * Email is now case insensitive
22
- * Avoid session fixation attacks
60
+ * Fix a bug with STI
61
+
62
+ * deprecations
63
+ * Rails 3 compatible only
64
+ * Removed support for MongoMapper
65
+ * Scoped views are no longer "sessions/users/new". Now use "users/sessions/new"
66
+ * Devise.orm is deprecated, just require "devise/orm/YOUR_ORM" instead
67
+ * Devise.default_url_options is deprecated, just modify ApplicationController.default_url_options
68
+ * All messages under devise.sessions, except :signed_in and :signed_out, should be moved to devise.failure
69
+ * :as and :scope in routes is deprecated. Use :path and :singular instead
23
70
 
24
71
  == 1.0.8
25
72
 
@@ -93,7 +140,6 @@
93
140
  * Added Http Basic Authentication support
94
141
  * Allow scoped_views to be customized per controller/mailer class
95
142
  * [#99] Allow authenticatable to used in change_table statements
96
- * Add mailer_content_type configuration parameter (by github.com/glennr)
97
143
 
98
144
  == 0.9.2
99
145
 
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ source "http://rubygems.org"
2
+
3
+ if File.exist? File.expand_path('../../rails', __FILE__)
4
+ gem "rails", :path => "../rails"
5
+ else
6
+ gem "rails", :git => "git://github.com/rails/rails.git"
7
+ end
8
+
9
+ gem "warden", "0.10.7"
10
+ gem "sqlite3-ruby"
11
+ gem "webrat", "0.7.0"
12
+ gem "mocha", :require => false
13
+ gem "bcrypt-ruby", :require => "bcrypt"
14
+
15
+ if RUBY_VERSION < '1.9'
16
+ gem "ruby-debug", ">= 0.10.3"
17
+ end
18
+
19
+ group :mongoid do
20
+ gem "mongo"
21
+ gem "mongoid", :git => "git://github.com/durran/mongoid.git"
22
+ gem "bson_ext"
23
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,118 @@
1
+ GIT
2
+ remote: git://github.com/durran/mongoid.git
3
+ revision: a5abe21
4
+ specs:
5
+ mongoid (2.0.0.beta9)
6
+ activemodel (~> 3.0.0.beta)
7
+ bson (~> 1.0.3)
8
+ mongo (~> 1.0.3)
9
+ tzinfo (~> 0.3.22)
10
+ will_paginate (~> 3.0.pre)
11
+
12
+ PATH
13
+ remote: /Users/jose/Work/github/rails
14
+ specs:
15
+ actionmailer (3.0.0.beta4)
16
+ actionpack (= 3.0.0.beta4)
17
+ mail (~> 2.2.5)
18
+ actionpack (3.0.0.beta4)
19
+ activemodel (= 3.0.0.beta4)
20
+ activesupport (= 3.0.0.beta4)
21
+ builder (~> 2.1.2)
22
+ erubis (~> 2.6.6)
23
+ i18n (~> 0.4.1)
24
+ rack (~> 1.2.1)
25
+ rack-mount (~> 0.6.9)
26
+ rack-test (~> 0.5.4)
27
+ tzinfo (~> 0.3.22)
28
+ activemodel (3.0.0.beta4)
29
+ activesupport (= 3.0.0.beta4)
30
+ builder (~> 2.1.2)
31
+ i18n (~> 0.4.1)
32
+ activerecord (3.0.0.beta4)
33
+ activemodel (= 3.0.0.beta4)
34
+ activesupport (= 3.0.0.beta4)
35
+ arel (~> 0.4.0)
36
+ tzinfo (~> 0.3.22)
37
+ activeresource (3.0.0.beta4)
38
+ activemodel (= 3.0.0.beta4)
39
+ activesupport (= 3.0.0.beta4)
40
+ activesupport (3.0.0.beta4)
41
+ rails (3.0.0.beta4)
42
+ actionmailer (= 3.0.0.beta4)
43
+ actionpack (= 3.0.0.beta4)
44
+ activerecord (= 3.0.0.beta4)
45
+ activeresource (= 3.0.0.beta4)
46
+ activesupport (= 3.0.0.beta4)
47
+ bundler (>= 1.0.0.beta.10)
48
+ railties (= 3.0.0.beta4)
49
+ railties (3.0.0.beta4)
50
+ actionpack (= 3.0.0.beta4)
51
+ activesupport (= 3.0.0.beta4)
52
+ rake (>= 0.8.3)
53
+ thor (~> 0.14.0)
54
+
55
+ GEM
56
+ remote: http://rubygems.org/
57
+ specs:
58
+ abstract (1.0.0)
59
+ arel (0.4.0)
60
+ activesupport (>= 3.0.0.beta)
61
+ bcrypt-ruby (2.1.2)
62
+ bson (1.0.4)
63
+ bson_ext (1.0.4)
64
+ builder (2.1.2)
65
+ columnize (0.3.1)
66
+ erubis (2.6.6)
67
+ abstract (>= 1.0.0)
68
+ i18n (0.4.1)
69
+ linecache (0.43)
70
+ mail (2.2.5)
71
+ activesupport (>= 2.3.6)
72
+ mime-types
73
+ treetop (>= 1.4.5)
74
+ mime-types (1.16)
75
+ mocha (0.9.8)
76
+ rake
77
+ mongo (1.0.5)
78
+ bson (>= 1.0.4)
79
+ nokogiri (1.4.2)
80
+ polyglot (0.3.1)
81
+ rack (1.2.1)
82
+ rack-mount (0.6.9)
83
+ rack (>= 1.0.0)
84
+ rack-test (0.5.4)
85
+ rack (>= 1.0)
86
+ rake (0.8.7)
87
+ ruby-debug (0.10.3)
88
+ columnize (>= 0.1)
89
+ ruby-debug-base (~> 0.10.3.0)
90
+ ruby-debug-base (0.10.3)
91
+ linecache (>= 0.3)
92
+ sqlite3-ruby (1.3.1)
93
+ thor (0.14.0)
94
+ treetop (1.4.8)
95
+ polyglot (>= 0.3.1)
96
+ tzinfo (0.3.22)
97
+ warden (0.10.7)
98
+ rack (>= 1.0.0)
99
+ webrat (0.7.0)
100
+ nokogiri (>= 1.2.0)
101
+ rack (>= 1.0)
102
+ rack-test (>= 0.5.3)
103
+ will_paginate (3.0.pre)
104
+
105
+ PLATFORMS
106
+ ruby
107
+
108
+ DEPENDENCIES
109
+ bcrypt-ruby
110
+ bson_ext
111
+ mocha
112
+ mongo
113
+ mongoid!
114
+ rails!
115
+ ruby-debug (>= 0.10.3)
116
+ sqlite3-ruby
117
+ warden (= 0.10.7)
118
+ webrat (= 0.7.0)
data/README.rdoc CHANGED
@@ -7,67 +7,82 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
7
7
  * Allows you to have multiple roles (or models/scopes) signed in at the same time;
8
8
  * Is based on a modularity concept: use just what you really need.
9
9
 
10
- Right now it's composed of 12 modules:
10
+ Right now it's composed of 11 modules:
11
+
12
+ * Database Authenticatable: encrypts and stores a password in the database to validate the authenticity of an user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
13
+ * Token Authenticatable: signs in an user based on an authentication token (also known as "single access token"). The token can be given both through query string or HTTP Basic Authentication.
14
+ * Confirmable: sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
15
+ * Recoverable: resets the user password and sends reset instructions.
16
+ * Registerable: handles signing up users through a registration process, also allowing them to edit and destroy their account.
17
+ * Rememberable: manages generating and clearing a token for remembering the user from a saved cookie.
18
+ * Trackable: tracks sign in count, timestamps and IP address.
19
+ * Timeoutable: expires sessions that have no activity in a specified period of time.
20
+ * Validatable: provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
21
+ * Lockable: locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
11
22
 
12
- * Database Authenticatable: responsible for encrypting password and validating authenticity of a user while signing in.
13
- * Token Authenticatable: validates authenticity of a user while signing in using an authentication token (also known as "single access token").
14
- * HttpAuthenticatable: sign in users using basic HTTP authentication.
15
- * Confirmable: responsible for verifying whether an account is already confirmed to sign in, and to send emails with confirmation instructions.
16
- * Recoverable: takes care of reseting the user password and send reset instructions.
17
- * Registerable: handles signing up users through a registration process.
18
- * Rememberable: manages generating and clearing token for remember the user from a saved cookie.
19
- * Trackable: tracks sign in count, timestamps and ip.
20
- * Timeoutable: expires sessions without activity in a certain period of time.
21
- * Validatable: creates all needed validations for email and password. It's totally optional, so you're able to to customize validations by yourself.
22
- * Lockable: takes care of locking an account based on the number of failed sign in attempts. Handles unlock via expire and email.
23
- * Activatable: if you need to activate accounts by other means, which are not through confirmation, use this module.
23
+ == Installation
24
24
 
25
- There's an example application using Devise at http://github.com/plataformatec/devise_example .
25
+ Devise 1.1 supports Rails 3 and is NOT backward compatible. You can use the latest Rails 3 beta gem with Devise latest gem:
26
26
 
27
- == Dependencies
27
+ gem install devise --version=1.1.rc2
28
28
 
29
- Devise is based on Warden (http://github.com/hassox/warden), a Rack Authentication Framework so you need to install it as a gem. Please ensure you have it installed in order to use devise (see installation below).
29
+ If you want to use Rails master (from git repository) you need to use Devise from git repository and vice-versa.
30
30
 
31
- == Installation
31
+ After you install Devise and add it to your Gemfile, you need to run the generator:
32
+
33
+ rails generate devise:install
34
+
35
+ The generator will install an initializer which describes ALL Devise's configuration options and you MUST take a look at it. When you are done, you are ready to add Devise to any of your models using the generator:
36
+
37
+ rails generate devise MODEL
38
+
39
+ Replace MODEL by the class name you want to add devise, like User, Admin, etc. This will create a model (if one does not exist) and configure it with default Devise modules. The generator will also create a migration file (if your ORM support them) and configure your routes. Continue reading this file to understand exactly what the generator produces and how to use it.
40
+
41
+ == Rails 2.3
32
42
 
33
- Install warden gem if you don't have it installed:
43
+ If you want to use the Rails 2.3.x version, you should do:
34
44
 
35
- gem install warden
45
+ gem install devise --version=1.0.8
36
46
 
37
- Install devise gem:
47
+ And please check the README at the v1.0 branch since this one is based on Rails 3:
38
48
 
39
- gem install devise --version=1.0.10
49
+ http://github.com/plataformatec/devise/tree/v1.0
40
50
 
41
- Configure warden and devise gems inside your app:
51
+ == Ecosystem
42
52
 
43
- config.gem 'warden'
44
- config.gem 'devise'
53
+ Devise ecosystem is growing solid day after day. If you just need a walkthrough about setting up Devise, this README will work great. But if you need more documentation and resources, please check both the wiki and rdoc:
45
54
 
46
- Run the generator:
55
+ * http://rdoc.info/projects/plataformatec/devise
56
+ * http://wiki.github.com/plataformatec/devise
47
57
 
48
- ruby script/generate devise_install
58
+ Both links above are for Devise with Rails 3. If you need to use Devise with Rails 2.3, you can always run `gem server` from the command line after you install the gem to access the old documentation.
49
59
 
50
- And you're ready to go. The generator will install an initializer which describes ALL Devise's configuration options, so be sure to take a look at it and the documentation as well:
60
+ Another great way to learn Devise are Ryan Bates' screencasts:
51
61
 
52
- http://rdoc.info/projects/plataformatec/devise
62
+ * http://railscasts.com/episodes/209-introducing-devise
63
+ * http://railscasts.com/episodes/210-customizing-devise
53
64
 
54
- If you want to use Devise with bundler on Rails 2.3, you need to follow the instructions here:
65
+ And a few example applications:
55
66
 
56
- http://github.com/carlhuda/bundler/issues/issue/83
67
+ * Rails 2.3 app using Devise at http://github.com/plataformatec/devise_example
68
+ * Rails 2.3 app using Devise with subdomains at http://github.com/fortuity/subdomain-authentication
69
+ * Rails 3.0 app with Mongoid at http://github.com/fortuity/rails3-mongoid-devise
70
+
71
+ Finally, Devise also has several extensions built by the community. Don't forget to check them at the end of this README. If you want to write an extension on your own, you should also check Warden (http://github.com/hassox/warden), a Rack Authentication Framework which Devise depends on.
57
72
 
58
73
  == Basic Usage
59
74
 
60
- This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration. You MUST also check out the *Generators* section below to help you start.
75
+ This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration.
61
76
 
62
- Devise must be set up within the model (or models) you want to use, and devise routes must be created inside your config/routes.rb file.
77
+ Devise must be set up within the model (or models) you want to use. Devise routes must be created inside your config/routes.rb file.
63
78
 
64
- We're assuming here you want a User model with some modules, as outlined below:
79
+ We're assuming here you want a User model with some Devise modules, as outlined below:
65
80
 
66
81
  class User < ActiveRecord::Base
67
82
  devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
68
83
  end
69
84
 
70
- After you choose which modules to use, you need to setup your migrations. Luckily, devise has some helpers to save you from this boring work:
85
+ After you choose which modules to use, you need to set up your migrations. Luckily, Devise has some helpers to save you from this boring work:
71
86
 
72
87
  create_table :users do |t|
73
88
  t.database_authenticatable
@@ -78,66 +93,67 @@ After you choose which modules to use, you need to setup your migrations. Luckil
78
93
  t.timestamps
79
94
  end
80
95
 
81
- Remember that Devise don't rely on _attr_accessible_ or _attr_protected_ inside its modules, so be sure to setup what attributes are accessible or protected in your model.
96
+ Devise doesn't use _attr_accessible_ or _attr_protected_ inside its modules, so be sure to define attributes as accessible or protected in your model.
82
97
 
83
- The next setup after setting up your model is to configure your routes. You do this by opening up your config/routes.rb and adding:
98
+ Configure your routes after setting up your model. Open your config/routes.rb file and add:
84
99
 
85
- map.devise_for :users
100
+ devise_for :users
86
101
 
87
- This is going to look inside you User model and create a set of needed routes (you can see them by running `rake routes`).
102
+ This will use your User model to create a set of needed routes (you can see them by running `rake routes`).
88
103
 
89
- There are also some options available for configuring your routes, as :class_name (to set the class for that route), :path_prefix, :as and :path_names, where the last two have the same meaning as in common routes. The available :path_names are:
104
+ Options for configuring your routes include :class_name (to set the class for that route), :path_prefix, :path and :path_names, where the last two have the same meaning as in common routes. The available :path_names are:
90
105
 
91
- map.devise_for :users, :as => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock' }
106
+ devise_for :users, :path => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
92
107
 
93
- Be sure to check devise_for documentation for detailed description.
108
+ Be sure to check devise_for documentation for details.
94
109
 
95
- After this steps, run your migrations, and you are ready to go! But don't finish reading, we still have a lot to tell you:
110
+ This exactly what the devise generator produces for you: model, routes and migrations. Don't forget to run rake db:migrate and you are ready to go! But don't stop reading here, we still have a lot to tell you.
96
111
 
97
112
  == Controller filters and helpers
98
113
 
99
- Devise is gonna create some helpers to use inside your controllers and views. To setup a controller that needs user authentication, just add this before_filter:
114
+ Devise will create some helpers to use inside your controllers and views. To set up a controller with user authentication, just add this before_filter:
100
115
 
101
116
  before_filter :authenticate_user!
102
117
 
103
- To verify if a user is signed in, you have the following helper:
118
+ To verify if a user is signed in, use the following helper:
104
119
 
105
120
  user_signed_in?
106
121
 
107
- And to get the current signed in user this helper is available:
122
+ For the current signed-in user, this helper is available:
108
123
 
109
124
  current_user
110
125
 
111
- You have also access to the session for this scope:
126
+ You can access the session for this scope:
112
127
 
113
128
  user_session
114
129
 
115
- After signing in a user, confirming it's account or updating it's password, devise will look for a scoped root path to redirect. Example: For a :user resource, it will use user_root_path if it exists, otherwise default root_path will be used. This means that you need to set the root inside your routes:
130
+ After signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect. Example: For a :user resource, it will use user_root_path if it exists, otherwise default root_path will be used. This means that you need to set the root inside your routes:
116
131
 
117
- map.root :controller => 'home'
132
+ root :to => "home"
118
133
 
119
- You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize better your redirect hooks.
134
+ You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize your redirect hooks.
120
135
 
121
- Finally, you also need to setup default url options for the mailer in each environment. Here's is the configuration for config/environments/development.rb:
136
+ Finally, you need to set up default url options for the mailer in each environment. Here is the configuration for config/environments/development.rb:
122
137
 
123
138
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
124
139
 
125
140
  == Tidying up
126
141
 
127
- Devise let's you setup as many roles as you want, so let's say you already have this User model and also want an Admin model with just authentication, trackable, lockable and timeoutable stuff and none of confirmation or password recovery. Just follow the same steps:
142
+ Devise allows you to set up as many roles as you want. For example, you may have a User model and also want an Admin model with just authentication, trackable, lockable and timeoutable features and no confirmation or password-recovery features. Just follow these steps:
128
143
 
129
144
  # Create a migration with the required fields
130
145
  create_table :admins do |t|
131
146
  t.database_authenticatable
132
147
  t.lockable
133
148
  t.trackable
149
+ t.timestamps
134
150
  end
135
151
 
136
152
  # Inside your Admin model
137
153
  devise :database_authenticatable, :trackable, :timeoutable, :lockable
138
154
 
139
155
  # Inside your routes
140
- map.devise_for :admin
156
+ devise_for :admins
141
157
 
142
158
  # Inside your protected controller
143
159
  before_filter :authenticate_admin!
@@ -147,41 +163,46 @@ Devise let's you setup as many roles as you want, so let's say you already have
147
163
  current_admin
148
164
  admin_session
149
165
 
150
- == Generators
166
+ == Model configuration
151
167
 
152
- Devise comes with some generators to help you start:
168
+ The devise method in your models also accepts some options to configure its modules. For example, you can choose which encryptor to use in database_authenticatable:
153
169
 
154
- ruby script/generate devise_install
170
+ devise :database_authenticatable, :confirmable, :recoverable, :encryptor => :bcrypt
155
171
 
156
- This will generate an initializer, with a description of all configuration values. You can also generate models through:
172
+ Besides :encryptor, you can define :pepper, :stretches, :confirm_within, :remember_for, :timeout_in, :unlock_in and other values. For details, see the initializer file that was created when you invoked the "devise:install" generator described above.
157
173
 
158
- ruby script/generate devise Model
174
+ == Configuring views
159
175
 
160
- A model configured with all devise modules and attr_accessible for default fields will be created. The generator will also create the migration and configure your routes for devise.
176
+ We built Devise to help you quickly develop an application that uses authentication. However, we don't want to be in your way when you need to customize it.
161
177
 
162
- == Model configuration
178
+ Since Devise is an engine, all its views are packaged inside the gem. These views will help you get started, but after sometime you may want to change them. If this is the case, you just need to invoke the following generator, and it will copy all views to your application:
163
179
 
164
- The devise method in your models also accept some options to configure its modules. For example, you can chose which encryptor to use in database_authenticatable:
180
+ rails generate devise:views
165
181
 
166
- devise :database_authenticatable, :confirmable, :recoverable, :encryptor => :bcrypt
182
+ However, if you have more than one role in your application (such as "User" and "Admin"), you will notice that Devise uses the same views for all roles. Fortunately, Devise offers an easy way to customize views. All you need to do is set "config.scoped_views = true" inside "config/initializers/devise.rb".
167
183
 
168
- Besides :encryptor, you can provide :pepper, :stretches, :confirm_within, :remember_for, :timeout_in, :unlock_in and others. All those are describer in the initializer created when you invoke the devise_install generator describer above.
184
+ After doing so, you will be able to have views based on the role like "users/sessions/new" and "admins/sessions/new". If no view is found within the scope, Devise will use the default view at "devise/sessions/new".
169
185
 
170
- == Views
186
+ == Configuring controllers
171
187
 
172
- Since devise is an engine, it has all default views inside the gem. They are good to get you started, but you will want to customize them at some point. And Devise has a generator to make copy them all to your application:
188
+ If the customization at the views level is not enough, you can customize each controller by following these steps:
173
189
 
174
- ruby script/generate devise_views
190
+ 1) Create your custom controller, for example a Admins::SessionsController:
175
191
 
176
- By default Devise will use the same views for all roles you have. But what if you need so different views to each of them? Devise also has an easy way to accomplish it: just setup config.scoped_views to true inside "config/initializers/devise.rb".
192
+ class Admins::SessionsController < Devise::SessionsController
193
+ end
177
194
 
178
- After doing so you will be able to have views based on the scope like 'sessions/users/new' and 'sessions/admin/new'. If no view is found within the scope, Devise will fallback to the default view.
195
+ 2) Tell the router to use this controller:
179
196
 
180
- Devise uses flash messages to let users know if their login is successful or not. Devise expects your application to call 'flash[:notice]' and 'flash[:alert]' as appropriate.
197
+ devise_for :admins, :controllers => { :sessions => "admin/sessions" }
198
+
199
+ 3) And since we changed the controller, it won't use the "devise/sessions" views, so remember to copy "devise/sessions" to "admin/sessions".
200
+
201
+ Remember that Devise uses flash messages to let users know if sign in was successful or failed. Devise expects your application to call "flash[:notice]" and "flash[:alert]" as appropriate.
181
202
 
182
203
  == I18n
183
204
 
184
- Devise uses flash messages with I18n with the flash keys :success and :failure. To customize your app, you can setup your locale file this way:
205
+ Devise uses flash messages with I18n with the flash keys :success and :failure. To customize your app, you can set up your locale file:
185
206
 
186
207
  en:
187
208
  devise:
@@ -198,7 +219,7 @@ You can also create distinct messages based on the resource you've configured us
198
219
  admin:
199
220
  signed_in: 'Hello admin!'
200
221
 
201
- Devise mailer uses the same pattern to create subject messages:
222
+ The Devise mailer uses the same pattern to create subject messages:
202
223
 
203
224
  en:
204
225
  devise:
@@ -226,15 +247,29 @@ You can include the Devise Test Helpers in all of your tests by adding the follo
226
247
  include Devise::TestHelpers
227
248
  end
228
249
 
229
- Do not use such helpers for integration tests like Cucumber, Webrat... Just fill in the form or explicitly set the user in session. For more tips, check the wiki (http://wiki.github.com/plataformatec/devise).
250
+ Do not use such helpers for integration tests such as Cucumber or Webrat. Instead, fill in the form or explicitly set the user in session. For more tips, check the wiki (http://wiki.github.com/plataformatec/devise).
230
251
 
231
252
  == Migrating from other solutions
232
253
 
233
- Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of it set the desired encryptor in the encryptor initializer config option. You might also need to rename your encrypted password and salt columns to match Devises's one (encrypted_password and password_salt).
254
+ Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of these strategies, set the desired encryptor in the encryptor initializer config option. You might also need to rename your encrypted password and salt columns to match Devise's fields (encrypted_password and password_salt).
234
255
 
235
256
  == Other ORMs
236
257
 
237
- Devise supports both ActiveRecord (default) and MongoMapper, and has experimental Datamapper supports (in a sense that Devise test suite does not run completely with Datamapper). To choose other ORM, you just need to configure it in the initializer file.
258
+ Devise supports ActiveRecord (by default) and Mongoid. We offer experimental Datamapper support (with the limitation that the Devise test suite does not run completely with Datamapper). To choose other ORM, you just need to configure it in the initializer file.
259
+
260
+ == Extensions
261
+
262
+ Devise also has extensions created by the community:
263
+
264
+ * http://github.com/scambra/devise_invitable adds support to Devise for sending invitations by email.
265
+
266
+ * http://github.com/grimen/devise_facebook_connectable adds support for Facebook Connect authentication, and optionally fetching user info from Facebook in the same step.
267
+
268
+ * http://github.com/joshk/devise_imapable adds support for imap based authentication, excellent for internal apps when an LDAP server isn't available.
269
+
270
+ * http://github.com/cschiewek/devise_ldap_authenticatable adds support for LDAP authentication via simple bind.
271
+
272
+ Please consult their respective documentation for more information and requirements.
238
273
 
239
274
  == TODO
240
275
 
@@ -257,16 +292,20 @@ Being able to reproduce the bug is the first step to fix it. Thanks for your und
257
292
 
258
293
  == Contributors
259
294
 
260
- We have a long running list of contributors. Check them all here:
295
+ We have a long list of valued contributors. Check them all at:
261
296
 
262
297
  http://github.com/plataformatec/devise/contributors
263
298
 
264
299
  == Bugs and Feedback
265
300
 
266
- If you discover any bugs or want to drop a line, feel free to create an issue on
267
- GitHub or send an e-mail to the mailing list.
301
+ If you discover any bugs, please create an issue on GitHub.
268
302
 
269
303
  http://github.com/plataformatec/devise/issues
304
+
305
+ For support, send an e-mail to the mailing list.
306
+
270
307
  http://groups.google.com/group/plataformatec-devise
271
308
 
272
- MIT License. Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br
309
+ == License
310
+
311
+ MIT License. Copyright 2010 Plataforma Tecnologia. http://blog.plataformatec.com.br
data/Rakefile CHANGED
@@ -43,8 +43,10 @@ begin
43
43
  s.homepage = "http://github.com/plataformatec/devise"
44
44
  s.description = "Flexible authentication solution for Rails with Warden"
45
45
  s.authors = ['José Valim', 'Carlos Antônio']
46
- s.files = FileList["[A-Z]*", "{app,config,generators,lib}/**/*", "rails/init.rb"]
47
- s.add_dependency("warden", "~> 0.10.3")
46
+ s.files = FileList["[A-Z]*", "{app,config,lib}/**/*"]
47
+ s.extra_rdoc_files = FileList["[A-Z]*"] - %w(Gemfile Rakefile)
48
+ s.add_dependency("warden", "~> 0.10.7")
49
+ s.add_dependency("bcrypt-ruby", "~> 2.1.2")
48
50
  end
49
51
 
50
52
  Jeweler::GemcutterTasks.new
data/TODO CHANGED
@@ -1,2 +1,3 @@
1
- * Make test run with DataMapper
2
- * Extract Activatable tests from Confirmable
1
+ * Move integration tests to Capybara
2
+ * Better ORM integration
3
+ * Extract activatable models tests from confirmable
@@ -1,4 +1,4 @@
1
- class ConfirmationsController < ApplicationController
1
+ class Devise::ConfirmationsController < ApplicationController
2
2
  include Devise::Controllers::InternalHelpers
3
3
 
4
4
  # GET /resource/confirmation/new
@@ -1,4 +1,4 @@
1
- class PasswordsController < ApplicationController
1
+ class Devise::PasswordsController < ApplicationController
2
2
  prepend_before_filter :require_no_authentication
3
3
  include Devise::Controllers::InternalHelpers
4
4