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
@@ -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,53 @@
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_up
7
+ def new
8
+ build_resource
9
+ render_with_scope :new
10
+ end
11
+
12
+ # POST /resource
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
+ self.resource.destroy
42
+ set_flash_message :notice, :destroyed
43
+ sign_out_and_redirect(self.resource)
44
+ end
45
+
46
+ protected
47
+
48
+ # Authenticates the current scope and dup the resource
49
+ def authenticate_scope!
50
+ send(:"authenticate_#{resource_name}!")
51
+ self.resource = send(:"current_#{resource_name}").dup
52
+ end
53
+ 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,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/route_devise.rb")
2
+
3
+ class DeviseGenerator < Rails::Generator::NamedBase
4
+
5
+ def manifest
6
+ record do |m|
7
+ m.directory(File.join('app', 'models', class_path))
8
+ m.template 'model.rb', File.join('app', 'models', "#{file_path}.rb")
9
+
10
+ m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "devise_create_#{table_name}"
11
+ m.route_devise table_name
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,32 @@
1
+ module Rails
2
+ module Generator
3
+ module Commands
4
+ class Create < Base
5
+
6
+ # Create devise route. Based on route_resources
7
+ def route_devise(*resources)
8
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
9
+ sentinel = 'ActionController::Routing::Routes.draw do |map|'
10
+
11
+ logger.route "map.devise_for #{resource_list}"
12
+ unless options[:pretend]
13
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
14
+ "#{match}\n map.devise_for #{resource_list}\n"
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ class Destroy < RewindBase
21
+
22
+ # Destroy devise route. Based on route_resources
23
+ def route_devise(*resources)
24
+ resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
25
+ look_for = "\n map.devise_for #{resource_list}\n"
26
+ logger.route "map.devise_for #{resource_list}"
27
+ gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table(:<%= table_name %>) do |t|
4
+ t.database_authenticatable :null => false
5
+ t.confirmable
6
+ t.recoverable
7
+ t.rememberable
8
+ t.trackable
9
+ # t.lockable
10
+
11
+ t.timestamps
12
+ end
13
+
14
+ add_index :<%= table_name %>, :email, :unique => true
15
+ add_index :<%= table_name %>, :confirmation_token, :unique => true
16
+ add_index :<%= table_name %>, :reset_password_token, :unique => true
17
+ # add_index :<%= table_name %>, :unlock_token, :unique => true
18
+ end
19
+
20
+ def self.down
21
+ drop_table :<%= table_name %>
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ # Include default devise modules. Others available are:
3
+ # :http_authenticatable, :token_authenticatable, :confirmable, :lockable, :timeoutable and :activatable
4
+ devise :registerable, :database_authenticatable, :recoverable,
5
+ :rememberable, :trackable, :validatable
6
+
7
+ # Setup accessible (or protected) attributes for your model
8
+ attr_accessible :email, :password, :password_confirmation
9
+ end
@@ -0,0 +1,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,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,21 @@
1
+ class DeviseViewsGenerator < Rails::Generator::Base
2
+
3
+ def initialize(*args)
4
+ super
5
+ @source_root = options[:source] || File.join(spec.path, '..', '..')
6
+ end
7
+
8
+ def manifest
9
+ record do |m|
10
+ m.directory "app/views"
11
+
12
+ Dir[File.join(@source_root, "app", "views", "**/*.erb")].each do |file|
13
+ file = file.gsub(@source_root, "")[1..-1]
14
+
15
+ m.directory File.dirname(file)
16
+ m.file file, file
17
+ end
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,212 @@
1
+ module Devise
2
+ module Controllers
3
+ # Those helpers are convenience methods added to ApplicationController.
4
+ module Helpers
5
+
6
+ def self.included(base)
7
+ base.class_eval do
8
+ helper_method :warden, :signed_in?, :devise_controller?, :anybody_signed_in?,
9
+ *Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?", :"#{m}_session"] }.flatten
10
+
11
+ # Use devise default_url_options. We have to declare it here to overwrite
12
+ # default definitions.
13
+ def default_url_options(options=nil)
14
+ Devise::Mapping.default_url_options
15
+ end
16
+ end
17
+ end
18
+
19
+ # The main accessor for the warden proxy instance
20
+ def warden
21
+ request.env['warden']
22
+ end
23
+
24
+ # Return true if it's a devise_controller. false to all controllers unless
25
+ # the controllers defined inside devise. Useful if you want to apply a before
26
+ # filter to all controller, except the ones in devise:
27
+ #
28
+ # before_filter :my_filter, :unless => { |c| c.devise_controller? }
29
+ def devise_controller?
30
+ false
31
+ end
32
+
33
+ # Attempts to authenticate the given scope by running authentication hooks,
34
+ # but does not redirect in case of failures.
35
+ def authenticate(scope)
36
+ warden.authenticate(:scope => scope)
37
+ end
38
+
39
+ # Attempts to authenticate the given scope by running authentication hooks,
40
+ # redirecting in case of failures.
41
+ def authenticate!(scope)
42
+ warden.authenticate!(:scope => scope)
43
+ end
44
+
45
+ # Check if the given scope is signed in session, without running
46
+ # authentication hooks.
47
+ def signed_in?(scope)
48
+ warden.authenticate?(:scope => scope)
49
+ end
50
+
51
+ # Check if the any scope is signed in session, without running
52
+ # authentication hooks.
53
+ def anybody_signed_in?
54
+ Devise.mappings.keys.any? { |scope| signed_in?(scope) }
55
+ end
56
+
57
+ # Sign in an user that already was authenticated. This helper is useful for logging
58
+ # users in after sign up.
59
+ #
60
+ # Examples:
61
+ #
62
+ # sign_in :user, @user # sign_in(scope, resource)
63
+ # sign_in @user # sign_in(resource)
64
+ #
65
+ def sign_in(resource_or_scope, resource=nil)
66
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
67
+ resource ||= resource_or_scope
68
+ warden.set_user(resource, :scope => scope)
69
+ @_session = request.session # Recalculate session
70
+ end
71
+
72
+ # Sign out a given user or scope. This helper is useful for signing out an user
73
+ # after deleting accounts.
74
+ #
75
+ # Examples:
76
+ #
77
+ # sign_out :user # sign_out(scope)
78
+ # sign_out @user # sign_out(resource)
79
+ #
80
+ def sign_out(resource_or_scope)
81
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
82
+ warden.user(scope) # Without loading user here, before_logout hook is not called
83
+ warden.raw_session.inspect # Without this inspect here. The session does not clear.
84
+ warden.logout(scope)
85
+ end
86
+
87
+ # Returns and delete the url stored in the session for the given scope. Useful
88
+ # for giving redirect backs after sign up:
89
+ #
90
+ # Example:
91
+ #
92
+ # redirect_to stored_location_for(:user) || root_path
93
+ #
94
+ def stored_location_for(resource_or_scope)
95
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
96
+ key = "#{scope}.return_to"
97
+ session.delete(key) || session.delete(key.to_sym)
98
+ end
99
+
100
+ # The default url to be used after signing in. This is used by all Devise
101
+ # controllers and you can overwrite it in your ApplicationController to
102
+ # provide a custom hook for a custom resource.
103
+ #
104
+ # By default, it first tries to find a resource_root_path, otherwise it
105
+ # uses the root path. For a user scope, you can define the default url in
106
+ # the following way:
107
+ #
108
+ # map.user_root '/users', :controller => 'users' # creates user_root_path
109
+ #
110
+ # map.namespace :user do |user|
111
+ # user.root :controller => 'users' # creates user_root_path
112
+ # end
113
+ #
114
+ #
115
+ # If the resource root path is not defined, root_path is used. However,
116
+ # if this default is not enough, you can customize it, for example:
117
+ #
118
+ # def after_sign_in_path_for(resource)
119
+ # if resource.is_a?(User) && resource.can_publish?
120
+ # publisher_url
121
+ # else
122
+ # super
123
+ # end
124
+ # end
125
+ #
126
+ def after_sign_in_path_for(resource_or_scope)
127
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
128
+ home_path = "#{scope}_root_path"
129
+ respond_to?(home_path, true) ? send(home_path) : root_path
130
+ end
131
+
132
+ # Method used by sessions controller to sign out an user. You can overwrite
133
+ # it in your ApplicationController to provide a custom hook for a custom
134
+ # scope. Notice that differently from +after_sign_in_path_for+ this method
135
+ # receives a symbol with the scope, and not the resource.
136
+ #
137
+ # By default is the root_path.
138
+ def after_sign_out_path_for(resource_or_scope)
139
+ root_path
140
+ end
141
+
142
+ # Sign in an user and tries to redirect first to the stored location and
143
+ # then to the url specified by after_sign_in_path_for.
144
+ #
145
+ # If just a symbol is given, consider that the user was already signed in
146
+ # through other means and just perform the redirection.
147
+ def sign_in_and_redirect(resource_or_scope, resource=nil, skip=false)
148
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
149
+ resource ||= resource_or_scope
150
+ if skip
151
+ @_session = request.session # Recalculate session
152
+ else
153
+ sign_in(scope, resource)
154
+ end
155
+ redirect_to stored_location_for(scope) || after_sign_in_path_for(resource)
156
+ end
157
+
158
+ # Sign out an user and tries to redirect to the url specified by
159
+ # after_sign_out_path_for.
160
+ def sign_out_and_redirect(resource_or_scope)
161
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
162
+ sign_out(scope)
163
+ redirect_to after_sign_out_path_for(scope)
164
+ end
165
+
166
+ # Define authentication filters and accessor helpers based on mappings.
167
+ # These filters should be used inside the controllers as before_filters,
168
+ # so you can control the scope of the user who should be signed in to
169
+ # access that specific controller/action.
170
+ # Example:
171
+ #
172
+ # Maps:
173
+ # User => :authenticatable
174
+ # Admin => :authenticatable
175
+ #
176
+ # Generated methods:
177
+ # authenticate_user! # Signs user in or redirect
178
+ # authenticate_admin! # Signs admin in or redirect
179
+ # user_signed_in? # Checks whether there is an user signed in or not
180
+ # admin_signed_in? # Checks whether there is an admin signed in or not
181
+ # current_user # Current signed in user
182
+ # current_admin # Current signed in admin
183
+ # user_session # Session data available only to the user scope
184
+ # admin_session # Session data available only to the admin scope
185
+ #
186
+ # Use:
187
+ # before_filter :authenticate_user! # Tell devise to use :user map
188
+ # before_filter :authenticate_admin! # Tell devise to use :admin map
189
+ #
190
+ Devise.mappings.each_key do |mapping|
191
+ class_eval <<-METHODS, __FILE__, __LINE__ + 1
192
+ def authenticate_#{mapping}!
193
+ warden.authenticate!(:scope => :#{mapping})
194
+ end
195
+
196
+ def #{mapping}_signed_in?
197
+ warden.authenticate?(:scope => :#{mapping})
198
+ end
199
+
200
+ def current_#{mapping}
201
+ @current_#{mapping} ||= warden.authenticate(:scope => :#{mapping})
202
+ end
203
+
204
+ def #{mapping}_session
205
+ current_#{mapping} && warden.session(:#{mapping})
206
+ end
207
+ METHODS
208
+ end
209
+
210
+ end
211
+ end
212
+ end