devise-edge 1.2.rc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. data/CHANGELOG.rdoc +500 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +335 -0
  4. data/app/controllers/devise/confirmations_controller.rb +33 -0
  5. data/app/controllers/devise/oauth_callbacks_controller.rb +4 -0
  6. data/app/controllers/devise/passwords_controller.rb +41 -0
  7. data/app/controllers/devise/registrations_controller.rb +75 -0
  8. data/app/controllers/devise/sessions_controller.rb +23 -0
  9. data/app/controllers/devise/unlocks_controller.rb +34 -0
  10. data/app/helpers/devise_helper.rb +17 -0
  11. data/app/mailers/devise/mailer.rb +88 -0
  12. data/app/views/devise/confirmations/new.html.erb +12 -0
  13. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  14. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  15. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  16. data/app/views/devise/passwords/edit.html.erb +16 -0
  17. data/app/views/devise/passwords/new.html.erb +12 -0
  18. data/app/views/devise/registrations/edit.html.erb +25 -0
  19. data/app/views/devise/registrations/new.html.erb +18 -0
  20. data/app/views/devise/sessions/new.html.erb +17 -0
  21. data/app/views/devise/shared/_links.erb +25 -0
  22. data/app/views/devise/unlocks/new.html.erb +12 -0
  23. data/config/locales/en.yml +42 -0
  24. data/lib/devise.rb +371 -0
  25. data/lib/devise/controllers/helpers.rb +261 -0
  26. data/lib/devise/controllers/internal_helpers.rb +113 -0
  27. data/lib/devise/controllers/scoped_views.rb +33 -0
  28. data/lib/devise/controllers/url_helpers.rb +39 -0
  29. data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
  30. data/lib/devise/encryptors/base.rb +20 -0
  31. data/lib/devise/encryptors/clearance_sha1.rb +17 -0
  32. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  33. data/lib/devise/encryptors/sha1.rb +25 -0
  34. data/lib/devise/encryptors/sha512.rb +25 -0
  35. data/lib/devise/failure_app.rb +126 -0
  36. data/lib/devise/hooks/activatable.rb +11 -0
  37. data/lib/devise/hooks/forgetable.rb +12 -0
  38. data/lib/devise/hooks/rememberable.rb +45 -0
  39. data/lib/devise/hooks/timeoutable.rb +22 -0
  40. data/lib/devise/hooks/trackable.rb +9 -0
  41. data/lib/devise/mapping.rb +105 -0
  42. data/lib/devise/models.rb +66 -0
  43. data/lib/devise/models/authenticatable.rb +143 -0
  44. data/lib/devise/models/confirmable.rb +160 -0
  45. data/lib/devise/models/database_authenticatable.rb +94 -0
  46. data/lib/devise/models/encryptable.rb +65 -0
  47. data/lib/devise/models/lockable.rb +168 -0
  48. data/lib/devise/models/oauthable.rb +49 -0
  49. data/lib/devise/models/recoverable.rb +83 -0
  50. data/lib/devise/models/registerable.rb +21 -0
  51. data/lib/devise/models/rememberable.rb +122 -0
  52. data/lib/devise/models/timeoutable.rb +33 -0
  53. data/lib/devise/models/token_authenticatable.rb +72 -0
  54. data/lib/devise/models/trackable.rb +30 -0
  55. data/lib/devise/models/validatable.rb +60 -0
  56. data/lib/devise/modules.rb +30 -0
  57. data/lib/devise/oauth.rb +41 -0
  58. data/lib/devise/oauth/config.rb +33 -0
  59. data/lib/devise/oauth/helpers.rb +18 -0
  60. data/lib/devise/oauth/internal_helpers.rb +182 -0
  61. data/lib/devise/oauth/test_helpers.rb +29 -0
  62. data/lib/devise/oauth/url_helpers.rb +35 -0
  63. data/lib/devise/orm/active_record.rb +36 -0
  64. data/lib/devise/orm/mongo_mapper.rb +46 -0
  65. data/lib/devise/orm/mongoid.rb +29 -0
  66. data/lib/devise/path_checker.rb +18 -0
  67. data/lib/devise/rails.rb +67 -0
  68. data/lib/devise/rails/routes.rb +260 -0
  69. data/lib/devise/rails/warden_compat.rb +42 -0
  70. data/lib/devise/schema.rb +96 -0
  71. data/lib/devise/strategies/authenticatable.rb +150 -0
  72. data/lib/devise/strategies/base.rb +15 -0
  73. data/lib/devise/strategies/database_authenticatable.rb +21 -0
  74. data/lib/devise/strategies/rememberable.rb +51 -0
  75. data/lib/devise/strategies/token_authenticatable.rb +53 -0
  76. data/lib/devise/test_helpers.rb +100 -0
  77. data/lib/devise/version.rb +3 -0
  78. data/lib/generators/active_record/devise_generator.rb +28 -0
  79. data/lib/generators/active_record/templates/migration.rb +30 -0
  80. data/lib/generators/devise/devise_generator.rb +17 -0
  81. data/lib/generators/devise/install_generator.rb +24 -0
  82. data/lib/generators/devise/orm_helpers.rb +24 -0
  83. data/lib/generators/devise/views_generator.rb +63 -0
  84. data/lib/generators/mongoid/devise_generator.rb +17 -0
  85. data/lib/generators/templates/README +25 -0
  86. data/lib/generators/templates/devise.rb +168 -0
  87. data/test/controllers/helpers_test.rb +220 -0
  88. data/test/controllers/internal_helpers_test.rb +56 -0
  89. data/test/controllers/url_helpers_test.rb +59 -0
  90. data/test/devise_test.rb +65 -0
  91. data/test/encryptors_test.rb +30 -0
  92. data/test/failure_app_test.rb +148 -0
  93. data/test/integration/authenticatable_test.rb +424 -0
  94. data/test/integration/confirmable_test.rb +104 -0
  95. data/test/integration/database_authenticatable_test.rb +38 -0
  96. data/test/integration/http_authenticatable_test.rb +64 -0
  97. data/test/integration/lockable_test.rb +109 -0
  98. data/test/integration/oauthable_test.rb +258 -0
  99. data/test/integration/recoverable_test.rb +141 -0
  100. data/test/integration/registerable_test.rb +179 -0
  101. data/test/integration/rememberable_test.rb +179 -0
  102. data/test/integration/timeoutable_test.rb +80 -0
  103. data/test/integration/token_authenticatable_test.rb +99 -0
  104. data/test/integration/trackable_test.rb +64 -0
  105. data/test/mailers/confirmation_instructions_test.rb +84 -0
  106. data/test/mailers/reset_password_instructions_test.rb +72 -0
  107. data/test/mailers/unlock_instructions_test.rb +66 -0
  108. data/test/mapping_test.rb +95 -0
  109. data/test/models/confirmable_test.rb +221 -0
  110. data/test/models/database_authenticatable_test.rb +82 -0
  111. data/test/models/encryptable_test.rb +65 -0
  112. data/test/models/lockable_test.rb +204 -0
  113. data/test/models/oauthable_test.rb +21 -0
  114. data/test/models/recoverable_test.rb +155 -0
  115. data/test/models/rememberable_test.rb +271 -0
  116. data/test/models/timeoutable_test.rb +28 -0
  117. data/test/models/token_authenticatable_test.rb +37 -0
  118. data/test/models/trackable_test.rb +5 -0
  119. data/test/models/validatable_test.rb +99 -0
  120. data/test/models_test.rb +77 -0
  121. data/test/oauth/config_test.rb +44 -0
  122. data/test/oauth/url_helpers_test.rb +47 -0
  123. data/test/orm/active_record.rb +9 -0
  124. data/test/orm/mongoid.rb +10 -0
  125. data/test/rails_app/app/active_record/admin.rb +6 -0
  126. data/test/rails_app/app/active_record/shim.rb +2 -0
  127. data/test/rails_app/app/active_record/user.rb +8 -0
  128. data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
  129. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  130. data/test/rails_app/app/controllers/application_controller.rb +9 -0
  131. data/test/rails_app/app/controllers/home_controller.rb +12 -0
  132. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
  133. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
  134. data/test/rails_app/app/controllers/users_controller.rb +18 -0
  135. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  136. data/test/rails_app/app/mongoid/admin.rb +9 -0
  137. data/test/rails_app/app/mongoid/shim.rb +24 -0
  138. data/test/rails_app/app/mongoid/user.rb +10 -0
  139. data/test/rails_app/config/application.rb +35 -0
  140. data/test/rails_app/config/boot.rb +13 -0
  141. data/test/rails_app/config/environment.rb +5 -0
  142. data/test/rails_app/config/environments/development.rb +19 -0
  143. data/test/rails_app/config/environments/production.rb +33 -0
  144. data/test/rails_app/config/environments/test.rb +33 -0
  145. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  146. data/test/rails_app/config/initializers/devise.rb +172 -0
  147. data/test/rails_app/config/initializers/inflections.rb +2 -0
  148. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  149. data/test/rails_app/config/routes.rb +54 -0
  150. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +31 -0
  151. data/test/rails_app/db/schema.rb +52 -0
  152. data/test/rails_app/lib/shared_admin.rb +9 -0
  153. data/test/rails_app/lib/shared_user.rb +48 -0
  154. data/test/routes_test.rb +189 -0
  155. data/test/support/assertions.rb +24 -0
  156. data/test/support/helpers.rb +60 -0
  157. data/test/support/integration.rb +88 -0
  158. data/test/support/webrat/integrations/rails.rb +24 -0
  159. data/test/test_helper.rb +23 -0
  160. data/test/test_helpers_test.rb +101 -0
  161. metadata +335 -0
@@ -0,0 +1,261 @@
1
+ module Devise
2
+ module Controllers
3
+ # Those helpers are convenience methods added to ApplicationController.
4
+ module Helpers
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ helper_method :warden, :signed_in?, :devise_controller?, :anybody_signed_in?
9
+ end
10
+
11
+ # Define authentication filters and accessor helpers based on mappings.
12
+ # These filters should be used inside the controllers as before_filters,
13
+ # so you can control the scope of the user who should be signed in to
14
+ # access that specific controller/action.
15
+ # Example:
16
+ #
17
+ # Roles:
18
+ # User
19
+ # Admin
20
+ #
21
+ # Generated methods:
22
+ # authenticate_user! # Signs user in or redirect
23
+ # authenticate_admin! # Signs admin in or redirect
24
+ # user_signed_in? # Checks whether there is an user signed in or not
25
+ # admin_signed_in? # Checks whether there is an admin signed in or not
26
+ # current_user # Current signed in user
27
+ # current_admin # Current signed in admin
28
+ # user_session # Session data available only to the user scope
29
+ # admin_session # Session data available only to the admin scope
30
+ #
31
+ # Use:
32
+ # before_filter :authenticate_user! # Tell devise to use :user map
33
+ # before_filter :authenticate_admin! # Tell devise to use :admin map
34
+ #
35
+ def self.define_helpers(mapping) #:nodoc:
36
+ mapping = mapping.name
37
+
38
+ class_eval <<-METHODS, __FILE__, __LINE__ + 1
39
+ def authenticate_#{mapping}!
40
+ warden.authenticate!(:scope => :#{mapping})
41
+ end
42
+
43
+ def #{mapping}_signed_in?
44
+ !!current_#{mapping}
45
+ end
46
+
47
+ def current_#{mapping}
48
+ @current_#{mapping} ||= warden.authenticate(:scope => :#{mapping})
49
+ end
50
+
51
+ def #{mapping}_session
52
+ current_#{mapping} && warden.session(:#{mapping})
53
+ end
54
+ METHODS
55
+
56
+ ActiveSupport.on_load(:action_controller) do
57
+ helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session"
58
+ end
59
+ end
60
+
61
+ # The main accessor for the warden proxy instance
62
+ def warden
63
+ request.env['warden']
64
+ end
65
+
66
+ # Return true if it's a devise_controller. false to all controllers unless
67
+ # the controllers defined inside devise. Useful if you want to apply a before
68
+ # filter to all controller, except the ones in devise:
69
+ #
70
+ # before_filter :my_filter, :unless => { |c| c.devise_controller? }
71
+ def devise_controller?
72
+ false
73
+ end
74
+
75
+ # Check if the given scope is signed in session, without running
76
+ # authentication hooks.
77
+ def signed_in?(scope)
78
+ warden.authenticate?(:scope => scope)
79
+ end
80
+
81
+ # Check if the any scope is signed in session, without running
82
+ # authentication hooks.
83
+ def anybody_signed_in?
84
+ Devise.mappings.keys.any? { |scope| signed_in?(scope) }
85
+ end
86
+
87
+ # Sign in an user that already was authenticated. This helper is useful for logging
88
+ # users in after sign up.
89
+ #
90
+ # All options given to sign_in is passed forward to the set_user method in warden.
91
+ # The only exception is the :bypass option, which bypass warden callbacks and stores
92
+ # the user straight in session. This option is useful in cases the user is already
93
+ # signed in, but we want to refresh the credentials in session.
94
+ #
95
+ # Examples:
96
+ #
97
+ # sign_in :user, @user # sign_in(scope, resource)
98
+ # sign_in @user # sign_in(resource)
99
+ # sign_in @user, :event => :authentication # sign_in(resource, options)
100
+ # sign_in @user, :bypass => true # sign_in(resource, options)
101
+ #
102
+ def sign_in(resource_or_scope, *args)
103
+ options = args.extract_options!
104
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
105
+ resource = args.last || resource_or_scope
106
+
107
+ if options[:bypass]
108
+ warden.session_serializer.store(resource, scope)
109
+ else
110
+ expire_session_data_after_sign_in!
111
+ warden.set_user(resource, options.merge!(:scope => scope))
112
+ end
113
+ end
114
+
115
+ # Sign out a given user or scope. This helper is useful for signing out an user
116
+ # after deleting accounts.
117
+ #
118
+ # Examples:
119
+ #
120
+ # sign_out :user # sign_out(scope)
121
+ # sign_out @user # sign_out(resource)
122
+ #
123
+ def sign_out(resource_or_scope)
124
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
125
+ warden.user(scope) # Without loading user here, before_logout hook is not called
126
+ warden.raw_session.inspect # Without this inspect here. The session does not clear.
127
+ warden.logout(scope)
128
+ end
129
+
130
+ # Sign out all active users or scopes. This helper is useful for signing out all roles
131
+ # in one click.
132
+ def sign_out_all_scopes
133
+ # Not "warden.logout" since we need to sign_out only devise-defined scopes.
134
+ scopes = Devise.mappings.keys
135
+ scopes.each { |scope| warden.user(scope) }
136
+ warden.raw_session.inspect
137
+ warden.logout(*scopes)
138
+ end
139
+
140
+ # Returns and delete the url stored in the session for the given scope. Useful
141
+ # for giving redirect backs after sign up:
142
+ #
143
+ # Example:
144
+ #
145
+ # redirect_to stored_location_for(:user) || root_path
146
+ #
147
+ def stored_location_for(resource_or_scope)
148
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
149
+ session.delete(:"#{scope}_return_to")
150
+ end
151
+
152
+ # The default url to be used after signing in. This is used by all Devise
153
+ # controllers and you can overwrite it in your ApplicationController to
154
+ # provide a custom hook for a custom resource.
155
+ #
156
+ # By default, it first tries to find a resource_root_path, otherwise it
157
+ # uses the root path. For a user scope, you can define the default url in
158
+ # the following way:
159
+ #
160
+ # map.user_root '/users', :controller => 'users' # creates user_root_path
161
+ #
162
+ # map.namespace :user do |user|
163
+ # user.root :controller => 'users' # creates user_root_path
164
+ # end
165
+ #
166
+ #
167
+ # If the resource root path is not defined, root_path is used. However,
168
+ # if this default is not enough, you can customize it, for example:
169
+ #
170
+ # def after_sign_in_path_for(resource)
171
+ # if resource.is_a?(User) && resource.can_publish?
172
+ # publisher_url
173
+ # else
174
+ # super
175
+ # end
176
+ # end
177
+ #
178
+ def after_sign_in_path_for(resource_or_scope)
179
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
180
+ home_path = :"#{scope}_root_path"
181
+ respond_to?(home_path, true) ? send(home_path) : root_path
182
+ end
183
+
184
+ # The default url to be used after updating a resource. This is used by all Devise
185
+ # controllers and you can overwrite it in your ApplicationController to
186
+ # provide a custom hook for a custom resource.
187
+ #
188
+ # By default, it first tries to find a resource_root_path, otherwise it
189
+ # uses the root path. For a user scope, you can define the default url in
190
+ # the following way:
191
+ #
192
+ # map.user_root '/users', :controller => 'users' # creates user_root_path
193
+ #
194
+ # map.resources :users do |users|
195
+ # users.root # creates user_root_path
196
+ # end
197
+ #
198
+ #
199
+ # If none of these are defined, root_path is used. However, if this default
200
+ # is not enough, you can customize it, for example:
201
+ #
202
+ # def after_update_path_for(resource)
203
+ # if resource.is_a?(User) && resource.can_publish?
204
+ # publisher_url
205
+ # else
206
+ # super
207
+ # end
208
+ # end
209
+ #
210
+ def after_update_path_for(resource_or_scope)
211
+ after_sign_in_path_for(resource_or_scope)
212
+ end
213
+
214
+ # Method used by sessions controller to sign out an user. You can overwrite
215
+ # it in your ApplicationController to provide a custom hook for a custom
216
+ # scope. Notice that differently from +after_sign_in_path_for+ this method
217
+ # receives a symbol with the scope, and not the resource.
218
+ #
219
+ # By default is the root_path.
220
+ def after_sign_out_path_for(resource_or_scope)
221
+ root_path
222
+ end
223
+
224
+ # Sign in an user and tries to redirect first to the stored location and
225
+ # then to the url specified by after_sign_in_path_for. It accepts the same
226
+ # parameters as the sign_in method.
227
+ def sign_in_and_redirect(resource_or_scope, *args)
228
+ options = args.extract_options!
229
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
230
+ resource = args.last || resource_or_scope
231
+ sign_in(scope, resource, options) unless warden.user(scope) == resource
232
+ redirect_for_sign_in(scope, resource)
233
+ end
234
+
235
+ def redirect_for_sign_in(scope, resource) #:nodoc:
236
+ redirect_to stored_location_for(scope) || after_sign_in_path_for(resource)
237
+ end
238
+
239
+ # Sign out an user and tries to redirect to the url specified by
240
+ # after_sign_out_path_for.
241
+ def sign_out_and_redirect(resource_or_scope)
242
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
243
+ if Devise.sign_out_all_scopes
244
+ sign_out_all_scopes
245
+ else
246
+ sign_out(scope)
247
+ end
248
+ redirect_for_sign_out(scope)
249
+ end
250
+
251
+ def redirect_for_sign_out(scope) #:nodoc:
252
+ redirect_to after_sign_out_path_for(scope)
253
+ end
254
+
255
+ # A hook called to expire session data after sign up/in. This is used
256
+ # by a few extensions, like oauth, to expire tokens stored in session.
257
+ def expire_session_data_after_sign_in!
258
+ end
259
+ end
260
+ end
261
+ end
@@ -0,0 +1,113 @@
1
+ module Devise
2
+ module Controllers
3
+ # Those helpers are used only inside Devise controllers and should not be
4
+ # included in ApplicationController since they all depend on the url being
5
+ # accessed.
6
+ module InternalHelpers #:nodoc:
7
+ extend ActiveSupport::Concern
8
+ include Devise::Controllers::ScopedViews
9
+
10
+ included do
11
+ helper DeviseHelper
12
+
13
+ helpers = %w(resource scope_name resource_name signed_in_resource
14
+ resource_class devise_mapping devise_controller?)
15
+ hide_action *helpers
16
+ helper_method *helpers
17
+
18
+ prepend_before_filter :is_devise_resource?
19
+ skip_before_filter *Devise.mappings.keys.map { |m| :"authenticate_#{m}!" }
20
+ end
21
+
22
+ # Gets the actual resource stored in the instance variable
23
+ def resource
24
+ instance_variable_get(:"@#{resource_name}")
25
+ end
26
+
27
+ # Proxy to devise map name
28
+ def resource_name
29
+ devise_mapping.name
30
+ end
31
+ alias :scope_name :resource_name
32
+
33
+ # Proxy to devise map class
34
+ def resource_class
35
+ devise_mapping.to
36
+ end
37
+
38
+ # Returns a signed in resource from session (if one exists)
39
+ def signed_in_resource
40
+ warden.authenticate(:scope => resource_name)
41
+ end
42
+
43
+ # Attempt to find the mapped route for devise based on request path
44
+ def devise_mapping
45
+ @devise_mapping ||= request.env["devise.mapping"]
46
+ end
47
+
48
+ # Overwrites devise_controller? to return true
49
+ def devise_controller?
50
+ true
51
+ end
52
+
53
+ protected
54
+
55
+ # Checks whether it's a devise mapped resource or not.
56
+ def is_devise_resource? #:nodoc:
57
+ unknown_action!("Could not find devise mapping for #{request.fullpath}.") unless devise_mapping
58
+ end
59
+
60
+ def unknown_action!(msg)
61
+ logger.debug "[Devise] #{msg}" if logger
62
+ raise ActionController::UnknownAction, msg
63
+ end
64
+
65
+ # Sets the resource creating an instance variable
66
+ def resource=(new_resource)
67
+ instance_variable_set(:"@#{resource_name}", new_resource)
68
+ end
69
+
70
+ # Build a devise resource.
71
+ def build_resource(hash=nil)
72
+ hash ||= params[resource_name] || {}
73
+ self.resource = resource_class.new(hash)
74
+ end
75
+
76
+ # Helper for use in before_filters where no authentication is required.
77
+ #
78
+ # Example:
79
+ # before_filter :require_no_authentication, :only => :new
80
+ def require_no_authentication
81
+ if warden.authenticated?(resource_name)
82
+ resource = warden.user(resource_name)
83
+ redirect_to after_sign_in_path_for(resource)
84
+ end
85
+ end
86
+
87
+ # Sets the flash message with :key, using I18n. By default you are able
88
+ # to setup your messages using specific resource scope, and if no one is
89
+ # found we look to default scope.
90
+ # Example (i18n locale file):
91
+ #
92
+ # en:
93
+ # devise:
94
+ # passwords:
95
+ # #default_scope_messages - only if resource_scope is not found
96
+ # user:
97
+ # #resource_scope_messages
98
+ #
99
+ # Please refer to README or en.yml locale file to check what messages are
100
+ # available.
101
+ def set_flash_message(key, kind, options={}) #:nodoc:
102
+ options[:scope] = "devise.#{controller_name}"
103
+ options[:default] = Array(options[:default]).unshift(kind.to_sym)
104
+ options[:resource_name] = resource_name
105
+ flash[key] = I18n.t("#{resource_name}.#{kind}", options)
106
+ end
107
+
108
+ def clean_up_passwords(object) #:nodoc:
109
+ object.clean_up_passwords if object.respond_to?(:clean_up_passwords)
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,33 @@
1
+ module Devise
2
+ module Controllers
3
+ module ScopedViews
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def scoped_views?
8
+ defined?(@scoped_views) ? @scoped_views : Devise.scoped_views
9
+ end
10
+
11
+ def scoped_views=(value)
12
+ @scoped_views = value
13
+ end
14
+ end
15
+
16
+ protected
17
+
18
+ # Render a view for the specified scope. Turned off by default.
19
+ # Accepts just :controller as option.
20
+ def render_with_scope(action, path=self.controller_path)
21
+ if self.class.scoped_views?
22
+ begin
23
+ render :template => "#{devise_mapping.plural}/#{path.split("/").last}/#{action}"
24
+ rescue ActionView::MissingTemplate
25
+ render :template => "#{path}/#{action}"
26
+ end
27
+ else
28
+ render :template => "#{path}/#{action}"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,39 @@
1
+ module Devise
2
+ module Controllers
3
+ # Create url helpers to be used with resource/scope configuration. Acts as
4
+ # proxies to the generated routes created by devise.
5
+ # Resource param can be a string or symbol, a class, or an instance object.
6
+ # Example using a :user resource:
7
+ #
8
+ # new_session_path(:user) => new_user_session_path
9
+ # session_path(:user) => user_session_path
10
+ # destroy_session_path(:user) => destroy_user_session_path
11
+ #
12
+ # new_password_path(:user) => new_user_password_path
13
+ # password_path(:user) => user_password_path
14
+ # edit_password_path(:user) => edit_user_password_path
15
+ #
16
+ # new_confirmation_path(:user) => new_user_confirmation_path
17
+ # confirmation_path(:user) => user_confirmation_path
18
+ #
19
+ # Those helpers are added to your ApplicationController.
20
+ module UrlHelpers
21
+
22
+ Devise::URL_HELPERS.each do |module_name, actions|
23
+ [:path, :url].each do |path_or_url|
24
+ actions.each do |action|
25
+ action = action ? "#{action}_" : ""
26
+
27
+ class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
28
+ def #{action}#{module_name}_#{path_or_url}(resource_or_scope, *args)
29
+ scope = Devise::Mapping.find_scope!(resource_or_scope)
30
+ send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
31
+ end
32
+ URL_HELPERS
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,19 @@
1
+ require "digest/sha2"
2
+
3
+ module Devise
4
+ module Encryptors
5
+ # = AuthlogicSha512
6
+ # Simulates Authlogic's default encryption mechanism.
7
+ # Warning: it uses Devise's stretches configuration to port Authlogic's one. Should be set to 20 in the initializer to silumate
8
+ # the default behavior.
9
+ class AuthlogicSha512 < Base
10
+ # Gererates a default password digest based on salt, pepper and the
11
+ # incoming password.
12
+ def self.digest(password, stretches, salt, pepper)
13
+ digest = [password, salt].flatten.join('')
14
+ stretches.times { digest = Digest::SHA512.hexdigest(digest) }
15
+ digest
16
+ end
17
+ end
18
+ end
19
+ end