mongoid-devise 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +333 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +260 -0
- data/Rakefile +53 -0
- data/TODO +2 -0
- data/app/controllers/confirmations_controller.rb +33 -0
- data/app/controllers/passwords_controller.rb +42 -0
- data/app/controllers/registrations_controller.rb +55 -0
- data/app/controllers/sessions_controller.rb +45 -0
- data/app/controllers/unlocks_controller.rb +33 -0
- data/app/models/devise_mailer.rb +68 -0
- data/app/views/confirmations/new.html.erb +12 -0
- data/app/views/devise_mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise_mailer/unlock_instructions.html.erb +7 -0
- data/app/views/passwords/edit.html.erb +16 -0
- data/app/views/passwords/new.html.erb +12 -0
- data/app/views/registrations/edit.html.erb +25 -0
- data/app/views/registrations/new.html.erb +17 -0
- data/app/views/sessions/new.html.erb +17 -0
- data/app/views/shared/_devise_links.erb +19 -0
- data/app/views/unlocks/new.html.erb +12 -0
- data/generators/devise/USAGE +5 -0
- data/generators/devise/devise_generator.rb +15 -0
- data/generators/devise/lib/route_devise.rb +32 -0
- data/generators/devise/templates/migration.rb +23 -0
- data/generators/devise/templates/model.rb +9 -0
- data/generators/devise_install/USAGE +3 -0
- data/generators/devise_install/devise_install_generator.rb +15 -0
- data/generators/devise_install/templates/README +18 -0
- data/generators/devise_install/templates/devise.rb +102 -0
- data/generators/devise_views/USAGE +3 -0
- data/generators/devise_views/devise_views_generator.rb +21 -0
- data/init.rb +2 -0
- data/lib/devise.rb +253 -0
- data/lib/devise/controllers/helpers.rb +200 -0
- data/lib/devise/controllers/internal_helpers.rb +129 -0
- data/lib/devise/controllers/url_helpers.rb +41 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/bcrypt.rb +21 -0
- data/lib/devise/encryptors/clearance_sha1.rb +19 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +27 -0
- data/lib/devise/encryptors/sha512.rb +27 -0
- data/lib/devise/failure_app.rb +65 -0
- data/lib/devise/hooks/activatable.rb +15 -0
- data/lib/devise/hooks/rememberable.rb +30 -0
- data/lib/devise/hooks/timeoutable.rb +18 -0
- data/lib/devise/hooks/trackable.rb +18 -0
- data/lib/devise/locales/en.yml +35 -0
- data/lib/devise/mapping.rb +131 -0
- data/lib/devise/models.rb +112 -0
- data/lib/devise/models/activatable.rb +16 -0
- data/lib/devise/models/authenticatable.rb +146 -0
- data/lib/devise/models/confirmable.rb +172 -0
- data/lib/devise/models/http_authenticatable.rb +21 -0
- data/lib/devise/models/lockable.rb +160 -0
- data/lib/devise/models/recoverable.rb +80 -0
- data/lib/devise/models/registerable.rb +8 -0
- data/lib/devise/models/rememberable.rb +94 -0
- data/lib/devise/models/timeoutable.rb +28 -0
- data/lib/devise/models/token_authenticatable.rb +89 -0
- data/lib/devise/models/trackable.rb +16 -0
- data/lib/devise/models/validatable.rb +48 -0
- data/lib/devise/orm/active_record.rb +41 -0
- data/lib/devise/orm/data_mapper.rb +83 -0
- data/lib/devise/orm/mongo_mapper.rb +51 -0
- data/lib/devise/orm/mongoid.rb +60 -0
- data/lib/devise/rails.rb +14 -0
- data/lib/devise/rails/routes.rb +125 -0
- data/lib/devise/rails/warden_compat.rb +25 -0
- data/lib/devise/schema.rb +65 -0
- data/lib/devise/strategies/authenticatable.rb +36 -0
- data/lib/devise/strategies/base.rb +16 -0
- data/lib/devise/strategies/http_authenticatable.rb +49 -0
- data/lib/devise/strategies/rememberable.rb +37 -0
- data/lib/devise/strategies/token_authenticatable.rb +37 -0
- data/lib/devise/test_helpers.rb +86 -0
- data/lib/devise/version.rb +3 -0
- data/test/controllers/helpers_test.rb +177 -0
- data/test/controllers/internal_helpers_test.rb +55 -0
- data/test/controllers/url_helpers_test.rb +47 -0
- data/test/devise_test.rb +69 -0
- data/test/encryptors_test.rb +31 -0
- data/test/failure_app_test.rb +44 -0
- data/test/integration/authenticatable_test.rb +271 -0
- data/test/integration/confirmable_test.rb +97 -0
- data/test/integration/http_authenticatable_test.rb +44 -0
- data/test/integration/lockable_test.rb +83 -0
- data/test/integration/recoverable_test.rb +141 -0
- data/test/integration/registerable_test.rb +130 -0
- data/test/integration/rememberable_test.rb +63 -0
- data/test/integration/timeoutable_test.rb +68 -0
- data/test/integration/token_authenticatable_test.rb +55 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +80 -0
- data/test/mailers/reset_password_instructions_test.rb +68 -0
- data/test/mailers/unlock_instructions_test.rb +62 -0
- data/test/mapping_test.rb +153 -0
- data/test/models/authenticatable_test.rb +180 -0
- data/test/models/confirmable_test.rb +228 -0
- data/test/models/lockable_test.rb +202 -0
- data/test/models/recoverable_test.rb +138 -0
- data/test/models/rememberable_test.rb +135 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +51 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +106 -0
- data/test/models_test.rb +56 -0
- data/test/orm/active_record.rb +31 -0
- data/test/orm/mongo_mapper.rb +20 -0
- data/test/orm/mongoid.rb +22 -0
- data/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +10 -0
- data/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/app/controllers/users_controller.rb +16 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongo_mapper/admin.rb +9 -0
- data/test/rails_app/app/mongo_mapper/user.rb +8 -0
- data/test/rails_app/app/mongoid/admin.rb +9 -0
- data/test/rails_app/app/mongoid/user.rb +8 -0
- data/test/rails_app/config/boot.rb +110 -0
- data/test/rails_app/config/environment.rb +42 -0
- data/test/rails_app/config/environments/development.rb +17 -0
- data/test/rails_app/config/environments/production.rb +28 -0
- data/test/rails_app/config/environments/test.rb +28 -0
- data/test/rails_app/config/initializers/devise.rb +79 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
- data/test/rails_app/config/initializers/session_store.rb +15 -0
- data/test/rails_app/config/routes.rb +21 -0
- data/test/routes_test.rb +110 -0
- data/test/support/assertions_helper.rb +37 -0
- data/test/support/integration_tests_helper.rb +71 -0
- data/test/support/test_silencer.rb +5 -0
- data/test/support/tests_helper.rb +39 -0
- data/test/test_helper.rb +21 -0
- data/test/test_helpers_test.rb +57 -0
- metadata +216 -0
@@ -0,0 +1,200 @@
|
|
1
|
+
module Devise
|
2
|
+
module Controllers
|
3
|
+
# Those helpers are convenience methods added to ApplicationController.
|
4
|
+
module Helpers
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.class_eval do
|
8
|
+
helper_method :warden, :signed_in?, :devise_controller?,
|
9
|
+
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
|
10
|
+
|
11
|
+
# Use devise default_url_options. We have to declare it here to overwrite
|
12
|
+
# default definitions.
|
13
|
+
def default_url_options(options=nil)
|
14
|
+
Devise::Mapping.default_url_options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# The main accessor for the warden proxy instance
|
20
|
+
def warden
|
21
|
+
request.env['warden']
|
22
|
+
end
|
23
|
+
|
24
|
+
# Return true if it's a devise_controller. false to all controllers unless
|
25
|
+
# the controllers defined inside devise. Useful if you want to apply a before
|
26
|
+
# filter to all controller, except the ones in devise:
|
27
|
+
#
|
28
|
+
# before_filter :my_filter, :unless => { |c| c.devise_controller? }
|
29
|
+
def devise_controller?
|
30
|
+
false
|
31
|
+
end
|
32
|
+
|
33
|
+
# Attempts to authenticate the given scope by running authentication hooks,
|
34
|
+
# but does not redirect in case of failures.
|
35
|
+
def authenticate(scope)
|
36
|
+
warden.authenticate(:scope => scope)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Attempts to authenticate the given scope by running authentication hooks,
|
40
|
+
# redirecting in case of failures.
|
41
|
+
def authenticate!(scope)
|
42
|
+
warden.authenticate!(:scope => scope)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Check if the given scope is signed in session, without running
|
46
|
+
# authentication hooks.
|
47
|
+
def signed_in?(scope)
|
48
|
+
warden.authenticate?(:scope => scope)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Sign in an user that already was authenticated. This helper is useful for logging
|
52
|
+
# users in after sign up.
|
53
|
+
#
|
54
|
+
# Examples:
|
55
|
+
#
|
56
|
+
# sign_in :user, @user # sign_in(scope, resource)
|
57
|
+
# sign_in @user # sign_in(resource)
|
58
|
+
#
|
59
|
+
def sign_in(resource_or_scope, resource=nil)
|
60
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
61
|
+
resource ||= resource_or_scope
|
62
|
+
warden.set_user(resource, :scope => scope)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Sign out a given user or scope. This helper is useful for signing out an user
|
66
|
+
# after deleting accounts.
|
67
|
+
#
|
68
|
+
# Examples:
|
69
|
+
#
|
70
|
+
# sign_out :user # sign_out(scope)
|
71
|
+
# sign_out @user # sign_out(resource)
|
72
|
+
#
|
73
|
+
def sign_out(resource_or_scope)
|
74
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
75
|
+
warden.user(scope) # Without loading user here, before_logout hook is not called
|
76
|
+
warden.raw_session.inspect # Without this inspect here. The session does not clear.
|
77
|
+
warden.logout(scope)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns and delete the url stored in the session for the given scope. Useful
|
81
|
+
# for giving redirect backs after sign up:
|
82
|
+
#
|
83
|
+
# Example:
|
84
|
+
#
|
85
|
+
# redirect_to stored_location_for(:user) || root_path
|
86
|
+
#
|
87
|
+
def stored_location_for(resource_or_scope)
|
88
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
89
|
+
session.delete(:"#{scope}.return_to")
|
90
|
+
end
|
91
|
+
|
92
|
+
# The default url to be used after signing in. This is used by all Devise
|
93
|
+
# controllers and you can overwrite it in your ApplicationController to
|
94
|
+
# provide a custom hook for a custom resource.
|
95
|
+
#
|
96
|
+
# By default, it first tries to find a resource_root_path, otherwise it
|
97
|
+
# uses the root path. For a user scope, you can define the default url in
|
98
|
+
# the following way:
|
99
|
+
#
|
100
|
+
# map.user_root '/users', :controller => 'users' # creates user_root_path
|
101
|
+
#
|
102
|
+
# map.resources :users do |users|
|
103
|
+
# users.root # creates user_root_path
|
104
|
+
# end
|
105
|
+
#
|
106
|
+
#
|
107
|
+
# If none of these are defined, root_path is used. However, if this default
|
108
|
+
# is not enough, you can customize it, for example:
|
109
|
+
#
|
110
|
+
# def after_sign_in_path_for(resource)
|
111
|
+
# if resource.is_a?(User) && resource.can_publish?
|
112
|
+
# publisher_url
|
113
|
+
# else
|
114
|
+
# super
|
115
|
+
# end
|
116
|
+
# end
|
117
|
+
#
|
118
|
+
def after_sign_in_path_for(resource_or_scope)
|
119
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
120
|
+
home_path = :"#{scope}_root_path"
|
121
|
+
respond_to?(home_path, true) ? send(home_path) : root_path
|
122
|
+
end
|
123
|
+
|
124
|
+
# Method used by sessions controller to sign out an user. You can overwrite
|
125
|
+
# it in your ApplicationController to provide a custom hook for a custom
|
126
|
+
# scope. Notice that differently from +after_sign_in_path_for+ this method
|
127
|
+
# receives a symbol with the scope, and not the resource.
|
128
|
+
#
|
129
|
+
# By default is the root_path.
|
130
|
+
def after_sign_out_path_for(resource_or_scope)
|
131
|
+
root_path
|
132
|
+
end
|
133
|
+
|
134
|
+
# Sign in an user and tries to redirect first to the stored location and
|
135
|
+
# then to the url specified by after_sign_in_path_for.
|
136
|
+
#
|
137
|
+
# If just a symbol is given, consider that the user was already signed in
|
138
|
+
# through other means and just perform the redirection.
|
139
|
+
def sign_in_and_redirect(resource_or_scope, resource=nil, skip=false)
|
140
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
141
|
+
resource ||= resource_or_scope
|
142
|
+
sign_in(scope, resource) unless skip
|
143
|
+
redirect_to stored_location_for(scope) || after_sign_in_path_for(resource)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Sign out an user and tries to redirect to the url specified by
|
147
|
+
# after_sign_out_path_for.
|
148
|
+
def sign_out_and_redirect(resource_or_scope)
|
149
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
150
|
+
sign_out(scope)
|
151
|
+
redirect_to after_sign_out_path_for(scope)
|
152
|
+
end
|
153
|
+
|
154
|
+
# Define authentication filters and accessor helpers based on mappings.
|
155
|
+
# These filters should be used inside the controllers as before_filters,
|
156
|
+
# so you can control the scope of the user who should be signed in to
|
157
|
+
# access that specific controller/action.
|
158
|
+
# Example:
|
159
|
+
#
|
160
|
+
# Maps:
|
161
|
+
# User => :authenticatable
|
162
|
+
# Admin => :authenticatable
|
163
|
+
#
|
164
|
+
# Generated methods:
|
165
|
+
# authenticate_user! # Signs user in or redirect
|
166
|
+
# authenticate_admin! # Signs admin in or redirect
|
167
|
+
# user_signed_in? # Checks whether there is an user signed in or not
|
168
|
+
# admin_signed_in? # Checks whether there is an admin signed in or not
|
169
|
+
# current_user # Current signed in user
|
170
|
+
# current_admin # Currend signed in admin
|
171
|
+
# user_session # Session data available only to the user scope
|
172
|
+
# admin_session # Session data available only to the admin scope
|
173
|
+
#
|
174
|
+
# Use:
|
175
|
+
# before_filter :authenticate_user! # Tell devise to use :user map
|
176
|
+
# before_filter :authenticate_admin! # Tell devise to use :admin map
|
177
|
+
#
|
178
|
+
Devise.mappings.each_key do |mapping|
|
179
|
+
class_eval <<-METHODS, __FILE__, __LINE__ + 1
|
180
|
+
def authenticate_#{mapping}!
|
181
|
+
warden.authenticate!(:scope => :#{mapping})
|
182
|
+
end
|
183
|
+
|
184
|
+
def #{mapping}_signed_in?
|
185
|
+
warden.authenticate?(:scope => :#{mapping})
|
186
|
+
end
|
187
|
+
|
188
|
+
def current_#{mapping}
|
189
|
+
@current_#{mapping} ||= warden.authenticate(:scope => :#{mapping})
|
190
|
+
end
|
191
|
+
|
192
|
+
def #{mapping}_session
|
193
|
+
current_#{mapping} && warden.session(:#{mapping})
|
194
|
+
end
|
195
|
+
METHODS
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
@@ -0,0 +1,129 @@
|
|
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
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.class_eval do
|
10
|
+
extend ScopedViews
|
11
|
+
unloadable
|
12
|
+
|
13
|
+
helper_method :resource, :scope_name, :resource_name, :resource_class, :devise_mapping, :devise_controller?
|
14
|
+
hide_action :resource, :scope_name, :resource_name, :resource_class, :devise_mapping, :devise_controller?
|
15
|
+
|
16
|
+
skip_before_filter *Devise.mappings.keys.map { |m| :"authenticate_#{m}!" }
|
17
|
+
before_filter :is_devise_resource?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module ScopedViews
|
22
|
+
def scoped_views
|
23
|
+
defined?(@scoped_views) ? @scoped_views : Devise.scoped_views
|
24
|
+
end
|
25
|
+
|
26
|
+
def scoped_views=(value)
|
27
|
+
@scoped_views = value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Gets the actual resource stored in the instance variable
|
32
|
+
def resource
|
33
|
+
instance_variable_get(:"@#{resource_name}")
|
34
|
+
end
|
35
|
+
|
36
|
+
# Proxy to devise map name
|
37
|
+
def resource_name
|
38
|
+
devise_mapping.name
|
39
|
+
end
|
40
|
+
alias :scope_name :resource_name
|
41
|
+
|
42
|
+
# Proxy to devise map class
|
43
|
+
def resource_class
|
44
|
+
devise_mapping.to
|
45
|
+
end
|
46
|
+
|
47
|
+
# Attempt to find the mapped route for devise based on request path
|
48
|
+
def devise_mapping
|
49
|
+
@devise_mapping ||= begin
|
50
|
+
mapping = Devise::Mapping.find_by_path(request.path)
|
51
|
+
mapping ||= Devise.mappings[Devise.default_scope] if Devise.use_default_scope
|
52
|
+
mapping
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Overwrites devise_controller? to return true
|
57
|
+
def devise_controller?
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
61
|
+
protected
|
62
|
+
|
63
|
+
# Checks whether it's a devise mapped resource or not.
|
64
|
+
def is_devise_resource? #:nodoc:
|
65
|
+
raise ActionController::UnknownAction unless devise_mapping && devise_mapping.allows?(controller_name)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Sets the resource creating an instance variable
|
69
|
+
def resource=(new_resource)
|
70
|
+
instance_variable_set(:"@#{resource_name}", new_resource)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Build a devise resource.
|
74
|
+
def build_resource
|
75
|
+
self.resource ||= resource_class.new(params[resource_name] || {})
|
76
|
+
end
|
77
|
+
|
78
|
+
# Helper for use in before_filters where no authentication is required.
|
79
|
+
#
|
80
|
+
# Example:
|
81
|
+
# before_filter :require_no_authentication, :only => :new
|
82
|
+
def require_no_authentication
|
83
|
+
redirect_to after_sign_in_path_for(resource_name) if warden.authenticated?(resource_name)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Sets the flash message with :key, using I18n. By default you are able
|
87
|
+
# to setup your messages using specific resource scope, and if no one is
|
88
|
+
# found we look to default scope.
|
89
|
+
# Example (i18n locale file):
|
90
|
+
#
|
91
|
+
# en:
|
92
|
+
# devise:
|
93
|
+
# passwords:
|
94
|
+
# #default_scope_messages - only if resource_scope is not found
|
95
|
+
# user:
|
96
|
+
# #resource_scope_messages
|
97
|
+
#
|
98
|
+
# Please refer to README or en.yml locale file to check what messages are
|
99
|
+
# available.
|
100
|
+
def set_flash_message(key, kind, now=false)
|
101
|
+
flash_hash = now ? flash.now : flash
|
102
|
+
flash_hash[key] = I18n.t(:"#{resource_name}.#{kind}",
|
103
|
+
:scope => [:devise, controller_name.to_sym], :default => kind)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Shortcut to set flash.now message. Same rules applied from set_flash_message
|
107
|
+
def set_now_flash_message(key, kind)
|
108
|
+
set_flash_message(key, kind, true)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Render a view for the specified scope. Turned off by default.
|
112
|
+
# Accepts just :controller as option.
|
113
|
+
def render_with_scope(action, options={})
|
114
|
+
controller_name = options.delete(:controller) || self.controller_name
|
115
|
+
|
116
|
+
if self.class.scoped_views
|
117
|
+
begin
|
118
|
+
render :template => "#{controller_name}/#{devise_mapping.as}/#{action}"
|
119
|
+
rescue ActionView::MissingTemplate
|
120
|
+
render action, :controller => controller_name
|
121
|
+
end
|
122
|
+
else
|
123
|
+
render action, :controller => controller_name
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,41 @@
|
|
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::ROUTES.each do |module_name|
|
23
|
+
[:path, :url].each do |path_or_url|
|
24
|
+
actions = [ nil, :new_ ]
|
25
|
+
actions << :edit_ if [:password, :registration].include?(module_name)
|
26
|
+
actions << :destroy_ if [:session].include?(module_name)
|
27
|
+
|
28
|
+
actions.each do |action|
|
29
|
+
class_eval <<-URL_HELPERS, __FILE__, __LINE__ + 1
|
30
|
+
def #{action}#{module_name}_#{path_or_url}(resource_or_scope, *args)
|
31
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
32
|
+
send("#{action}\#{scope}_#{module_name}_#{path_or_url}", *args)
|
33
|
+
end
|
34
|
+
URL_HELPERS
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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
|
+
|
11
|
+
# Gererates a default password digest based on salt, pepper and the
|
12
|
+
# incoming password.
|
13
|
+
def self.digest(password, stretches, salt, pepper)
|
14
|
+
digest = [password, salt].flatten.join('')
|
15
|
+
stretches.times { digest = Digest::SHA512.hexdigest(digest) }
|
16
|
+
digest
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Devise
|
2
|
+
# Implements a way of adding different encryptions.
|
3
|
+
# The class should implement a self.digest method that taks the following params:
|
4
|
+
# - password
|
5
|
+
# - stretches: the number of times the encryption will be applied
|
6
|
+
# - salt: the password salt as defined by devise
|
7
|
+
# - pepper: Devise config option
|
8
|
+
#
|
9
|
+
module Encryptors
|
10
|
+
class Base
|
11
|
+
def self.digest
|
12
|
+
raise NotImplemented
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.salt
|
16
|
+
Devise.friendly_token
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "bcrypt"
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Encryptors
|
5
|
+
# = BCrypt
|
6
|
+
# Uses the BCrypt hash algorithm to encrypt passwords.
|
7
|
+
class Bcrypt < Base
|
8
|
+
|
9
|
+
# Gererates a default password digest based on stretches, salt, pepper and the
|
10
|
+
# incoming password. We don't strech it ourselves since BCrypt does so internally.
|
11
|
+
def self.digest(password, stretches, salt, pepper)
|
12
|
+
::BCrypt::Engine.hash_secret([password, pepper].join, salt, stretches)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.salt
|
16
|
+
::BCrypt::Engine.generate_salt
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "digest/sha1"
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Encryptors
|
5
|
+
# = ClearanceSha1
|
6
|
+
# Simulates Clearance's default encryption mechanism.
|
7
|
+
# Warning: it uses Devise's pepper to port the concept of REST_AUTH_SITE_KEY
|
8
|
+
# Warning: it uses Devise's stretches configuration to port the concept of REST_AUTH_DIGEST_STRETCHES
|
9
|
+
class ClearanceSha1 < Base
|
10
|
+
|
11
|
+
# Gererates a default password digest based on salt, pepper and the
|
12
|
+
# incoming password.
|
13
|
+
def self.digest(password, stretches, salt, pepper)
|
14
|
+
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|