devise_ennder 1.0.1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. data/CHANGELOG.rdoc +397 -0
  2. data/INSTALL +94 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +272 -0
  5. data/Rakefile +53 -0
  6. data/TODO +2 -0
  7. data/app/controllers/confirmations_controller.rb +33 -0
  8. data/app/controllers/passwords_controller.rb +41 -0
  9. data/app/controllers/registrations_controller.rb +62 -0
  10. data/app/controllers/sessions_controller.rb +42 -0
  11. data/app/controllers/unlocks_controller.rb +41 -0
  12. data/app/models/devise_mailer.rb +68 -0
  13. data/app/models/user.rb +9 -0
  14. data/app/views/confirmations/new.html.erb +14 -0
  15. data/app/views/devise_mailer/confirmation_instructions.html.erb +6 -0
  16. data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
  17. data/app/views/devise_mailer/unlock_instructions.html.erb +7 -0
  18. data/app/views/passwords/edit.html.erb +16 -0
  19. data/app/views/passwords/new.html.erb +12 -0
  20. data/app/views/registrations/edit.html.erb +25 -0
  21. data/app/views/registrations/new.html.erb +17 -0
  22. data/app/views/sessions/new.html.erb +17 -0
  23. data/app/views/shared/_devise_links.erb +19 -0
  24. data/app/views/shared/_user_nav.html.erb +15 -0
  25. data/app/views/unlocks/new.html.erb +12 -0
  26. data/config/locales/devise.en.yml +62 -0
  27. data/config/locales/devise.fr.yml +60 -0
  28. data/config/locales/en.yml +6 -0
  29. data/config/locales/fr.yml +18 -0
  30. data/config/routes.rb +4 -0
  31. data/db/migrate/20100506013336_devise_create_users.rb +23 -0
  32. data/lib/devise/controllers/helpers.rb +212 -0
  33. data/lib/devise/controllers/internal_helpers.rb +129 -0
  34. data/lib/devise/controllers/url_helpers.rb +41 -0
  35. data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
  36. data/lib/devise/encryptors/base.rb +20 -0
  37. data/lib/devise/encryptors/bcrypt.rb +21 -0
  38. data/lib/devise/encryptors/clearance_sha1.rb +19 -0
  39. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  40. data/lib/devise/encryptors/sha1.rb +27 -0
  41. data/lib/devise/encryptors/sha512.rb +27 -0
  42. data/lib/devise/failure_app.rb +70 -0
  43. data/lib/devise/hooks/activatable.rb +15 -0
  44. data/lib/devise/hooks/rememberable.rb +33 -0
  45. data/lib/devise/hooks/timeoutable.rb +18 -0
  46. data/lib/devise/hooks/trackable.rb +18 -0
  47. data/lib/devise/locales/en.yml +35 -0
  48. data/lib/devise/mapping.rb +130 -0
  49. data/lib/devise/models/activatable.rb +16 -0
  50. data/lib/devise/models/confirmable.rb +167 -0
  51. data/lib/devise/models/database_authenticatable.rb +144 -0
  52. data/lib/devise/models/http_authenticatable.rb +23 -0
  53. data/lib/devise/models/lockable.rb +150 -0
  54. data/lib/devise/models/recoverable.rb +80 -0
  55. data/lib/devise/models/registerable.rb +8 -0
  56. data/lib/devise/models/rememberable.rb +92 -0
  57. data/lib/devise/models/timeoutable.rb +28 -0
  58. data/lib/devise/models/token_authenticatable.rb +89 -0
  59. data/lib/devise/models/trackable.rb +16 -0
  60. data/lib/devise/models/validatable.rb +39 -0
  61. data/lib/devise/models.rb +117 -0
  62. data/lib/devise/orm/active_record.rb +41 -0
  63. data/lib/devise/orm/data_mapper.rb +83 -0
  64. data/lib/devise/orm/mongo_mapper.rb +52 -0
  65. data/lib/devise/rails/routes.rb +133 -0
  66. data/lib/devise/rails/warden_compat.rb +60 -0
  67. data/lib/devise/rails.rb +14 -0
  68. data/lib/devise/schema.rb +73 -0
  69. data/lib/devise/strategies/base.rb +16 -0
  70. data/lib/devise/strategies/database_authenticatable.rb +36 -0
  71. data/lib/devise/strategies/http_authenticatable.rb +59 -0
  72. data/lib/devise/strategies/rememberable.rb +37 -0
  73. data/lib/devise/strategies/token_authenticatable.rb +37 -0
  74. data/lib/devise/test_helpers.rb +90 -0
  75. data/lib/devise/version.rb +3 -0
  76. data/lib/devise.rb +269 -0
  77. data/lib/devise_ennder.rb +3 -0
  78. data/lib/tasks/devise_ennder_tasks.rake +11 -0
  79. data/test/controllers/helpers_test.rb +184 -0
  80. data/test/controllers/internal_helpers_test.rb +55 -0
  81. data/test/controllers/url_helpers_test.rb +47 -0
  82. data/test/devise_test.rb +74 -0
  83. data/test/encryptors_test.rb +31 -0
  84. data/test/failure_app_test.rb +44 -0
  85. data/test/integration/authenticatable_test.rb +332 -0
  86. data/test/integration/confirmable_test.rb +97 -0
  87. data/test/integration/http_authenticatable_test.rb +52 -0
  88. data/test/integration/lockable_test.rb +102 -0
  89. data/test/integration/rack_middleware_test.rb +47 -0
  90. data/test/integration/recoverable_test.rb +141 -0
  91. data/test/integration/registerable_test.rb +144 -0
  92. data/test/integration/rememberable_test.rb +72 -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 +86 -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 +158 -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 +70 -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 +12 -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 +13 -0
  120. data/test/rails_app/app/mongo_mapper/user.rb +14 -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 +25 -0
  131. data/test/rails_app/vendor/plugins/devise/app/controllers/confirmations_controller.rb +33 -0
  132. data/test/rails_app/vendor/plugins/devise/app/controllers/passwords_controller.rb +41 -0
  133. data/test/rails_app/vendor/plugins/devise/app/controllers/registrations_controller.rb +53 -0
  134. data/test/rails_app/vendor/plugins/devise/app/controllers/sessions_controller.rb +42 -0
  135. data/test/rails_app/vendor/plugins/devise/app/controllers/unlocks_controller.rb +41 -0
  136. data/test/rails_app/vendor/plugins/devise/app/models/devise_mailer.rb +68 -0
  137. data/test/rails_app/vendor/plugins/devise/generators/devise/devise_generator.rb +15 -0
  138. data/test/rails_app/vendor/plugins/devise/generators/devise/lib/route_devise.rb +32 -0
  139. data/test/rails_app/vendor/plugins/devise/generators/devise/templates/migration.rb +23 -0
  140. data/test/rails_app/vendor/plugins/devise/generators/devise/templates/model.rb +9 -0
  141. data/test/rails_app/vendor/plugins/devise/generators/devise_install/devise_install_generator.rb +15 -0
  142. data/test/rails_app/vendor/plugins/devise/generators/devise_install/templates/devise.rb +105 -0
  143. data/test/rails_app/vendor/plugins/devise/generators/devise_views/devise_views_generator.rb +21 -0
  144. data/test/rails_app/vendor/plugins/devise/lib/devise/controllers/helpers.rb +212 -0
  145. data/test/rails_app/vendor/plugins/devise/lib/devise/controllers/internal_helpers.rb +129 -0
  146. data/test/rails_app/vendor/plugins/devise/lib/devise/controllers/url_helpers.rb +41 -0
  147. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/authlogic_sha512.rb +21 -0
  148. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/base.rb +20 -0
  149. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/bcrypt.rb +21 -0
  150. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/clearance_sha1.rb +19 -0
  151. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  152. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/sha1.rb +27 -0
  153. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/sha512.rb +27 -0
  154. data/test/rails_app/vendor/plugins/devise/lib/devise/failure_app.rb +70 -0
  155. data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/activatable.rb +15 -0
  156. data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/rememberable.rb +33 -0
  157. data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/timeoutable.rb +18 -0
  158. data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/trackable.rb +18 -0
  159. data/test/rails_app/vendor/plugins/devise/lib/devise/mapping.rb +130 -0
  160. data/test/rails_app/vendor/plugins/devise/lib/devise/models/activatable.rb +16 -0
  161. data/test/rails_app/vendor/plugins/devise/lib/devise/models/confirmable.rb +167 -0
  162. data/test/rails_app/vendor/plugins/devise/lib/devise/models/database_authenticatable.rb +144 -0
  163. data/test/rails_app/vendor/plugins/devise/lib/devise/models/http_authenticatable.rb +23 -0
  164. data/test/rails_app/vendor/plugins/devise/lib/devise/models/lockable.rb +150 -0
  165. data/test/rails_app/vendor/plugins/devise/lib/devise/models/recoverable.rb +80 -0
  166. data/test/rails_app/vendor/plugins/devise/lib/devise/models/registerable.rb +8 -0
  167. data/test/rails_app/vendor/plugins/devise/lib/devise/models/rememberable.rb +92 -0
  168. data/test/rails_app/vendor/plugins/devise/lib/devise/models/timeoutable.rb +28 -0
  169. data/test/rails_app/vendor/plugins/devise/lib/devise/models/token_authenticatable.rb +89 -0
  170. data/test/rails_app/vendor/plugins/devise/lib/devise/models/trackable.rb +16 -0
  171. data/test/rails_app/vendor/plugins/devise/lib/devise/models/validatable.rb +39 -0
  172. data/test/rails_app/vendor/plugins/devise/lib/devise/models.rb +117 -0
  173. data/test/rails_app/vendor/plugins/devise/lib/devise/orm/active_record.rb +41 -0
  174. data/test/rails_app/vendor/plugins/devise/lib/devise/orm/data_mapper.rb +83 -0
  175. data/test/rails_app/vendor/plugins/devise/lib/devise/orm/mongo_mapper.rb +52 -0
  176. data/test/rails_app/vendor/plugins/devise/lib/devise/rails/routes.rb +133 -0
  177. data/test/rails_app/vendor/plugins/devise/lib/devise/rails/warden_compat.rb +60 -0
  178. data/test/rails_app/vendor/plugins/devise/lib/devise/rails.rb +14 -0
  179. data/test/rails_app/vendor/plugins/devise/lib/devise/schema.rb +73 -0
  180. data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/base.rb +16 -0
  181. data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/database_authenticatable.rb +36 -0
  182. data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/http_authenticatable.rb +59 -0
  183. data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/rememberable.rb +37 -0
  184. data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/token_authenticatable.rb +37 -0
  185. data/test/rails_app/vendor/plugins/devise/lib/devise/test_helpers.rb +90 -0
  186. data/test/rails_app/vendor/plugins/devise/lib/devise/version.rb +3 -0
  187. data/test/rails_app/vendor/plugins/devise/lib/devise.rb +266 -0
  188. data/test/rails_app/vendor/plugins/devise/rails/init.rb +2 -0
  189. data/test/rails_app/vendor/plugins/devise/test/controllers/helpers_test.rb +184 -0
  190. data/test/rails_app/vendor/plugins/devise/test/controllers/internal_helpers_test.rb +55 -0
  191. data/test/rails_app/vendor/plugins/devise/test/controllers/url_helpers_test.rb +47 -0
  192. data/test/rails_app/vendor/plugins/devise/test/devise_test.rb +74 -0
  193. data/test/rails_app/vendor/plugins/devise/test/encryptors_test.rb +31 -0
  194. data/test/rails_app/vendor/plugins/devise/test/failure_app_test.rb +44 -0
  195. data/test/rails_app/vendor/plugins/devise/test/integration/authenticatable_test.rb +332 -0
  196. data/test/rails_app/vendor/plugins/devise/test/integration/confirmable_test.rb +97 -0
  197. data/test/rails_app/vendor/plugins/devise/test/integration/http_authenticatable_test.rb +52 -0
  198. data/test/rails_app/vendor/plugins/devise/test/integration/lockable_test.rb +102 -0
  199. data/test/rails_app/vendor/plugins/devise/test/integration/rack_middleware_test.rb +47 -0
  200. data/test/rails_app/vendor/plugins/devise/test/integration/recoverable_test.rb +141 -0
  201. data/test/rails_app/vendor/plugins/devise/test/integration/registerable_test.rb +144 -0
  202. data/test/rails_app/vendor/plugins/devise/test/integration/rememberable_test.rb +72 -0
  203. data/test/rails_app/vendor/plugins/devise/test/integration/timeoutable_test.rb +68 -0
  204. data/test/rails_app/vendor/plugins/devise/test/integration/token_authenticatable_test.rb +55 -0
  205. data/test/rails_app/vendor/plugins/devise/test/integration/trackable_test.rb +64 -0
  206. data/test/rails_app/vendor/plugins/devise/test/mailers/confirmation_instructions_test.rb +86 -0
  207. data/test/rails_app/vendor/plugins/devise/test/mailers/reset_password_instructions_test.rb +68 -0
  208. data/test/rails_app/vendor/plugins/devise/test/mailers/unlock_instructions_test.rb +62 -0
  209. data/test/rails_app/vendor/plugins/devise/test/mapping_test.rb +158 -0
  210. data/test/rails_app/vendor/plugins/devise/test/models/authenticatable_test.rb +180 -0
  211. data/test/rails_app/vendor/plugins/devise/test/models/confirmable_test.rb +228 -0
  212. data/test/rails_app/vendor/plugins/devise/test/models/lockable_test.rb +202 -0
  213. data/test/rails_app/vendor/plugins/devise/test/models/recoverable_test.rb +138 -0
  214. data/test/rails_app/vendor/plugins/devise/test/models/rememberable_test.rb +135 -0
  215. data/test/rails_app/vendor/plugins/devise/test/models/timeoutable_test.rb +28 -0
  216. data/test/rails_app/vendor/plugins/devise/test/models/token_authenticatable_test.rb +51 -0
  217. data/test/rails_app/vendor/plugins/devise/test/models/trackable_test.rb +5 -0
  218. data/test/rails_app/vendor/plugins/devise/test/models/validatable_test.rb +106 -0
  219. data/test/rails_app/vendor/plugins/devise/test/models_test.rb +70 -0
  220. data/test/rails_app/vendor/plugins/devise/test/orm/active_record.rb +31 -0
  221. data/test/rails_app/vendor/plugins/devise/test/orm/mongo_mapper.rb +20 -0
  222. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/active_record/admin.rb +7 -0
  223. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/active_record/user.rb +7 -0
  224. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/admins_controller.rb +6 -0
  225. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/application_controller.rb +12 -0
  226. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/home_controller.rb +4 -0
  227. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/users_controller.rb +16 -0
  228. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/helpers/application_helper.rb +3 -0
  229. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/mongo_mapper/admin.rb +13 -0
  230. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/mongo_mapper/user.rb +14 -0
  231. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/boot.rb +110 -0
  232. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environment.rb +42 -0
  233. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environments/development.rb +17 -0
  234. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environments/production.rb +28 -0
  235. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environments/test.rb +28 -0
  236. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/devise.rb +82 -0
  237. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/inflections.rb +2 -0
  238. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
  239. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/session_store.rb +15 -0
  240. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/routes.rb +25 -0
  241. data/test/rails_app/vendor/plugins/devise/test/routes_test.rb +131 -0
  242. data/test/rails_app/vendor/plugins/devise/test/support/assertions_helper.rb +37 -0
  243. data/test/rails_app/vendor/plugins/devise/test/support/integration_tests_helper.rb +71 -0
  244. data/test/rails_app/vendor/plugins/devise/test/support/test_silencer.rb +5 -0
  245. data/test/rails_app/vendor/plugins/devise/test/support/tests_helper.rb +39 -0
  246. data/test/rails_app/vendor/plugins/devise/test/test_helper.rb +21 -0
  247. data/test/rails_app/vendor/plugins/devise/test/test_helpers_test.rb +57 -0
  248. data/test/routes_test.rb +131 -0
  249. data/test/support/assertions_helper.rb +37 -0
  250. data/test/support/integration_tests_helper.rb +71 -0
  251. data/test/support/test_silencer.rb +5 -0
  252. data/test/support/tests_helper.rb +39 -0
  253. data/test/test_helper.rb +21 -0
  254. data/test/test_helpers_test.rb +57 -0
  255. metadata +515 -0
data/README.rdoc ADDED
@@ -0,0 +1,272 @@
1
+ == Devise
2
+
3
+ Devise is a flexible authentication solution for Rails based on Warden. It:
4
+
5
+ * Is Rack based;
6
+ * Is a complete MVC solution based on Rails engines;
7
+ * Allows you to have multiple roles (or models/scopes) signed in at the same time;
8
+ * Is based on a modularity concept: use just what you really need.
9
+
10
+ Right now it's composed of 12 modules:
11
+
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.
24
+
25
+ There's an example application using Devise at http://github.com/plataformatec/devise_example .
26
+
27
+ == Dependencies
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).
30
+
31
+ == Installation
32
+
33
+ Install warden gem if you don't have it installed:
34
+
35
+ gem install warden
36
+
37
+ Install devise gem:
38
+
39
+ gem install devise --version=1.0.9
40
+
41
+ Configure warden and devise gems inside your app:
42
+
43
+ config.gem 'warden'
44
+ config.gem 'devise'
45
+
46
+ Run the generator:
47
+
48
+ ruby script/generate devise_install
49
+
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:
51
+
52
+ http://rdoc.info/projects/plataformatec/devise
53
+
54
+ If you want to use Devise with bundler on Rails 2.3, you need to follow the instructions here:
55
+
56
+ http://github.com/carlhuda/bundler/issues/issue/83
57
+
58
+ == Basic Usage
59
+
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.
61
+
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.
63
+
64
+ We're assuming here you want a User model with some modules, as outlined below:
65
+
66
+ class User < ActiveRecord::Base
67
+ devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
68
+ end
69
+
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:
71
+
72
+ create_table :users do |t|
73
+ t.database_authenticatable
74
+ t.confirmable
75
+ t.recoverable
76
+ t.rememberable
77
+ t.trackable
78
+ t.timestamps
79
+ end
80
+
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.
82
+
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:
84
+
85
+ map.devise_for :users
86
+
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`).
88
+
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:
90
+
91
+ map.devise_for :users, :as => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock' }
92
+
93
+ Be sure to check devise_for documentation for detailed description.
94
+
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:
96
+
97
+ == Controller filters and helpers
98
+
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:
100
+
101
+ before_filter :authenticate_user!
102
+
103
+ To verify if a user is signed in, you have the following helper:
104
+
105
+ user_signed_in?
106
+
107
+ And to get the current signed in user this helper is available:
108
+
109
+ current_user
110
+
111
+ You have also access to the session for this scope:
112
+
113
+ user_session
114
+
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:
116
+
117
+ map.root :controller => 'home'
118
+
119
+ You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize better your redirect hooks.
120
+
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:
122
+
123
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
124
+
125
+ == Tidying up
126
+
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:
128
+
129
+ # Create a migration with the required fields
130
+ create_table :admins do |t|
131
+ t.database_authenticatable
132
+ t.lockable
133
+ t.trackable
134
+ end
135
+
136
+ # Inside your Admin model
137
+ devise :database_authenticatable, :trackable, :timeoutable, :lockable
138
+
139
+ # Inside your routes
140
+ map.devise_for :admin
141
+
142
+ # Inside your protected controller
143
+ before_filter :authenticate_admin!
144
+
145
+ # Inside your controllers and views
146
+ admin_signed_in?
147
+ current_admin
148
+ admin_session
149
+
150
+ == Generators
151
+
152
+ Devise comes with some generators to help you start:
153
+
154
+ ruby script/generate devise_install
155
+
156
+ This will generate an initializer, with a description of all configuration values. You can also generate models through:
157
+
158
+ ruby script/generate devise Model
159
+
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.
161
+
162
+ == Model configuration
163
+
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:
165
+
166
+ devise :database_authenticatable, :confirmable, :recoverable, :encryptor => :bcrypt
167
+
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.
169
+
170
+ == Views
171
+
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:
173
+
174
+ ruby script/generate devise_views
175
+
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".
177
+
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.
179
+
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.
181
+
182
+ == I18n
183
+
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:
185
+
186
+ en:
187
+ devise:
188
+ sessions:
189
+ signed_in: 'Signed in successfully.'
190
+
191
+ You can also create distinct messages based on the resource you've configured using the singular name given in routes:
192
+
193
+ en:
194
+ devise:
195
+ sessions:
196
+ user:
197
+ signed_in: 'Welcome user, you are signed in.'
198
+ admin:
199
+ signed_in: 'Hello admin!'
200
+
201
+ Devise mailer uses the same pattern to create subject messages:
202
+
203
+ en:
204
+ devise:
205
+ mailer:
206
+ confirmation_instructions: 'Hello everybody!'
207
+ user:
208
+ confirmation_instructions: 'Hello User! Please confirm your email'
209
+ reset_password_instructions: 'Reset instructions'
210
+
211
+ Take a look at our locale file to check all available messages.
212
+
213
+ == Test helpers
214
+
215
+ Devise includes some tests helpers for functional specs. To use them, you just need to include Devise::TestHelpers in your test class and use the sign_in and sign_out method. Such methods have the same signature as in controllers:
216
+
217
+ sign_in :user, @user # sign_in(scope, resource)
218
+ sign_in @user # sign_in(resource)
219
+
220
+ sign_out :user # sign_out(scope)
221
+ sign_out @user # sign_out(resource)
222
+
223
+ You can include the Devise Test Helpers in all of your tests by adding the following to the bottom of your test/test_helper.rb or spec/spec_helper.rb file:
224
+
225
+ class ActionController::TestCase
226
+ include Devise::TestHelpers
227
+ end
228
+
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).
230
+
231
+ == Migrating from other solutions
232
+
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).
234
+
235
+ == Other ORMs
236
+
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.
238
+
239
+ == TODO
240
+
241
+ Please refer to TODO file.
242
+
243
+ == Security
244
+
245
+ Needless to say, security is extremely important to Devise. If you find yourself in a possible security issue with Devise, please go through the following steps, trying to reproduce the bug:
246
+
247
+ 1) Look at the source code a bit to find out whether your assumptions are correct;
248
+ 2) If possible, provide a way to reproduce the bug: a small app on Github or a step-by-step to reproduce;
249
+ 3) E-mail us or send a Github private message instead of using the normal issues;
250
+
251
+ Being able to reproduce the bug is the first step to fix it. Thanks for your understanding.
252
+
253
+ == Maintainers
254
+
255
+ * José Valim (http://github.com/josevalim)
256
+ * Carlos Antônio da Silva (http://github.com/carlosantoniodasilva)
257
+
258
+ == Contributors
259
+
260
+ We have a long running list of contributors. Check them all here:
261
+
262
+ http://github.com/plataformatec/devise/contributors
263
+
264
+ == Bugs and Feedback
265
+
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.
268
+
269
+ http://github.com/plataformatec/devise/issues
270
+ http://groups.google.com/group/plataformatec-devise
271
+
272
+ MIT License. Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require 'rake/rdoctask'
6
+ require File.join(File.dirname(__FILE__), 'lib', 'devise', 'version')
7
+
8
+ desc 'Default: run tests for all ORMs.'
9
+ task :default => :pre_commit
10
+
11
+ desc 'Run Devise tests for all ORMs.'
12
+ task :pre_commit do
13
+ Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file|
14
+ orm = File.basename(file).split(".").first
15
+ system "rake test DEVISE_ORM=#{orm}"
16
+ end
17
+ end
18
+
19
+ desc 'Run Devise unit tests.'
20
+ Rake::TestTask.new(:test) do |t|
21
+ t.libs << 'lib'
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = true
25
+ end
26
+
27
+ desc 'Generate documentation for Devise.'
28
+ Rake::RDocTask.new(:rdoc) do |rdoc|
29
+ rdoc.rdoc_dir = 'rdoc'
30
+ rdoc.title = 'Devise'
31
+ rdoc.options << '--line-numbers' << '--inline-source'
32
+ rdoc.rdoc_files.include('README.rdoc')
33
+ rdoc.rdoc_files.include('lib/**/*.rb')
34
+ end
35
+
36
+ begin
37
+ require 'jeweler'
38
+ Jeweler::Tasks.new do |s|
39
+ s.name = "devise_ennder"
40
+ s.version = '1.0.' + Devise::VERSION.dup
41
+ s.summary = "Flexible authentication solution for Rails with Warden, translated in FR"
42
+ s.email = "mel@ennder.fr"
43
+ s.homepage = "http://homo-agilis.ennder.fr"
44
+ s.description = "Flexible authentication solution for Rails with Warden, translated in FR by Ennder"
45
+ s.authors = ['José VALIM', 'Carlos ANTÔNIO', 'Jérôme BATAILLE']
46
+ s.files = FileList["[A-Z]*", "{app,config,db,lib}/**/*", "rails/init.rb"]
47
+ s.add_dependency("warden", "~> 0.10.7")
48
+ end
49
+
50
+ Jeweler::GemcutterTasks.new
51
+ rescue LoadError
52
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
53
+ end
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ * Make test run with DataMapper
2
+ * Extract Activatable tests from Confirmable
@@ -0,0 +1,33 @@
1
+ class ConfirmationsController < ApplicationController
2
+ include Devise::Controllers::InternalHelpers
3
+
4
+ # GET /resource/confirmation/new
5
+ def new
6
+ build_resource
7
+ render_with_scope :new
8
+ end
9
+
10
+ # POST /resource/confirmation
11
+ def create
12
+ self.resource = resource_class.send_confirmation_instructions(params[resource_name])
13
+
14
+ if resource.errors.empty?
15
+ set_flash_message :notice, :send_instructions
16
+ redirect_to new_session_path(resource_name)
17
+ else
18
+ render_with_scope :new
19
+ end
20
+ end
21
+
22
+ # GET /resource/confirmation?confirmation_token=abcdef
23
+ def show
24
+ self.resource = resource_class.confirm_by_token(params[:confirmation_token])
25
+
26
+ if resource.errors.empty?
27
+ set_flash_message :notice, :confirmed
28
+ sign_in_and_redirect(resource_name, resource)
29
+ else
30
+ render_with_scope :new
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,41 @@
1
+ class PasswordsController < ApplicationController
2
+ prepend_before_filter :require_no_authentication
3
+ include Devise::Controllers::InternalHelpers
4
+
5
+ # GET /resource/password/new
6
+ def new
7
+ build_resource
8
+ render_with_scope :new
9
+ end
10
+
11
+ # POST /resource/password
12
+ def create
13
+ self.resource = resource_class.send_reset_password_instructions(params[resource_name])
14
+
15
+ if resource.errors.empty?
16
+ set_flash_message :notice, :send_instructions
17
+ redirect_to new_session_path(resource_name)
18
+ else
19
+ render_with_scope :new
20
+ end
21
+ end
22
+
23
+ # GET /resource/password/edit?reset_password_token=abcdef
24
+ def edit
25
+ self.resource = resource_class.new
26
+ resource.reset_password_token = params[:reset_password_token]
27
+ render_with_scope :edit
28
+ end
29
+
30
+ # PUT /resource/password
31
+ def update
32
+ self.resource = resource_class.reset_password_by_token(params[resource_name])
33
+
34
+ if resource.errors.empty?
35
+ set_flash_message :notice, :updated
36
+ sign_in_and_redirect(resource_name, resource)
37
+ else
38
+ render_with_scope :edit
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,62 @@
1
+ class RegistrationsController < ApplicationController
2
+ prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
3
+ prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
4
+ include Devise::Controllers::InternalHelpers
5
+
6
+ # GET /resource/sign_in
7
+ def new
8
+ build_resource
9
+ render_with_scope :new
10
+ end
11
+
12
+ # POST /resource/sign_up
13
+ def create
14
+ build_resource
15
+
16
+ if resource.save
17
+ set_flash_message :notice, :signed_up
18
+ sign_in_and_redirect(resource_name, resource)
19
+ else
20
+ render_with_scope :new
21
+ end
22
+ end
23
+
24
+ # GET /resource/edit
25
+ def edit
26
+ render_with_scope :edit
27
+ end
28
+
29
+ # PUT /resource
30
+ def update
31
+ if self.resource.update_with_password(params[resource_name])
32
+ set_flash_message :notice, :updated
33
+ redirect_to after_sign_in_path_for(self.resource)
34
+ else
35
+ render_with_scope :edit
36
+ end
37
+ end
38
+
39
+ # DELETE /resource
40
+ def destroy
41
+ begin
42
+ self.resource.destroy
43
+ rescue Exception => exception
44
+ #Ennder 2010-11
45
+ #New message
46
+ set_flash_message :error, t('devise.sessions.Could_not_destroy_resource') + ': ' + exception.message
47
+ render_with_scope :edit
48
+ return
49
+ end
50
+
51
+ set_flash_message :notice, :destroyed
52
+ sign_out_and_redirect(self.resource)
53
+ end
54
+
55
+ protected
56
+
57
+ # Authenticates the current scope and dup the resource
58
+ def authenticate_scope!
59
+ send(:"authenticate_#{resource_name}!")
60
+ self.resource = send(:"current_#{resource_name}").dup
61
+ end
62
+ end
@@ -0,0 +1,42 @@
1
+ class SessionsController < ApplicationController
2
+ prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
3
+ include Devise::Controllers::InternalHelpers
4
+
5
+ # GET /resource/sign_in
6
+ def new
7
+ unless flash[:notice].present?
8
+ Devise::FLASH_MESSAGES.each do |message|
9
+ set_now_flash_message :alert, message if params.try(:[], message) == "true"
10
+ end
11
+ end
12
+
13
+ build_resource
14
+ render_with_scope :new
15
+ end
16
+
17
+ # POST /resource/sign_in
18
+ def create
19
+ if resource = authenticate(resource_name)
20
+ set_flash_message :notice, :signed_in
21
+ sign_in_and_redirect(resource_name, resource, true)
22
+ elsif [:custom, :redirect].include?(warden.result)
23
+ throw :warden, :scope => resource_name
24
+ else
25
+ set_now_flash_message :alert, (warden.message || :invalid)
26
+ clean_up_passwords(build_resource)
27
+ render_with_scope :new
28
+ end
29
+ end
30
+
31
+ # GET /resource/sign_out
32
+ def destroy
33
+ set_flash_message :notice, :signed_out if signed_in?(resource_name)
34
+ sign_out_and_redirect(resource_name)
35
+ end
36
+
37
+ protected
38
+
39
+ def clean_up_passwords(object)
40
+ object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
41
+ end
42
+ end
@@ -0,0 +1,41 @@
1
+ class UnlocksController < ApplicationController
2
+ prepend_before_filter :ensure_email_as_unlock_strategy
3
+ prepend_before_filter :require_no_authentication
4
+ include Devise::Controllers::InternalHelpers
5
+
6
+ # GET /resource/unlock/new
7
+ def new
8
+ build_resource
9
+ render_with_scope :new
10
+ end
11
+
12
+ # POST /resource/unlock
13
+ def create
14
+ self.resource = resource_class.send_unlock_instructions(params[resource_name])
15
+
16
+ if resource.errors.empty?
17
+ set_flash_message :notice, :send_instructions
18
+ redirect_to new_session_path(resource_name)
19
+ else
20
+ render_with_scope :new
21
+ end
22
+ end
23
+
24
+ # GET /resource/unlock?unlock_token=abcdef
25
+ def show
26
+ self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
27
+
28
+ if resource.errors.empty?
29
+ set_flash_message :notice, :unlocked
30
+ sign_in_and_redirect(resource_name, resource)
31
+ else
32
+ render_with_scope :new
33
+ end
34
+ end
35
+
36
+ protected
37
+
38
+ def ensure_email_as_unlock_strategy
39
+ raise ActionController::UnknownAction unless resource_class.unlock_strategy_enabled?(:email)
40
+ end
41
+ end
@@ -0,0 +1,68 @@
1
+ class DeviseMailer < ::ActionMailer::Base
2
+ extend Devise::Controllers::InternalHelpers::ScopedViews
3
+
4
+ # Deliver confirmation instructions when the user is created or its email is
5
+ # updated, and also when confirmation is manually requested
6
+ def confirmation_instructions(record)
7
+ setup_mail(record, :confirmation_instructions)
8
+ end
9
+
10
+ # Deliver reset password instructions when manually requested
11
+ def reset_password_instructions(record)
12
+ setup_mail(record, :reset_password_instructions)
13
+ end
14
+
15
+ def unlock_instructions(record)
16
+ setup_mail(record, :unlock_instructions)
17
+ end
18
+
19
+ private
20
+
21
+ # Configure default email options
22
+ def setup_mail(record, key)
23
+ scope_name = Devise::Mapping.find_scope!(record)
24
+ mapping = Devise.mappings[scope_name]
25
+
26
+ subject translate(mapping, key)
27
+ from mailer_sender(mapping)
28
+ recipients record.email
29
+ sent_on Time.now
30
+ content_type Devise.mailer_content_type
31
+ body render_with_scope(key, mapping, mapping.name => record, :resource => record)
32
+ end
33
+
34
+ def render_with_scope(key, mapping, assigns)
35
+ if self.class.scoped_views
36
+ begin
37
+ render :file => "devise_mailer/#{mapping.as}/#{key}", :body => assigns
38
+ rescue ActionView::MissingTemplate
39
+ render :file => "devise_mailer/#{key}", :body => assigns
40
+ end
41
+ else
42
+ render :file => "devise_mailer/#{key}", :body => assigns
43
+ end
44
+ end
45
+
46
+ def mailer_sender(mapping)
47
+ if Devise.mailer_sender.is_a?(Proc)
48
+ block_args = mapping.name if Devise.mailer_sender.arity > 0
49
+ Devise.mailer_sender.call(block_args)
50
+ else
51
+ Devise.mailer_sender
52
+ end
53
+ end
54
+
55
+ # Setup subject namespaced by model. It means you're able to setup your
56
+ # messages using specific resource scope, or provide a default one.
57
+ # Example (i18n locale file):
58
+ #
59
+ # en:
60
+ # devise:
61
+ # mailer:
62
+ # confirmation_instructions: '...'
63
+ # user:
64
+ # confirmation_instructions: '...'
65
+ def translate(mapping, key)
66
+ I18n.t(:"#{mapping.name}.#{key}", :scope => [:devise, :mailer], :default => key)
67
+ end
68
+ end
@@ -0,0 +1,9 @@
1
+ class User < ActiveRecord::Base
2
+ # Include default devise modules. Others available are:
3
+ # :http_authenticatable, :token_authenticatable, :lockable, :timeoutable and :activatable
4
+ devise :registerable, :database_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,14 @@
1
+ <!-- TODO A TRADUIRE "Resend confirmation instructions" -->
2
+ <h2>Renvoi des instructions de confirmation</h2>
3
+
4
+ <% form_for resource_name, resource, :url => confirmation_path(resource_name) do |f| %>
5
+ <%= f.error_messages %>
6
+ <br/>
7
+ <p><%= f.label :email %></p>
8
+ <p><%= f.text_field :email %></p>
9
+
10
+ <!-- TODO A TRADUIRE "Resend confirmation instructions" -->
11
+ <p><%= f.submit "Renvoyer les instructions de confirmation" %></p>
12
+ <% end %>
13
+
14
+ <%= render :partial => "shared/devise_links" %>
@@ -0,0 +1,6 @@
1
+ <p>Welcome <%= @resource.email %>!</p>
2
+
3
+ <p><%= t("devise.registrations.confirm_link") %></p>
4
+
5
+ <!-- TODO A TRADUIRE "Confirm my account" -->
6
+ <p><%= link_to 'Confirmer mon inscription', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
@@ -0,0 +1,8 @@
1
+ <p>Hello <%= (@resource.username + ' : ') unless @resource.username.blank? %><%= @resource.email %>!</p>
2
+
3
+ <p><%= t('devise.mailer.Someone_requested_change_password') %></p>
4
+
5
+ <p><%= link_to t('devise.mailer.Change_my_password'), edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
6
+
7
+ <p><%= t('devise.mailer.If_you_didnt_request_this') %></p>
8
+ <p><%= t('devise.mailer.Your_password_wont_change_until') %></p>
@@ -0,0 +1,7 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
4
+
5
+ <p>Click the link below to unlock your account:</p>
6
+
7
+ <p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>