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,89 @@
1
+ require 'devise/strategies/token_authenticatable'
2
+
3
+ module Devise
4
+ module Models
5
+ # Token Authenticatable Module, responsible for generate authentication token and validating
6
+ # authenticity of a user while signing in using an authentication token (say follows an URL).
7
+ #
8
+ # == Configuration:
9
+ #
10
+ # You can overwrite configuration values by setting in globally in Devise (+Devise.setup+),
11
+ # using devise method, or overwriting the respective instance method.
12
+ #
13
+ # +token_authentication_key+ - Defines name of the authentication token params key. E.g. /users/sign_in?some_key=...
14
+ #
15
+ # == Examples:
16
+ #
17
+ # User.authenticate_with_token(:auth_token => '123456789') # returns authenticated user or nil
18
+ # User.find(1).valid_authentication_token?('rI1t6PKQ8yP7VetgwdybB') # returns true/false
19
+ #
20
+ module TokenAuthenticatable
21
+ def self.included(base)
22
+ base.class_eval do
23
+ extend ClassMethods
24
+ before_save :ensure_authentication_token
25
+ end
26
+ end
27
+
28
+ # Generate new authentication token (a.k.a. "single access token").
29
+ def reset_authentication_token
30
+ self.authentication_token = self.class.authentication_token
31
+ end
32
+
33
+ # Generate new authentication token and save the record.
34
+ def reset_authentication_token!
35
+ reset_authentication_token
36
+ self.save
37
+ end
38
+
39
+ # Generate authentication token unless already exists.
40
+ def ensure_authentication_token
41
+ self.reset_authentication_token if self.authentication_token.blank?
42
+ end
43
+
44
+ # Generate authentication token unless already exists and save the record.
45
+ def ensure_authentication_token!
46
+ self.reset_authentication_token! if self.authentication_token.blank?
47
+ end
48
+
49
+ # Verifies whether an +incoming_authentication_token+ (i.e. from single access URL)
50
+ # is the user authentication token.
51
+ def valid_authentication_token?(incoming_auth_token)
52
+ incoming_auth_token.present? && incoming_auth_token == self.authentication_token
53
+ end
54
+
55
+ module ClassMethods
56
+ ::Devise::Models.config(self, :token_authentication_key)
57
+
58
+ # Authenticate a user based on authentication token.
59
+ def authenticate_with_token(attributes)
60
+ token = attributes[self.token_authentication_key]
61
+ resource = self.find_for_token_authentication(token)
62
+ resource if resource.try(:valid_authentication_token?, token)
63
+ end
64
+
65
+ def authentication_token
66
+ ::Devise.friendly_token
67
+ end
68
+
69
+ protected
70
+
71
+ # Find first record based on conditions given (ie by the sign in form).
72
+ # Overwrite to add customized conditions, create a join, or maybe use a
73
+ # namedscope to filter records while authenticating.
74
+ #
75
+ # == Example:
76
+ #
77
+ # def self.find_for_token_authentication(token, conditions = {})
78
+ # conditions = {:active => true}
79
+ # self.find_by_authentication_token(token, :conditions => conditions)
80
+ # end
81
+ #
82
+ def find_for_token_authentication(token)
83
+ self.find(:first, :conditions => { :authentication_token => token})
84
+ end
85
+
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,16 @@
1
+ require 'devise/hooks/trackable'
2
+
3
+ module Devise
4
+ module Models
5
+ # Track information about your user sign in. It tracks the following columns:
6
+ #
7
+ # * sign_in_count - Increased every time a sign in is made (by form, openid, oauth)
8
+ # * current_sign_in_at - A tiemstamp updated when the user signs in
9
+ # * last_sign_in_at - Holds the timestamp of the previous sign in
10
+ # * current_sign_in_ip - The remote ip updated when the user sign in
11
+ # * last_sign_in_at - Holds the remote ip of the previous sign in
12
+ #
13
+ module Trackable
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,39 @@
1
+ module Devise
2
+ module Models
3
+
4
+ # Validatable creates all needed validations for a user email and password.
5
+ # It's optional, given you may want to create the validations by yourself.
6
+ # Automatically validate if the email is present, unique and it's format is
7
+ # valid. Also tests presence of password, confirmation and length
8
+ module Validatable
9
+ # All validations used by this module.
10
+ VALIDATIONS = [ :validates_presence_of, :validates_uniqueness_of, :validates_format_of,
11
+ :validates_confirmation_of, :validates_length_of ].freeze
12
+
13
+ def self.included(base)
14
+ assert_validations_api!(base)
15
+
16
+ base.class_eval do
17
+ validates_presence_of :email
18
+ validates_uniqueness_of :email, :scope => authentication_keys[1..-1], :case_sensitive => false, :allow_blank => true
19
+ validates_format_of :email, :with => EMAIL_REGEX, :allow_blank => true
20
+
21
+ with_options :if => :password_required? do |v|
22
+ v.validates_presence_of :password
23
+ v.validates_confirmation_of :password
24
+ v.validates_length_of :password, :within => 6..20, :allow_blank => true
25
+ end
26
+ end
27
+ end
28
+
29
+ def self.assert_validations_api!(base) #:nodoc:
30
+ unavailable_validations = VALIDATIONS.select { |v| !base.respond_to?(v) }
31
+
32
+ unless unavailable_validations.empty?
33
+ raise "Could not use :validatable module since #{base} does not respond " <<
34
+ "to the following methods: #{unavailable_validations.to_sentence}."
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,117 @@
1
+ module Devise
2
+ module Models
3
+ autoload :Activatable, 'devise/models/activatable'
4
+ autoload :DatabaseAuthenticatable, 'devise/models/database_authenticatable'
5
+ autoload :Confirmable, 'devise/models/confirmable'
6
+ autoload :Lockable, 'devise/models/lockable'
7
+ autoload :Recoverable, 'devise/models/recoverable'
8
+ autoload :Rememberable, 'devise/models/rememberable'
9
+ autoload :Registerable, 'devise/models/registerable'
10
+ autoload :Timeoutable, 'devise/models/timeoutable'
11
+ autoload :Trackable, 'devise/models/trackable'
12
+ autoload :Validatable, 'devise/models/validatable'
13
+
14
+ # Creates configuration values for Devise and for the given module.
15
+ #
16
+ # Devise::Models.config(Devise::Authenticable, :stretches, 10)
17
+ #
18
+ # The line above creates:
19
+ #
20
+ # 1) An accessor called Devise.stretches, which value is used by default;
21
+ #
22
+ # 2) Some class methods for your model Model.stretches and Model.stretches=
23
+ # which have higher priority than Devise.stretches;
24
+ #
25
+ # 3) And an instance method stretches.
26
+ #
27
+ # To add the class methods you need to have a module ClassMethods defined
28
+ # inside the given class.
29
+ #
30
+ def self.config(mod, *accessors) #:nodoc:
31
+ accessors.each do |accessor|
32
+ mod.class_eval <<-METHOD, __FILE__, __LINE__ + 1
33
+ def #{accessor}
34
+ if defined?(@#{accessor})
35
+ @#{accessor}
36
+ elsif superclass.respond_to?(:#{accessor})
37
+ superclass.#{accessor}
38
+ else
39
+ Devise.#{accessor}
40
+ end
41
+ end
42
+
43
+ def #{accessor}=(value)
44
+ @#{accessor} = value
45
+ end
46
+ METHOD
47
+ end
48
+ end
49
+
50
+ # Include the chosen devise modules in your model:
51
+ #
52
+ # devise :authenticatable, :confirmable, :recoverable
53
+ #
54
+ # You can also give any of the devise configuration values in form of a hash,
55
+ # with specific values for this model. Please check your Devise initializer
56
+ # for a complete description on those values.
57
+ #
58
+ def devise(*modules)
59
+ raise "You need to give at least one Devise module" if modules.empty?
60
+ options = modules.extract_options!
61
+
62
+ if modules.delete(:authenticatable)
63
+ ActiveSupport::Deprecation.warn ":authenticatable as module is deprecated. Please give :database_authenticatable instead.", caller
64
+ modules << :database_authenticatable
65
+ end
66
+
67
+ @devise_modules = Devise::ALL & modules.map(&:to_sym).uniq
68
+
69
+ Devise.orm_class.included_modules_hook(self) do
70
+ devise_modules.each do |m|
71
+ include Devise::Models.const_get(m.to_s.classify)
72
+ end
73
+
74
+ options.each { |key, value| send(:"#{key}=", value) }
75
+ end
76
+ end
77
+
78
+ # Stores all modules included inside the model, so we are able to verify
79
+ # which routes are needed.
80
+ def devise_modules
81
+ @devise_modules ||= []
82
+ end
83
+
84
+ # Find an initialize a record setting an error if it can't be found.
85
+ def find_or_initialize_with_error_by(attribute, value, error=:invalid)
86
+ if value.present?
87
+ conditions = { attribute => value }
88
+ record = find(:first, :conditions => conditions)
89
+ end
90
+
91
+ unless record
92
+ record = new
93
+
94
+ if value.present?
95
+ record.send(:"#{attribute}=", value)
96
+ else
97
+ error, skip_default = :blank, true
98
+ end
99
+
100
+ add_error_on(record, attribute, error, !skip_default)
101
+ end
102
+
103
+ record
104
+ end
105
+
106
+ # Wraps add error logic in a method that works for different frameworks.
107
+ def add_error_on(record, attribute, error, add_default=true)
108
+ options = add_default ? { :default => error.to_s.gsub("_", " ") } : {}
109
+
110
+ begin
111
+ record.errors.add(attribute, error, options)
112
+ rescue ArgumentError
113
+ record.errors.add(attribute, error.to_s.gsub("_", " "))
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,41 @@
1
+ module Devise
2
+ module Orm
3
+ # This module contains some helpers and handle schema (migrations):
4
+ #
5
+ # create_table :accounts do |t|
6
+ # t.authenticatable
7
+ # t.confirmable
8
+ # t.recoverable
9
+ # t.rememberable
10
+ # t.trackable
11
+ # t.lockable
12
+ # t.timestamps
13
+ # end
14
+ #
15
+ # However this method does not add indexes. If you need them, here is the declaration:
16
+ #
17
+ # add_index "accounts", ["email"], :name => "email", :unique => true
18
+ # add_index "accounts", ["confirmation_token"], :name => "confirmation_token", :unique => true
19
+ # add_index "accounts", ["reset_password_token"], :name => "reset_password_token", :unique => true
20
+ #
21
+ module ActiveRecord
22
+ # Required ORM hook. Just yield the given block in ActiveRecord.
23
+ def self.included_modules_hook(klass)
24
+ yield
25
+ end
26
+
27
+ include Devise::Schema
28
+
29
+ # Tell how to apply schema methods.
30
+ def apply_schema(name, type, options={})
31
+ column name, type.to_s.downcase.to_sym, options
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ if defined?(ActiveRecord)
38
+ ActiveRecord::Base.extend Devise::Models
39
+ ActiveRecord::ConnectionAdapters::Table.send :include, Devise::Orm::ActiveRecord
40
+ ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Orm::ActiveRecord
41
+ end
@@ -0,0 +1,83 @@
1
+ module Devise
2
+ module Orm
3
+ module DataMapper
4
+ module InstanceMethods
5
+ def save(flag=nil)
6
+ if flag == false
7
+ save!
8
+ else
9
+ super()
10
+ end
11
+ end
12
+ end
13
+
14
+ def self.included_modules_hook(klass)
15
+ klass.send :extend, self
16
+ klass.send :include, InstanceMethods
17
+
18
+ yield
19
+
20
+ klass.devise_modules.each do |mod|
21
+ klass.send(mod) if klass.respond_to?(mod)
22
+ end
23
+ end
24
+
25
+ include Devise::Schema
26
+
27
+ SCHEMA_OPTIONS = {
28
+ :null => :nullable,
29
+ :limit => :length
30
+ }
31
+
32
+ # Hooks for confirmable
33
+ def before_create(*args)
34
+ wrap_hook(:before, *args)
35
+ end
36
+
37
+ def after_create(*args)
38
+ wrap_hook(:after, *args)
39
+ end
40
+
41
+ def wrap_hook(action, *args)
42
+ options = args.extract_options!
43
+
44
+ args.each do |callback|
45
+ send action, :create, callback
46
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
47
+ def #{callback}
48
+ super if #{options[:if] || true}
49
+ end
50
+ METHOD
51
+ end
52
+ end
53
+
54
+ # Add ActiveRecord like finder
55
+ def find(*args)
56
+ options = args.extract_options!
57
+ case args.first
58
+ when :first
59
+ first(options)
60
+ when :all
61
+ all(options)
62
+ else
63
+ get(*args)
64
+ end
65
+ end
66
+
67
+ # Tell how to apply schema methods. This automatically maps :limit to
68
+ # :length and :null to :nullable.
69
+ def apply_schema(name, type, options={})
70
+ return unless Devise.apply_schema
71
+
72
+ SCHEMA_OPTIONS.each do |old_key, new_key|
73
+ next unless options.key?(old_key)
74
+ options[new_key] = options.delete(old_key)
75
+ end
76
+
77
+ property name, type, options
78
+ end
79
+ end
80
+ end
81
+ end
82
+
83
+ DataMapper::Model.send(:include, Devise::Models)
@@ -0,0 +1,52 @@
1
+ module Devise
2
+ module Orm
3
+ module MongoMapper
4
+ module InstanceMethods
5
+ def save(options={})
6
+ if options == false
7
+ super(:validate => false)
8
+ else
9
+ super
10
+ end
11
+ end
12
+ end
13
+
14
+ def self.included_modules_hook(klass)
15
+ klass.send :extend, self
16
+ klass.send :include, InstanceMethods
17
+ yield
18
+
19
+ klass.devise_modules.each do |mod|
20
+ klass.send(mod) if klass.respond_to?(mod)
21
+ end
22
+ end
23
+
24
+ def find(*args)
25
+ case args.first
26
+ when :first, :all
27
+ send(args.shift, *args)
28
+ else
29
+ super
30
+ end
31
+ end
32
+
33
+ include Devise::Schema
34
+
35
+ # Tell how to apply schema methods. This automatically converts DateTime
36
+ # to Time, since MongoMapper does not recognize the former.
37
+ def apply_schema(name, type, options={})
38
+ return unless Devise.apply_schema
39
+ type = Time if type == DateTime
40
+ key name, type, options
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ if MongoMapper::Version >= "0.8.0"
47
+ MongoMapper::Plugins::Document::ClassMethods.send(:include, Devise::Models)
48
+ MongoMapper::Plugins::EmbeddedDocument::ClassMethods.send(:include, Devise::Models)
49
+ else
50
+ MongoMapper::Document::ClassMethods.send(:include, Devise::Models)
51
+ MongoMapper::EmbeddedDocument::ClassMethods.send(:include, Devise::Models)
52
+ end
@@ -0,0 +1,133 @@
1
+ module ActionController::Routing
2
+ class RouteSet #:nodoc:
3
+
4
+ # Ensure Devise modules are included only after loading routes, because we
5
+ # need devise_for mappings already declared to create magic filters and
6
+ # helpers.
7
+ def load_routes_with_devise!
8
+ load_routes_without_devise!
9
+ return if Devise.mappings.empty?
10
+
11
+ ActionController::Base.send :include, Devise::Controllers::Helpers
12
+ ActionController::Base.send :include, Devise::Controllers::UrlHelpers
13
+
14
+ ActionView::Base.send :include, Devise::Controllers::UrlHelpers
15
+ end
16
+ alias_method_chain :load_routes!, :devise
17
+
18
+ class Mapper #:doc:
19
+ # Includes devise_for method for routes. This method is responsible to
20
+ # generate all needed routes for devise, based on what modules you have
21
+ # defined in your model.
22
+ # Examples: Let's say you have an User model configured to use
23
+ # authenticatable, confirmable and recoverable modules. After creating this
24
+ # inside your routes:
25
+ #
26
+ # map.devise_for :users
27
+ #
28
+ # this method is going to look inside your User model and create the
29
+ # needed routes:
30
+ #
31
+ # # Session routes for Authenticatable (default)
32
+ # new_user_session GET /users/sign_in {:controller=>"sessions", :action=>"new"}
33
+ # user_session POST /users/sign_in {:controller=>"sessions", :action=>"create"}
34
+ # destroy_user_session GET /users/sign_out {:controller=>"sessions", :action=>"destroy"}
35
+ #
36
+ # # Password routes for Recoverable, if User model has :recoverable configured
37
+ # new_user_password GET /users/password/new(.:format) {:controller=>"passwords", :action=>"new"}
38
+ # edit_user_password GET /users/password/edit(.:format) {:controller=>"passwords", :action=>"edit"}
39
+ # user_password PUT /users/password(.:format) {:controller=>"passwords", :action=>"update"}
40
+ # POST /users/password(.:format) {:controller=>"passwords", :action=>"create"}
41
+ #
42
+ # # Confirmation routes for Confirmable, if User model has :confirmable configured
43
+ # new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"confirmations", :action=>"new"}
44
+ # user_confirmation GET /users/confirmation(.:format) {:controller=>"confirmations", :action=>"show"}
45
+ # POST /users/confirmation(.:format) {:controller=>"confirmations", :action=>"create"}
46
+ #
47
+ # You can configure your routes with some options:
48
+ #
49
+ # * :class_name => setup a different class to be looked up by devise, if it cannot be correctly find by the route name.
50
+ #
51
+ # map.devise_for :users, :class_name => 'Account'
52
+ #
53
+ # * :as => allows you to setup path name that will be used, as rails routes does. The following route configuration would setup your route as /accounts instead of /users:
54
+ #
55
+ # map.devise_for :users, :as => 'accounts'
56
+ #
57
+ # * :scope => setup the scope name. This is used as the instance variable name in controller, as the name in routes and the scope given to warden. Defaults to the singular of the given name:
58
+ #
59
+ # map.devise_for :users, :scope => :account
60
+ #
61
+ # * :path_names => configure different path names to overwrite defaults :sign_in, :sign_out, :password and :confirmation.
62
+ #
63
+ # map.devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
64
+ #
65
+ # * :path_prefix => the path prefix to be used in all routes.
66
+ #
67
+ # map.devise_for :users, :path_prefix => "/:locale"
68
+ #
69
+ # * :sign_out_via => restirct the HTTP method(s) accepted for the :sign_out action (default: :get), possible values are :post, :get, :put, :delete and :any, e.g. if you wish to restrict this to accept only :delete requests you should do:
70
+ #
71
+ # map.devise_for :users, :sign_out_via => :delete
72
+ #
73
+ # You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
74
+ #
75
+ # Any other options will be passed to route definition. If you need conditions for your routes, just map:
76
+ #
77
+ # map.devise_for :users, :conditions => { :subdomain => /.+/ }
78
+ #
79
+ # If you are using a dynamic prefix, like :locale above, you need to configure default_url_options through Devise. You can do that in config/initializers/devise.rb or setting a Devise.default_url_options:
80
+ #
81
+ # Devise.default_url_options do
82
+ # { :locale => I18n.locale }
83
+ # end
84
+ #
85
+ def devise_for(*resources)
86
+ options = resources.extract_options!
87
+
88
+ resources.map!(&:to_sym)
89
+ resources.each do |resource|
90
+ mapping = Devise::Mapping.new(resource, options.dup)
91
+ Devise.default_scope ||= mapping.name
92
+ Devise.mappings[mapping.name] = mapping
93
+
94
+ route_options = mapping.route_options.merge(:path_prefix => mapping.raw_path, :name_prefix => "#{mapping.name}_")
95
+
96
+ with_options(route_options) do |routes|
97
+ mapping.for.each do |mod|
98
+ send(mod, routes, mapping) if self.respond_to?(mod, true)
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ protected
105
+
106
+ def database_authenticatable(routes, mapping)
107
+ routes.with_options(:controller => 'sessions', :name_prefix => nil) do |session|
108
+ session.send(:"new_#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'new', :conditions => { :method => :get })
109
+ session.send(:"#{mapping.name}_session", mapping.path_names[:sign_in], :action => 'create', :conditions => { :method => :post })
110
+ destroy_options = { :action => 'destroy' }
111
+ destroy_options.merge! :conditions => { :method => mapping.sign_out_via } unless mapping.sign_out_via == :any
112
+ session.send(:"destroy_#{mapping.name}_session", mapping.path_names[:sign_out], destroy_options)
113
+ end
114
+ end
115
+
116
+ def confirmable(routes, mapping)
117
+ routes.resource :confirmation, :only => [:new, :create, :show], :as => mapping.path_names[:confirmation]
118
+ end
119
+
120
+ def lockable(routes, mapping)
121
+ routes.resource :unlock, :only => [:new, :create, :show], :as => mapping.path_names[:unlock]
122
+ end
123
+
124
+ def recoverable(routes, mapping)
125
+ routes.resource :password, :only => [:new, :create, :edit, :update], :as => mapping.path_names[:password]
126
+ end
127
+
128
+ def registerable(routes, mapping)
129
+ routes.resource :registration, :only => [:new, :create, :edit, :update, :destroy], :as => mapping.raw_path[1..-1], :path_prefix => nil, :path_names => { :new => mapping.path_names[:sign_up] }
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,60 @@
1
+ module Warden::Mixins::Common
2
+ def request
3
+ @request ||= env['action_controller.rescue.request']
4
+ end
5
+
6
+ def reset_session!
7
+ raw_session.inspect # why do I have to inspect it to get it to clear?
8
+ raw_session.clear
9
+ end
10
+
11
+ def response
12
+ @response ||= env['action_controller.rescue.response']
13
+ end
14
+ end
15
+
16
+ class Warden::SessionSerializer
17
+ def serialize(record)
18
+ [record.class, record.id]
19
+ end
20
+
21
+ def deserialize(keys)
22
+ klass, id = keys
23
+ klass.find(:first, :conditions => { :id => id })
24
+ end
25
+ end
26
+
27
+ class ActionController::Request
28
+ def reset_session
29
+ session.destroy if session && session.respond_to?(:destroy)
30
+ self.session = {}
31
+ end
32
+ end
33
+
34
+ # Solve a bug in Rails where Set-Cookie is returning an array.
35
+ class Devise::CookieSanitizer
36
+ SET_COOKIE = "Set-Cookie".freeze
37
+
38
+ def initialize(app)
39
+ @app = app
40
+ end
41
+
42
+ def call(env)
43
+ response = @app.call(env)
44
+ headers = response[1]
45
+ headers[SET_COOKIE] = headers[SET_COOKIE].join("\n") if headers[SET_COOKIE].respond_to?(:join)
46
+ response
47
+ end
48
+ end
49
+
50
+ Rails.configuration.middleware.insert_after ActionController::Failsafe, Devise::CookieSanitizer
51
+
52
+ Warden::Manager.after_set_user :event => [:set_user, :authentication] do |record, warden, options|
53
+ if options[:scope] && warden.authenticated?(options[:scope])
54
+ request = warden.request
55
+ backup = request.session.to_hash
56
+ backup.delete(:session_id)
57
+ request.reset_session
58
+ request.session.update(backup)
59
+ end
60
+ end
@@ -0,0 +1,14 @@
1
+ require 'devise/rails/routes'
2
+ require 'devise/rails/warden_compat'
3
+
4
+ Rails.configuration.after_initialize do
5
+ require "devise/orm/#{Devise.orm}"
6
+
7
+ # Adds Warden Manager to Rails middleware stack, configuring default devise
8
+ # strategy and also the failure app.
9
+ Rails.configuration.middleware.use Warden::Manager do |config|
10
+ Devise.configure_warden(config)
11
+ end
12
+
13
+ I18n.load_path.unshift File.expand_path(File.join(File.dirname(__FILE__), 'locales', 'en.yml'))
14
+ end