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.
- data/CHANGELOG.rdoc +500 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +335 -0
- data/app/controllers/devise/confirmations_controller.rb +33 -0
- data/app/controllers/devise/oauth_callbacks_controller.rb +4 -0
- data/app/controllers/devise/passwords_controller.rb +41 -0
- data/app/controllers/devise/registrations_controller.rb +75 -0
- data/app/controllers/devise/sessions_controller.rb +23 -0
- data/app/controllers/devise/unlocks_controller.rb +34 -0
- data/app/helpers/devise_helper.rb +17 -0
- data/app/mailers/devise/mailer.rb +88 -0
- data/app/views/devise/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/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/app/views/devise/registrations/edit.html.erb +25 -0
- data/app/views/devise/registrations/new.html.erb +18 -0
- data/app/views/devise/sessions/new.html.erb +17 -0
- data/app/views/devise/shared/_links.erb +25 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/config/locales/en.yml +42 -0
- data/lib/devise.rb +371 -0
- data/lib/devise/controllers/helpers.rb +261 -0
- data/lib/devise/controllers/internal_helpers.rb +113 -0
- data/lib/devise/controllers/scoped_views.rb +33 -0
- data/lib/devise/controllers/url_helpers.rb +39 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/clearance_sha1.rb +17 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +25 -0
- data/lib/devise/encryptors/sha512.rb +25 -0
- data/lib/devise/failure_app.rb +126 -0
- data/lib/devise/hooks/activatable.rb +11 -0
- data/lib/devise/hooks/forgetable.rb +12 -0
- data/lib/devise/hooks/rememberable.rb +45 -0
- data/lib/devise/hooks/timeoutable.rb +22 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mapping.rb +105 -0
- data/lib/devise/models.rb +66 -0
- data/lib/devise/models/authenticatable.rb +143 -0
- data/lib/devise/models/confirmable.rb +160 -0
- data/lib/devise/models/database_authenticatable.rb +94 -0
- data/lib/devise/models/encryptable.rb +65 -0
- data/lib/devise/models/lockable.rb +168 -0
- data/lib/devise/models/oauthable.rb +49 -0
- data/lib/devise/models/recoverable.rb +83 -0
- data/lib/devise/models/registerable.rb +21 -0
- data/lib/devise/models/rememberable.rb +122 -0
- data/lib/devise/models/timeoutable.rb +33 -0
- data/lib/devise/models/token_authenticatable.rb +72 -0
- data/lib/devise/models/trackable.rb +30 -0
- data/lib/devise/models/validatable.rb +60 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/oauth.rb +41 -0
- data/lib/devise/oauth/config.rb +33 -0
- data/lib/devise/oauth/helpers.rb +18 -0
- data/lib/devise/oauth/internal_helpers.rb +182 -0
- data/lib/devise/oauth/test_helpers.rb +29 -0
- data/lib/devise/oauth/url_helpers.rb +35 -0
- data/lib/devise/orm/active_record.rb +36 -0
- data/lib/devise/orm/mongo_mapper.rb +46 -0
- data/lib/devise/orm/mongoid.rb +29 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails.rb +67 -0
- data/lib/devise/rails/routes.rb +260 -0
- data/lib/devise/rails/warden_compat.rb +42 -0
- data/lib/devise/schema.rb +96 -0
- data/lib/devise/strategies/authenticatable.rb +150 -0
- data/lib/devise/strategies/base.rb +15 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +51 -0
- data/lib/devise/strategies/token_authenticatable.rb +53 -0
- data/lib/devise/test_helpers.rb +100 -0
- data/lib/devise/version.rb +3 -0
- data/lib/generators/active_record/devise_generator.rb +28 -0
- data/lib/generators/active_record/templates/migration.rb +30 -0
- data/lib/generators/devise/devise_generator.rb +17 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +24 -0
- data/lib/generators/devise/views_generator.rb +63 -0
- data/lib/generators/mongoid/devise_generator.rb +17 -0
- data/lib/generators/templates/README +25 -0
- data/lib/generators/templates/devise.rb +168 -0
- data/test/controllers/helpers_test.rb +220 -0
- data/test/controllers/internal_helpers_test.rb +56 -0
- data/test/controllers/url_helpers_test.rb +59 -0
- data/test/devise_test.rb +65 -0
- data/test/encryptors_test.rb +30 -0
- data/test/failure_app_test.rb +148 -0
- data/test/integration/authenticatable_test.rb +424 -0
- data/test/integration/confirmable_test.rb +104 -0
- data/test/integration/database_authenticatable_test.rb +38 -0
- data/test/integration/http_authenticatable_test.rb +64 -0
- data/test/integration/lockable_test.rb +109 -0
- data/test/integration/oauthable_test.rb +258 -0
- data/test/integration/recoverable_test.rb +141 -0
- data/test/integration/registerable_test.rb +179 -0
- data/test/integration/rememberable_test.rb +179 -0
- data/test/integration/timeoutable_test.rb +80 -0
- data/test/integration/token_authenticatable_test.rb +99 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +84 -0
- data/test/mailers/reset_password_instructions_test.rb +72 -0
- data/test/mailers/unlock_instructions_test.rb +66 -0
- data/test/mapping_test.rb +95 -0
- data/test/models/confirmable_test.rb +221 -0
- data/test/models/database_authenticatable_test.rb +82 -0
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +204 -0
- data/test/models/oauthable_test.rb +21 -0
- data/test/models/recoverable_test.rb +155 -0
- data/test/models/rememberable_test.rb +271 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +37 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +99 -0
- data/test/models_test.rb +77 -0
- data/test/oauth/config_test.rb +44 -0
- data/test/oauth/url_helpers_test.rb +47 -0
- data/test/orm/active_record.rb +9 -0
- data/test/orm/mongoid.rb +10 -0
- data/test/rails_app/app/active_record/admin.rb +6 -0
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +8 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/home_controller.rb +12 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
- data/test/rails_app/app/controllers/users_controller.rb +18 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongoid/admin.rb +9 -0
- data/test/rails_app/app/mongoid/shim.rb +24 -0
- data/test/rails_app/app/mongoid/user.rb +10 -0
- data/test/rails_app/config/application.rb +35 -0
- data/test/rails_app/config/boot.rb +13 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +19 -0
- data/test/rails_app/config/environments/production.rb +33 -0
- data/test/rails_app/config/environments/test.rb +33 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +172 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +54 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +31 -0
- data/test/rails_app/db/schema.rb +52 -0
- data/test/rails_app/lib/shared_admin.rb +9 -0
- data/test/rails_app/lib/shared_user.rb +48 -0
- data/test/routes_test.rb +189 -0
- data/test/support/assertions.rb +24 -0
- data/test/support/helpers.rb +60 -0
- data/test/support/integration.rb +88 -0
- data/test/support/webrat/integrations/rails.rb +24 -0
- data/test/test_helper.rb +23 -0
- data/test/test_helpers_test.rb +101 -0
- metadata +335 -0
|
@@ -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(stretches)
|
|
16
|
+
Devise.friendly_token[0,20]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
# Gererates a default password digest based on salt, pepper and the
|
|
11
|
+
# incoming password.
|
|
12
|
+
def self.digest(password, stretches, salt, pepper)
|
|
13
|
+
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "digest/sha1"
|
|
2
|
+
|
|
3
|
+
module Devise
|
|
4
|
+
module Encryptors
|
|
5
|
+
# = RestfulAuthenticationSha1
|
|
6
|
+
# Simulates Restful Authentication'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. Should be set to 10 in
|
|
9
|
+
# the initializer to silumate the default behavior.
|
|
10
|
+
class RestfulAuthenticationSha1 < Base
|
|
11
|
+
|
|
12
|
+
# Gererates a default password digest based on salt, pepper and the
|
|
13
|
+
# incoming password.
|
|
14
|
+
def self.digest(password, stretches, salt, pepper)
|
|
15
|
+
digest = pepper
|
|
16
|
+
stretches.times { digest = Digest::SHA1.hexdigest([digest, salt, password, pepper].flatten.join('--')) }
|
|
17
|
+
digest
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "digest/sha1"
|
|
2
|
+
|
|
3
|
+
module Devise
|
|
4
|
+
module Encryptors
|
|
5
|
+
# = Sha1
|
|
6
|
+
# Uses the Sha1 hash algorithm to encrypt passwords.
|
|
7
|
+
class Sha1 < Base
|
|
8
|
+
# Gererates a default password digest based on stretches, salt, pepper and the
|
|
9
|
+
# incoming password.
|
|
10
|
+
def self.digest(password, stretches, salt, pepper)
|
|
11
|
+
digest = pepper
|
|
12
|
+
stretches.times { digest = self.secure_digest(salt, digest, password, pepper) }
|
|
13
|
+
digest
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
# Generate a SHA1 digest joining args. Generated token is something like
|
|
19
|
+
# --arg1--arg2--arg3--argN--
|
|
20
|
+
def self.secure_digest(*tokens)
|
|
21
|
+
::Digest::SHA1.hexdigest('--' << tokens.flatten.join('--') << '--')
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require "digest/sha2"
|
|
2
|
+
|
|
3
|
+
module Devise
|
|
4
|
+
module Encryptors
|
|
5
|
+
# = Sha512
|
|
6
|
+
# Uses the Sha512 hash algorithm to encrypt passwords.
|
|
7
|
+
class Sha512 < Base
|
|
8
|
+
# Gererates a default password digest based on salt, pepper and the
|
|
9
|
+
# incoming password.
|
|
10
|
+
def self.digest(password, stretches, salt, pepper)
|
|
11
|
+
digest = pepper
|
|
12
|
+
stretches.times { digest = self.secure_digest(salt, digest, password, pepper) }
|
|
13
|
+
digest
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
# Generate a Sha512 digest joining args. Generated token is something like
|
|
19
|
+
# --arg1--arg2--arg3--argN--
|
|
20
|
+
def self.secure_digest(*tokens)
|
|
21
|
+
::Digest::SHA512.hexdigest('--' << tokens.flatten.join('--') << '--')
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
require "action_controller/metal"
|
|
2
|
+
|
|
3
|
+
module Devise
|
|
4
|
+
# Failure application that will be called every time :warden is thrown from
|
|
5
|
+
# any strategy or hook. Responsible for redirect the user to the sign in
|
|
6
|
+
# page based on current scope and mapping. If no scope is given, redirect
|
|
7
|
+
# to the default_url.
|
|
8
|
+
class FailureApp < ActionController::Metal
|
|
9
|
+
include ActionController::RackDelegation
|
|
10
|
+
include ActionController::UrlFor
|
|
11
|
+
include ActionController::Redirecting
|
|
12
|
+
include Rails.application.routes.url_helpers
|
|
13
|
+
|
|
14
|
+
delegate :flash, :to => :request
|
|
15
|
+
|
|
16
|
+
def self.call(env)
|
|
17
|
+
action(:respond).call(env)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.default_url_options(*args)
|
|
21
|
+
ApplicationController.default_url_options(*args)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def respond
|
|
25
|
+
if http_auth?
|
|
26
|
+
http_auth
|
|
27
|
+
elsif warden_options[:recall]
|
|
28
|
+
recall
|
|
29
|
+
else
|
|
30
|
+
redirect
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def http_auth
|
|
35
|
+
self.status = 401
|
|
36
|
+
self.headers["WWW-Authenticate"] = %(Basic realm=#{Devise.http_authentication_realm.inspect}) if http_auth_header?
|
|
37
|
+
self.content_type = request.format.to_s
|
|
38
|
+
self.response_body = http_auth_body
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def recall
|
|
42
|
+
env["PATH_INFO"] = attempted_path
|
|
43
|
+
flash.now[:alert] = i18n_message(:invalid)
|
|
44
|
+
self.response = recall_app(warden_options[:recall]).call(env)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def redirect
|
|
48
|
+
store_location!
|
|
49
|
+
flash[:alert] = i18n_message unless flash[:notice]
|
|
50
|
+
redirect_to redirect_url
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
protected
|
|
54
|
+
|
|
55
|
+
def i18n_message(default = nil)
|
|
56
|
+
message = warden.message || warden_options[:message] || default || :unauthenticated
|
|
57
|
+
|
|
58
|
+
if message.is_a?(Symbol)
|
|
59
|
+
I18n.t(:"#{scope}.#{message}", :resource_name => scope,
|
|
60
|
+
:scope => "devise.failure", :default => [message, message.to_s])
|
|
61
|
+
else
|
|
62
|
+
message.to_s
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def redirect_url
|
|
67
|
+
send(:"new_#{scope}_session_path")
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Choose whether we should respond in a http authentication fashion,
|
|
71
|
+
# including 401 and optional headers.
|
|
72
|
+
#
|
|
73
|
+
# This method allows the user to explicitly disable http authentication
|
|
74
|
+
# on ajax requests in case they want to redirect on failures instead of
|
|
75
|
+
# handling the errors on their own. This is useful in case your ajax API
|
|
76
|
+
# is the same as your public API and uses a format like JSON (so you
|
|
77
|
+
# cannot mark JSON as a navigational format).
|
|
78
|
+
def http_auth?
|
|
79
|
+
if request.xhr?
|
|
80
|
+
Devise.http_authenticatable_on_xhr
|
|
81
|
+
else
|
|
82
|
+
!Devise.navigational_formats.include?(request.format.to_sym)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# It does not make sense to send authenticate headers in ajax requests
|
|
87
|
+
# or if the user disabled them.
|
|
88
|
+
def http_auth_header?
|
|
89
|
+
Devise.mappings[scope].to.http_authenticatable && !request.xhr?
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def http_auth_body
|
|
93
|
+
method = :"to_#{request.format.to_sym}"
|
|
94
|
+
{}.respond_to?(method) ? { :error => i18n_message }.send(method) : i18n_message
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def recall_app(app)
|
|
98
|
+
controller, action = app.split("#")
|
|
99
|
+
"#{controller.camelize}Controller".constantize.action(action)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def warden
|
|
103
|
+
env['warden']
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def warden_options
|
|
107
|
+
env['warden.options']
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def scope
|
|
111
|
+
@scope ||= warden_options[:scope] || Devise.default_scope
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def attempted_path
|
|
115
|
+
warden_options[:attempted_path]
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Stores requested uri to redirect the user after signing in. We cannot use
|
|
119
|
+
# scoped session provided by warden here, since the user is not authenticated
|
|
120
|
+
# yet, but we still need to store the uri based on scope, so different scopes
|
|
121
|
+
# would never use the same uri to redirect.
|
|
122
|
+
def store_location!
|
|
123
|
+
session["#{scope}_return_to"] = attempted_path if request.get? && !http_auth?
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Deny user access whenever his account is not active yet. All strategies that inherits from
|
|
2
|
+
# Devise::Strategies::Authenticatable and uses the validate already check if the user is active?
|
|
3
|
+
# before actively signing him in. However, we need this as hook to validate the user activity
|
|
4
|
+
# in each request and in case the user is using other strategies beside Devise ones.
|
|
5
|
+
Warden::Manager.after_set_user do |record, warden, options|
|
|
6
|
+
if record && record.respond_to?(:active?) && !record.active?
|
|
7
|
+
scope = options[:scope]
|
|
8
|
+
warden.logout(scope)
|
|
9
|
+
throw :warden, :scope => scope, :message => record.inactive_message
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Before logout hook to forget the user in the given scope, if it responds
|
|
2
|
+
# to forget_me! Also clear remember token to ensure the user won't be
|
|
3
|
+
# remembered again. Notice that we forget the user unless the record is frozen.
|
|
4
|
+
# This avoids forgetting deleted users.
|
|
5
|
+
Warden::Manager.before_logout do |record, warden, options|
|
|
6
|
+
if record.respond_to?(:forget_me!)
|
|
7
|
+
record.forget_me! unless record.frozen?
|
|
8
|
+
cookie_options = Rails.configuration.session_options.slice(:path, :domain, :secure)
|
|
9
|
+
cookie_options.merge!(record.cookie_options)
|
|
10
|
+
warden.cookies.delete("remember_#{options[:scope]}_token", cookie_options)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
module Hooks
|
|
3
|
+
# Overwrite success! in authentication strategies allowing users to be remembered.
|
|
4
|
+
# We choose to implement this as an strategy hook instead of a warden hook to allow a specific
|
|
5
|
+
# strategy (like token authenticatable or facebook authenticatable) to turn off remember_me?
|
|
6
|
+
# cookies.
|
|
7
|
+
module Rememberable #:nodoc:
|
|
8
|
+
def success!(resource)
|
|
9
|
+
super
|
|
10
|
+
|
|
11
|
+
if succeeded? && resource.respond_to?(:remember_me!) && remember_me?
|
|
12
|
+
resource.remember_me!(extend_remember_period?)
|
|
13
|
+
cookies.signed["remember_#{scope}_token"] = cookie_values(resource)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
|
|
19
|
+
def cookie_values(resource)
|
|
20
|
+
options = Rails.configuration.session_options.slice(:path, :domain, :secure)
|
|
21
|
+
options.merge!(resource.cookie_options)
|
|
22
|
+
options.merge!(
|
|
23
|
+
:value => resource.class.serialize_into_cookie(resource),
|
|
24
|
+
:expires => resource.remember_expires_at
|
|
25
|
+
)
|
|
26
|
+
options
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def succeeded?
|
|
30
|
+
@result == :success
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def extend_remember_period?
|
|
34
|
+
false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def remember_me?
|
|
38
|
+
valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me])
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
Devise::Strategies::Authenticatable.send :include, Devise::Hooks::Rememberable
|
|
45
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Each time a record is set we check whether its session has already timed out
|
|
2
|
+
# or not, based on last request time. If so, the record is logged out and
|
|
3
|
+
# redirected to the sign in page. Also, each time the request comes and the
|
|
4
|
+
# record is set, we set the last request time inside it's scoped session to
|
|
5
|
+
# verify timeout in the following request.
|
|
6
|
+
Warden::Manager.after_set_user do |record, warden, options|
|
|
7
|
+
scope = options[:scope]
|
|
8
|
+
|
|
9
|
+
if record && record.respond_to?(:timedout?) && warden.authenticated?(scope)
|
|
10
|
+
last_request_at = warden.session(scope)['last_request_at']
|
|
11
|
+
|
|
12
|
+
if record.timedout?(last_request_at)
|
|
13
|
+
path_checker = Devise::PathChecker.new(warden.env, scope)
|
|
14
|
+
unless path_checker.signing_out?
|
|
15
|
+
warden.logout(scope)
|
|
16
|
+
throw :warden, :scope => scope, :message => :timeout
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
warden.session(scope)['last_request_at'] = Time.now.utc
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# After each sign in, update sign in time, sign in count and sign in IP.
|
|
2
|
+
# This is only triggered when the user is explicitly set (with set_user)
|
|
3
|
+
# and on authentication. Retrieving the user from session (:fetch) does
|
|
4
|
+
# not trigger it.
|
|
5
|
+
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
|
|
6
|
+
if record.respond_to?(:update_tracked_fields!) && warden.authenticated?(options[:scope])
|
|
7
|
+
record.update_tracked_fields!(warden.request)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
# Responsible for handling devise mappings and routes configuration. Each
|
|
3
|
+
# resource configured by devise_for in routes is actually creating a mapping
|
|
4
|
+
# object. You can refer to devise_for in routes for usage options.
|
|
5
|
+
#
|
|
6
|
+
# The required value in devise_for is actually not used internally, but it's
|
|
7
|
+
# inflected to find all other values.
|
|
8
|
+
#
|
|
9
|
+
# map.devise_for :users
|
|
10
|
+
# mapping = Devise.mappings[:user]
|
|
11
|
+
#
|
|
12
|
+
# mapping.name #=> :user
|
|
13
|
+
# # is the scope used in controllers and warden, given in the route as :singular.
|
|
14
|
+
#
|
|
15
|
+
# mapping.as #=> "users"
|
|
16
|
+
# # how the mapping should be search in the path, given in the route as :as.
|
|
17
|
+
#
|
|
18
|
+
# mapping.to #=> User
|
|
19
|
+
# # is the class to be loaded from routes, given in the route as :class_name.
|
|
20
|
+
#
|
|
21
|
+
# mapping.modules #=> [:authenticatable]
|
|
22
|
+
# # is the modules included in the class
|
|
23
|
+
#
|
|
24
|
+
class Mapping #:nodoc:
|
|
25
|
+
attr_reader :singular, :plural, :path, :controllers, :path_names, :class_name, :sign_out_via
|
|
26
|
+
alias :name :singular
|
|
27
|
+
|
|
28
|
+
# Receives an object and find a scope for it. If a scope cannot be found,
|
|
29
|
+
# raises an error. If a symbol is given, it's considered to be the scope.
|
|
30
|
+
def self.find_scope!(duck)
|
|
31
|
+
case duck
|
|
32
|
+
when String, Symbol
|
|
33
|
+
return duck
|
|
34
|
+
when Class
|
|
35
|
+
Devise.mappings.each_value { |m| return m.name if duck <= m.to }
|
|
36
|
+
else
|
|
37
|
+
Devise.mappings.each_value { |m| return m.name if duck.is_a?(m.to) }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
raise "Could not find a valid mapping for #{duck}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def initialize(name, options) #:nodoc:
|
|
44
|
+
@plural = (options[:as] ? "#{options[:as]}_#{name}" : name).to_sym
|
|
45
|
+
@singular = (options[:singular] || @plural.to_s.singularize).to_sym
|
|
46
|
+
|
|
47
|
+
@class_name = (options[:class_name] || name.to_s.classify).to_s
|
|
48
|
+
@ref = ActiveSupport::Dependencies.ref(@class_name)
|
|
49
|
+
|
|
50
|
+
@path = (options[:path] || name).to_s
|
|
51
|
+
@path_prefix = options[:path_prefix]
|
|
52
|
+
|
|
53
|
+
mod = options[:module] || "devise"
|
|
54
|
+
@controllers = Hash.new { |h,k| h[k] = "#{mod}/#{k}" }
|
|
55
|
+
@controllers.merge!(options[:controllers] || {})
|
|
56
|
+
|
|
57
|
+
@path_names = Hash.new { |h,k| h[k] = k.to_s }
|
|
58
|
+
@path_names.merge!(:registration => "")
|
|
59
|
+
@path_names.merge!(options[:path_names] || {})
|
|
60
|
+
|
|
61
|
+
@sign_out_via = options[:sign_out_via] || Devise.sign_out_via
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Return modules for the mapping.
|
|
65
|
+
def modules
|
|
66
|
+
@modules ||= to.respond_to?(:devise_modules) ? to.devise_modules : []
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Gives the class the mapping points to.
|
|
70
|
+
def to
|
|
71
|
+
@ref.get
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def strategies
|
|
75
|
+
@strategies ||= STRATEGIES.values_at(*self.modules).compact.uniq.reverse
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def routes
|
|
79
|
+
@routes ||= ROUTES.values_at(*self.modules).compact.uniq
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def authenticatable?
|
|
83
|
+
@authenticatable ||= self.modules.any? { |m| m.to_s =~ /authenticatable/ }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def fullpath
|
|
87
|
+
"#{@path_prefix}/#{@path}".squeeze("/")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Create magic predicates for verifying what module is activated by this map.
|
|
91
|
+
# Example:
|
|
92
|
+
#
|
|
93
|
+
# def confirmable?
|
|
94
|
+
# self.modules.include?(:confirmable)
|
|
95
|
+
# end
|
|
96
|
+
#
|
|
97
|
+
def self.add_module(m)
|
|
98
|
+
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
|
99
|
+
def #{m}?
|
|
100
|
+
self.modules.include?(:#{m})
|
|
101
|
+
end
|
|
102
|
+
METHOD
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|