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,73 @@
1
+ module Devise
2
+ # Holds devise schema information. To use it, just include its methods
3
+ # and overwrite the apply_schema method.
4
+ module Schema
5
+
6
+ def authenticatable(*args)
7
+ ActiveSupport::Deprecation.warn "t.authenticatable in migrations is deprecated. Please use t.database_authenticatable instead.", caller
8
+ database_authenticatable(*args)
9
+ end
10
+
11
+ # Creates email, encrypted_password and password_salt.
12
+ #
13
+ # == Options
14
+ # * :null - When true, allow columns to be null.
15
+ def database_authenticatable(options={})
16
+ null = options[:null] || false
17
+ default = options[:default] || ""
18
+
19
+ if options.delete(:encryptor)
20
+ ActiveSupport::Deprecation.warn ":encryptor as option is deprecated, simply remove it."
21
+ end
22
+
23
+ apply_schema :email, String, :null => null, :default => default
24
+ apply_schema :encrypted_password, String, :null => null, :default => default, :limit => 128
25
+ apply_schema :password_salt, String, :null => null, :default => default
26
+ end
27
+
28
+ # Creates authentication_token.
29
+ def token_authenticatable
30
+ apply_schema :authentication_token, String
31
+ end
32
+
33
+ # Creates confirmation_token, confirmed_at and confirmation_sent_at.
34
+ def confirmable
35
+ apply_schema :confirmation_token, String
36
+ apply_schema :confirmed_at, DateTime
37
+ apply_schema :confirmation_sent_at, DateTime
38
+ end
39
+
40
+ # Creates reset_password_token.
41
+ def recoverable
42
+ apply_schema :reset_password_token, String
43
+ end
44
+
45
+ # Creates remember_token and remember_created_at.
46
+ def rememberable
47
+ apply_schema :remember_token, String
48
+ apply_schema :remember_created_at, DateTime
49
+ end
50
+
51
+ # Creates sign_in_count, current_sign_in_at, last_sign_in_at,
52
+ # current_sign_in_ip, last_sign_in_ip.
53
+ def trackable
54
+ apply_schema :sign_in_count, Integer, :default => 0
55
+ apply_schema :current_sign_in_at, DateTime
56
+ apply_schema :last_sign_in_at, DateTime
57
+ apply_schema :current_sign_in_ip, String
58
+ apply_schema :last_sign_in_ip, String
59
+ end
60
+
61
+ # Creates failed_attempts, unlock_token and locked_at
62
+ def lockable
63
+ apply_schema :failed_attempts, Integer, :default => 0
64
+ apply_schema :unlock_token, String
65
+ apply_schema :locked_at, DateTime
66
+ end
67
+
68
+ # Overwrite with specific modification to create your own schema.
69
+ def apply_schema(name, type, options={})
70
+ raise NotImplementedError
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,16 @@
1
+ module Devise
2
+ module Strategies
3
+ # Base strategy for Devise. Responsible for verifying correct scope and mapping.
4
+ class Base < ::Warden::Strategies::Base
5
+ # Checks if a valid scope was given for devise and find mapping based on
6
+ # this scope.
7
+ def mapping
8
+ @mapping ||= begin
9
+ mapping = Devise.mappings[scope]
10
+ raise "Could not find mapping for #{scope}" unless mapping
11
+ mapping
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+ require 'devise/strategies/base'
2
+
3
+ module Devise
4
+ module Strategies
5
+ # Default strategy for signing in a user, based on his email and password.
6
+ # Redirects to sign_in page if it's not authenticated
7
+ class DatabaseAuthenticatable < Base
8
+ def valid?
9
+ valid_controller? && valid_params? && mapping.to.respond_to?(:authenticate)
10
+ end
11
+
12
+ # Authenticate a user based on email and password params, returning to warden
13
+ # success and the authenticated user if everything is okay. Otherwise redirect
14
+ # to sign in page.
15
+ def authenticate!
16
+ if resource = mapping.to.authenticate(params[scope])
17
+ success!(resource)
18
+ else
19
+ fail(:invalid)
20
+ end
21
+ end
22
+
23
+ protected
24
+
25
+ def valid_controller?
26
+ params[:controller] =~ /sessions$/
27
+ end
28
+
29
+ def valid_params?
30
+ params[scope] && params[scope][:password].present?
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ Warden::Strategies.add(:database_authenticatable, Devise::Strategies::DatabaseAuthenticatable)
@@ -0,0 +1,59 @@
1
+ require 'devise/strategies/base'
2
+
3
+ module Devise
4
+ module Strategies
5
+ # Sign in an user using HTTP authentication.
6
+ class HttpAuthenticatable < Base
7
+ def valid?
8
+ http_authentication? && mapping.to.respond_to?(:authenticate_with_http)
9
+ end
10
+
11
+ def authenticate!
12
+ username, password = username_and_password
13
+
14
+ if resource = mapping.to.authenticate_with_http(username, password)
15
+ success!(resource)
16
+ else
17
+ custom!([401, custom_headers, [response_body]])
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def username_and_password
24
+ decode_credentials(request).split(/:/, 2)
25
+ end
26
+
27
+ def response_body
28
+ body = "HTTP Basic: Access denied."
29
+ method = :"to_#{request_format.to_sym}"
30
+ {}.respond_to?(method) ? { :error => body }.send(method) : body
31
+ end
32
+
33
+ def http_authentication
34
+ request.env['HTTP_AUTHORIZATION'] ||
35
+ request.env['X-HTTP_AUTHORIZATION'] ||
36
+ request.env['X_HTTP_AUTHORIZATION'] ||
37
+ request.env['REDIRECT_X_HTTP_AUTHORIZATION']
38
+ end
39
+ alias :http_authentication? :http_authentication
40
+
41
+ def decode_credentials(request)
42
+ ActiveSupport::Base64.decode64(http_authentication.split(' ', 2).last || '')
43
+ end
44
+
45
+ def custom_headers
46
+ {
47
+ "Content-Type" => request_format.to_s,
48
+ "WWW-Authenticate" => %(Basic realm="#{Devise.http_authentication_realm.gsub(/"/, "")}")
49
+ }
50
+ end
51
+
52
+ def request_format
53
+ @request_format ||= Mime::Type.lookup_by_extension(request.template_format.to_s)
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ Warden::Strategies.add(:http_authenticatable, Devise::Strategies::HttpAuthenticatable)
@@ -0,0 +1,37 @@
1
+ require 'devise/strategies/base'
2
+
3
+ module Devise
4
+ module Strategies
5
+ # Remember the user through the remember token. This strategy is responsible
6
+ # to verify whether there is a cookie with the remember token, and to
7
+ # recreate the user from this cookie if it exists. Must be called *before*
8
+ # authenticatable.
9
+ class Rememberable < Devise::Strategies::Base
10
+
11
+ # A valid strategy for rememberable needs a remember token in the cookies.
12
+ def valid?
13
+ remember_me_cookie.present? && mapping.to.respond_to?(:serialize_from_cookie)
14
+ end
15
+
16
+ # To authenticate a user we deserialize the cookie and attempt finding
17
+ # the record in the database. If the attempt fails, we pass to another
18
+ # strategy handle the authentication.
19
+ def authenticate!
20
+ if resource = mapping.to.serialize_from_cookie(remember_me_cookie)
21
+ success!(resource)
22
+ else
23
+ pass
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ # Accessor for remember cookie
30
+ def remember_me_cookie
31
+ @remember_me_cookie ||= request.cookies["remember_#{mapping.name}_token"]
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ Warden::Strategies.add(:rememberable, Devise::Strategies::Rememberable)
@@ -0,0 +1,37 @@
1
+ require 'devise/strategies/base'
2
+
3
+ module Devise
4
+ module Strategies
5
+ # Strategy for signing in a user, based on a authenticatable token.
6
+ # Redirects to sign_in page if it's not authenticated.
7
+ class TokenAuthenticatable < Base
8
+ def valid?
9
+ mapping.to.respond_to?(:authenticate_with_token) && authentication_token(scope).present?
10
+ end
11
+
12
+ # Authenticate a user based on authenticatable token params, returning to warden
13
+ # success and the authenticated user if everything is okay. Otherwise redirect
14
+ # to sign in page.
15
+ def authenticate!
16
+ if resource = mapping.to.authenticate_with_token(params[scope] || params)
17
+ success!(resource)
18
+ else
19
+ fail!(:invalid_token)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ # Detect authentication token in params: scoped or not.
26
+ def authentication_token(scope)
27
+ if params[scope]
28
+ params[scope][mapping.to.token_authentication_key]
29
+ else
30
+ params[mapping.to.token_authentication_key]
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ Warden::Strategies.add(:token_authenticatable, Devise::Strategies::TokenAuthenticatable)
@@ -0,0 +1,90 @@
1
+ module Devise
2
+ module TestHelpers
3
+ def self.included(base)
4
+ base.class_eval do
5
+ setup :setup_controller_for_warden, :warden if respond_to?(:setup)
6
+ end
7
+ end
8
+
9
+ # This is a Warden::Proxy customized for functional tests. It's meant to
10
+ # some of Warden::Manager responsibilities, as retrieving configuration
11
+ # options and calling the FailureApp.
12
+ class TestWarden < Warden::Proxy #:nodoc:
13
+ attr_reader :controller
14
+
15
+ def initialize(controller)
16
+ @controller = controller
17
+ manager = Warden::Manager.new(nil) do |config|
18
+ Devise.configure_warden(config)
19
+ end
20
+ super(controller.request.env, manager)
21
+ end
22
+
23
+ def authenticate!(*args)
24
+ catch_with_redirect { super }
25
+ end
26
+
27
+ def user(*args)
28
+ catch_with_redirect { super }
29
+ end
30
+
31
+ def catch_with_redirect(&block)
32
+ result = catch(:warden, &block)
33
+
34
+ if result.is_a?(Hash) && !custom_failure? && !@controller.send(:performed?)
35
+ result[:action] ||= :unauthenticated
36
+
37
+ env = @controller.request.env
38
+ env["PATH_INFO"] = "/#{result[:action]}"
39
+ env["warden.options"] = result
40
+ Warden::Manager._before_failure.each{ |hook| hook.call(env, result) }
41
+
42
+ status, headers, body = Devise::FailureApp.call(env).to_a
43
+ @controller.send :redirect_to, headers["Location"]
44
+ else
45
+ result
46
+ end
47
+ end
48
+ end
49
+
50
+ # We need to setup the environment variables and the response in the controller.
51
+ def setup_controller_for_warden #:nodoc:
52
+ @request.env['action_controller.rescue.request'] = @request
53
+ @request.env['action_controller.rescue.response'] = @response
54
+ @request.env['rack.session'] = session
55
+ @controller.response = @response
56
+ end
57
+
58
+ # Quick access to Warden::Proxy.
59
+ def warden #:nodoc:
60
+ @warden ||= (@request.env['warden'] = TestWarden.new(@controller))
61
+ end
62
+
63
+ # sign_in a given resource by storing its keys in the session.
64
+ #
65
+ # Examples:
66
+ #
67
+ # sign_in :user, @user # sign_in(scope, resource)
68
+ # sign_in @user # sign_in(resource)
69
+ #
70
+ def sign_in(resource_or_scope, resource=nil)
71
+ scope ||= Devise::Mapping.find_scope!(resource_or_scope)
72
+ resource ||= resource_or_scope
73
+ warden.session_serializer.store(resource, scope)
74
+ end
75
+
76
+ # Sign out a given resource or scope by calling logout on Warden.
77
+ #
78
+ # Examples:
79
+ #
80
+ # sign_out :user # sign_out(scope)
81
+ # sign_out @user # sign_out(resource)
82
+ #
83
+ def sign_out(resource_or_scope)
84
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
85
+ @controller.instance_variable_set(:"@current_#{scope}", nil)
86
+ warden.logout(scope)
87
+ end
88
+
89
+ end
90
+ end
@@ -0,0 +1,3 @@
1
+ module Devise
2
+ VERSION = "1.0.9".freeze
3
+ end
@@ -0,0 +1,266 @@
1
+ module Devise
2
+ autoload :FailureApp, 'devise/failure_app'
3
+ autoload :Models, 'devise/models'
4
+ autoload :Schema, 'devise/schema'
5
+ autoload :TestHelpers, 'devise/test_helpers'
6
+
7
+ module Controllers
8
+ autoload :Helpers, 'devise/controllers/helpers'
9
+ autoload :InternalHelpers, 'devise/controllers/internal_helpers'
10
+ autoload :UrlHelpers, 'devise/controllers/url_helpers'
11
+ end
12
+
13
+ module Encryptors
14
+ autoload :Base, 'devise/encryptors/base'
15
+ autoload :Bcrypt, 'devise/encryptors/bcrypt'
16
+ autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
17
+ autoload :ClearanceSha1, 'devise/encryptors/clearance_sha1'
18
+ autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
19
+ autoload :Sha512, 'devise/encryptors/sha512'
20
+ autoload :Sha1, 'devise/encryptors/sha1'
21
+ end
22
+
23
+ module Orm
24
+ autoload :ActiveRecord, 'devise/orm/active_record'
25
+ autoload :DataMapper, 'devise/orm/data_mapper'
26
+ autoload :MongoMapper, 'devise/orm/mongo_mapper'
27
+ end
28
+
29
+ ALL = []
30
+
31
+ # Authentication ones first
32
+ ALL.push :database_authenticatable, :http_authenticatable, :token_authenticatable, :rememberable
33
+
34
+ # Misc after
35
+ ALL.push :recoverable, :registerable, :validatable
36
+
37
+ # The ones which can sign out after
38
+ ALL.push :activatable, :confirmable, :lockable, :timeoutable
39
+
40
+ # Stats for last, so we make sure the user is really signed in
41
+ ALL.push :trackable
42
+
43
+ # Maps controller names to devise modules.
44
+ CONTROLLERS = {
45
+ :sessions => [:database_authenticatable, :token_authenticatable],
46
+ :passwords => [:recoverable],
47
+ :confirmations => [:confirmable],
48
+ :registrations => [:registerable],
49
+ :unlocks => [:lockable]
50
+ }
51
+
52
+ # Routes for generating url helpers.
53
+ ROUTES = [:session, :password, :confirmation, :registration, :unlock]
54
+
55
+ STRATEGIES = [:rememberable, :http_authenticatable, :token_authenticatable, :database_authenticatable]
56
+
57
+ TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
58
+
59
+ # Maps the messages types that are used in flash message.
60
+ FLASH_MESSAGES = [:unauthenticated, :unconfirmed, :invalid, :invalid_token, :timeout, :inactive, :locked]
61
+
62
+ # Declare encryptors length which are used in migrations.
63
+ ENCRYPTORS_LENGTH = {
64
+ :sha1 => 40,
65
+ :sha512 => 128,
66
+ :clearance_sha1 => 40,
67
+ :restful_authentication_sha1 => 40,
68
+ :authlogic_sha512 => 128,
69
+ :bcrypt => 60
70
+ }
71
+
72
+ # Email regex used to validate email formats. Adapted from authlogic.
73
+ EMAIL_REGEX = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
74
+
75
+ # Used to encrypt password. Please generate one with rake secret.
76
+ mattr_accessor :pepper
77
+ @@pepper = nil
78
+
79
+ # The number of times to encrypt password.
80
+ mattr_accessor :stretches
81
+ @@stretches = 10
82
+
83
+ # Keys used when authenticating an user.
84
+ mattr_accessor :authentication_keys
85
+ @@authentication_keys = [ :email ]
86
+
87
+ # Time interval where the remember me token is valid.
88
+ mattr_accessor :remember_for
89
+ @@remember_for = 2.weeks
90
+
91
+ # Time interval you can access your account before confirming your account.
92
+ mattr_accessor :confirm_within
93
+ @@confirm_within = 0.days
94
+
95
+ # Time interval to timeout the user session without activity.
96
+ mattr_accessor :timeout_in
97
+ @@timeout_in = 30.minutes
98
+
99
+ # Used to define the password encryption algorithm.
100
+ mattr_accessor :encryptor
101
+ @@encryptor = :sha1
102
+
103
+ # Store scopes mappings.
104
+ mattr_accessor :mappings
105
+ @@mappings = ActiveSupport::OrderedHash.new
106
+
107
+ # Stores the chosen ORM.
108
+ mattr_accessor :orm
109
+ @@orm = :active_record
110
+
111
+ # TODO Remove
112
+ mattr_accessor :all
113
+ @@all = []
114
+
115
+ # Tells if devise should apply the schema in ORMs where devise declaration
116
+ # and schema belongs to the same class (as Datamapper and MongoMapper).
117
+ mattr_accessor :apply_schema
118
+ @@apply_schema = true
119
+
120
+ # Scoped views. Since it relies on fallbacks to render default views, it's
121
+ # turned off by default.
122
+ mattr_accessor :scoped_views
123
+ @@scoped_views = false
124
+
125
+ # Number of authentication tries before locking an account
126
+ mattr_accessor :maximum_attempts
127
+ @@maximum_attempts = 20
128
+
129
+ # Defines which strategy can be used to unlock an account.
130
+ # Values: :email, :time, :both
131
+ mattr_accessor :unlock_strategy
132
+ @@unlock_strategy = :both
133
+
134
+ # Time interval to unlock the account if :time is defined as unlock_strategy.
135
+ mattr_accessor :unlock_in
136
+ @@unlock_in = 1.hour
137
+
138
+ # Tell when to use the default scope, if one cannot be found from routes.
139
+ mattr_accessor :use_default_scope
140
+ @@use_default_scope = false
141
+
142
+ # The default scope which is used by warden.
143
+ mattr_accessor :default_scope
144
+ @@default_scope = nil
145
+
146
+ # Address which sends Devise e-mails.
147
+ mattr_accessor :mailer_sender
148
+ @@mailer_sender = nil
149
+
150
+ # Content Type of Devise e-mails.
151
+ mattr_accessor :mailer_content_type
152
+ @@mailer_content_type = 'text/html'
153
+
154
+ # Authentication token params key name of choice. E.g. /users/sign_in?some_key=...
155
+ mattr_accessor :token_authentication_key
156
+ @@token_authentication_key = :auth_token
157
+
158
+ # The realm used in Http Basic Authentication
159
+ mattr_accessor :http_authentication_realm
160
+ @@http_authentication_realm = "Application"
161
+
162
+ class << self
163
+ # Default way to setup Devise. Run script/generate devise_install to create
164
+ # a fresh initializer with all configuration values.
165
+ def setup
166
+ yield self
167
+ end
168
+
169
+ # Sets warden configuration using a block that will be invoked on warden
170
+ # initialization.
171
+ #
172
+ # Devise.initialize do |config|
173
+ # config.confirm_within = 2.days
174
+ #
175
+ # config.warden do |manager|
176
+ # # Configure warden to use other strategies, like oauth.
177
+ # manager.oauth(:twitter)
178
+ # end
179
+ # end
180
+ def warden(&block)
181
+ @warden_config = block
182
+ end
183
+
184
+ # Configure default url options to be used within Devise and ActionController.
185
+ def default_url_options(&block)
186
+ who = Devise::Mapping.respond_to?(:singleton_class) ?
187
+ Devise::Mapping.singleton_class : Devise::Mapping.metaclass
188
+ who.send :define_method, :default_url_options, &block
189
+ end
190
+
191
+ # A method used internally to setup warden manager from the Rails initialize
192
+ # block.
193
+ def configure_warden(config) #:nodoc:
194
+ config.default_strategies *Devise::STRATEGIES
195
+ config.failure_app = Devise::FailureApp
196
+ config.silence_missing_strategies!
197
+ config.default_scope = Devise.default_scope
198
+
199
+ # If the user provided a warden hook, call it now.
200
+ @warden_config.try :call, config
201
+ end
202
+
203
+ # The class of the configured ORM
204
+ def orm_class
205
+ Devise::Orm.const_get(@@orm.to_s.camelize.to_sym)
206
+ end
207
+
208
+ # Generate a friendly string randomically to be used as token.
209
+ def friendly_token
210
+ ActiveSupport::SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
211
+ end
212
+
213
+ # Make Devise aware of an 3rd party Devise-module. For convenience.
214
+ #
215
+ # == Options:
216
+ #
217
+ # +strategy+ - Boolean value representing if this module got a custom *strategy*.
218
+ # Default is +false+. Note: Devise will auto-detect this in such case if this is true.
219
+ # +model+ - String representing a load path to a custom *model* for this module (to autoload).
220
+ # Default is +nil+ (i.e. +false+).
221
+ # +controller+ - Symbol representing a name of an exisiting or custom *controller* for this module.
222
+ # Default is +nil+ (i.e. +false+).
223
+ # +route+ - Symbol representing the name of a *route* related to this module which a set of
224
+ # route view helpers should be created for.
225
+ # Default is +nil+ (i.e. +false+).
226
+ #
227
+ # == Examples:
228
+ #
229
+ # Devise.add_module(:party_module)
230
+ # Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
231
+ # Devise.add_module(:party_module, :model => 'party_module/model')
232
+ #
233
+ def add_module(module_name, options = {})
234
+ Devise::ALL << module_name unless Devise::ALL.include?(module_name)
235
+ Devise::STRATEGIES.unshift module_name if options[:strategy] && !Devise::STRATEGIES.include?(module_name)
236
+
237
+ if options[:controller]
238
+ controller = options[:controller].to_sym
239
+ Devise::CONTROLLERS[controller] ||= []
240
+ Devise::CONTROLLERS[controller].unshift module_name unless Devise::CONTROLLERS[controller].include?(module_name)
241
+ end
242
+
243
+ if options[:route]
244
+ Devise::ROUTES.unshift options[:route] unless Devise::ROUTES.include?(options[:route])
245
+ end
246
+
247
+ if options[:model]
248
+ Devise::Models.module_eval do
249
+ autoload :"#{module_name.to_s.classify}", options[:model]
250
+ end
251
+ end
252
+
253
+ Devise::Mapping.register module_name
254
+ end
255
+ end
256
+ end
257
+
258
+ begin
259
+ require 'warden'
260
+ rescue
261
+ gem 'warden'
262
+ require 'warden'
263
+ end
264
+
265
+ require 'devise/mapping'
266
+ require 'devise/rails'
@@ -0,0 +1,2 @@
1
+ # We need to load devise here to ensure routes extensions are loaded.
2
+ require 'devise'