devise 1.1.pre2 → 1.1.pre3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- data/CHANGELOG.rdoc +12 -0
- data/Gemfile +3 -3
- data/README.rdoc +3 -2
- data/Rakefile +1 -1
- data/app/controllers/devise/registrations_controller.rb +2 -2
- data/app/views/devise/mailer/confirmation_instructions.html.erb +3 -3
- data/app/views/devise/mailer/reset_password_instructions.html.erb +5 -5
- data/app/views/devise/mailer/unlock_instructions.html.erb +4 -4
- data/lib/devise.rb +12 -24
- data/lib/devise/controllers/helpers.rb +0 -6
- data/lib/devise/failure_app.rb +33 -36
- data/lib/devise/mapping.rb +1 -15
- data/lib/devise/models.rb +9 -6
- data/lib/devise/orm/active_record.rb +8 -11
- data/lib/devise/orm/data_mapper.rb +60 -57
- data/lib/devise/orm/mongo_mapper.rb +36 -26
- data/lib/devise/rails.rb +0 -4
- data/lib/devise/rails/routes.rb +11 -9
- data/lib/devise/strategies/http_authenticatable.rb +7 -1
- data/lib/devise/version.rb +1 -1
- data/lib/generators/devise_install/templates/devise.rb +1 -8
- data/lib/generators/devise_views/devise_views_generator.rb +4 -0
- data/test/controllers/helpers_test.rb +0 -9
- data/test/failure_app_test.rb +9 -12
- data/test/integration/http_authenticatable_test.rb +1 -0
- data/test/integration/registerable_test.rb +2 -2
- data/test/integration/rememberable_test.rb +8 -0
- data/test/mapping_test.rb +3 -32
- data/test/rails_app/app/mongo_mapper/admin.rb +1 -1
- data/test/rails_app/app/mongo_mapper/user.rb +3 -3
- data/test/rails_app/config/initializers/devise.rb +0 -1
- data/test/support/integration.rb +1 -1
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
@@ -4,10 +4,22 @@
|
|
4
4
|
* Rails 3 compatibility.
|
5
5
|
* All controllers and views are namespaced, for example: Devise::SessionsController and "devise/sessions".
|
6
6
|
* You can specify the controller in routes and have specific controllers for each role.
|
7
|
+
* Devise.orm is deprecated. This reduces the required API to hook your ORM with devise.
|
8
|
+
* Use metal for failure app.
|
9
|
+
* HTML e-mails now have proper formatting.
|
10
|
+
* Do not remove options from Datamapper and MongoMapper in find
|
7
11
|
|
8
12
|
* deprecations
|
9
13
|
* Rails 3 compatible only.
|
10
14
|
* Scoped views are no longer "sessions/users/new". Now use "users/sessions/new".
|
15
|
+
* Devise.orm is deprecated, just require "devise/orm/YOUR_ORM" instead.
|
16
|
+
* Devise.default_url_options is deprecated, just modify ApplicationController.default_url_options.
|
17
|
+
|
18
|
+
== 1.0.3
|
19
|
+
|
20
|
+
* enhancements
|
21
|
+
* HTML e-mails now have proper formatting
|
22
|
+
* Do not remove MongoMapper options in find
|
11
23
|
|
12
24
|
== 1.0.2
|
13
25
|
|
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
source "http://gemcutter.org"
|
2
2
|
|
3
3
|
gem "rails", "3.0.0.beta"
|
4
|
-
gem "warden", "0.9.
|
4
|
+
gem "warden", "0.9.4"
|
5
5
|
gem "sqlite3-ruby", :require => "sqlite3"
|
6
6
|
gem "webrat", "0.7"
|
7
7
|
gem "mocha", :require => false
|
@@ -14,5 +14,5 @@ end
|
|
14
14
|
group :mongo_mapper do
|
15
15
|
gem "mongo", "0.18.3"
|
16
16
|
gem "mongo_ext", "0.18.3", :require => false
|
17
|
-
gem "mongo_mapper", "
|
18
|
-
end
|
17
|
+
gem "mongo_mapper", :git => "git://github.com/merbjedi/mongomapper.git", :branch => "rails3"
|
18
|
+
end
|
data/README.rdoc
CHANGED
@@ -271,7 +271,8 @@ We have a long running list of contributors. Check them in the CHANGELOG or do `
|
|
271
271
|
If you discover any bugs or want to drop a line, feel free to create an issue on
|
272
272
|
GitHub or send an e-mail to the mailing list.
|
273
273
|
|
274
|
-
http://github.com/plataformatec/devise/issues
|
275
|
-
http://groups.google.com/group/plataformatec-devise
|
274
|
+
http://github.com/plataformatec/devise/issues |
|
275
|
+
http://groups.google.com/group/plataformatec-devise |
|
276
|
+
http://wiki.github.com/plataformatec/devise/
|
276
277
|
|
277
278
|
MIT License. Copyright 2009 Plataforma Tecnologia. http://blog.plataformatec.com.br
|
data/Rakefile
CHANGED
@@ -45,7 +45,7 @@ begin
|
|
45
45
|
s.authors = ['José Valim', 'Carlos Antônio']
|
46
46
|
s.files = FileList["[A-Z]*", "{app,config,lib}/**/*"]
|
47
47
|
s.extra_rdoc_files = FileList["[A-Z]*"] - %w(Gemfile Rakefile)
|
48
|
-
s.add_dependency("warden", "~> 0.9.
|
48
|
+
s.add_dependency("warden", "~> 0.9.4")
|
49
49
|
end
|
50
50
|
|
51
51
|
Jeweler::GemcutterTasks.new
|
@@ -4,7 +4,7 @@ class Devise::RegistrationsController < ApplicationController
|
|
4
4
|
before_filter :require_no_authentication, :only => [ :new, :create ]
|
5
5
|
before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
|
6
6
|
|
7
|
-
# GET /resource/
|
7
|
+
# GET /resource/sign_up
|
8
8
|
def new
|
9
9
|
build_resource
|
10
10
|
render_with_scope :new
|
@@ -54,4 +54,4 @@ class Devise::RegistrationsController < ApplicationController
|
|
54
54
|
send(:"authenticate_#{resource_name}!")
|
55
55
|
self.resource = send(:"current_#{resource_name}")
|
56
56
|
end
|
57
|
-
end
|
57
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
Welcome <%= @resource.email
|
1
|
+
<p>Welcome <%= @resource.email %>!</p>
|
2
2
|
|
3
|
-
You can confirm your account through the link below
|
3
|
+
<p>You can confirm your account through the link below:</p>
|
4
4
|
|
5
|
-
|
5
|
+
<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
|
@@ -1,8 +1,8 @@
|
|
1
|
-
Hello <%= @resource.email
|
1
|
+
<p>Hello <%= @resource.email %>!</p>
|
2
2
|
|
3
|
-
Someone has requested a link to change your password, and you can do this through the link below
|
3
|
+
<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
|
4
4
|
|
5
|
-
|
5
|
+
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %></p>
|
6
6
|
|
7
|
-
If you didn't request this, please ignore this email
|
8
|
-
Your password won't change until you access the link above and create a new one
|
7
|
+
<p>If you didn't request this, please ignore this email.</p>
|
8
|
+
<p>Your password won't change until you access the link above and create a new one.</p>
|
@@ -1,7 +1,7 @@
|
|
1
|
-
Hello <%= @resource.email
|
1
|
+
<p>Hello <%= @resource.email %>!</p>
|
2
2
|
|
3
|
-
Your account has been locked due to an excessive amount of unsuccessful sign in attempts
|
3
|
+
<p>Your account has been locked due to an excessive amount of unsuccessful sign in attempts.</p>
|
4
4
|
|
5
|
-
Click the link below to unlock your account
|
5
|
+
<p>Click the link below to unlock your account:</p>
|
6
6
|
|
7
|
-
|
7
|
+
<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %></p>
|
data/lib/devise.rb
CHANGED
@@ -21,12 +21,6 @@ module Devise
|
|
21
21
|
autoload :Sha1, 'devise/encryptors/sha1'
|
22
22
|
end
|
23
23
|
|
24
|
-
module Orm
|
25
|
-
autoload :ActiveRecord, 'devise/orm/active_record'
|
26
|
-
autoload :DataMapper, 'devise/orm/data_mapper'
|
27
|
-
autoload :MongoMapper, 'devise/orm/mongo_mapper'
|
28
|
-
end
|
29
|
-
|
30
24
|
ALL = []
|
31
25
|
|
32
26
|
# Authentication ones first
|
@@ -105,14 +99,6 @@ module Devise
|
|
105
99
|
mattr_accessor :mappings
|
106
100
|
@@mappings = ActiveSupport::OrderedHash.new
|
107
101
|
|
108
|
-
# Stores the chosen ORM.
|
109
|
-
mattr_accessor :orm
|
110
|
-
@@orm = :active_record
|
111
|
-
|
112
|
-
# TODO Remove
|
113
|
-
mattr_accessor :all
|
114
|
-
@@all = []
|
115
|
-
|
116
102
|
# Tells if devise should apply the schema in ORMs where devise declaration
|
117
103
|
# and schema belongs to the same class (as Datamapper and MongoMapper).
|
118
104
|
mattr_accessor :apply_schema
|
@@ -163,6 +149,18 @@ module Devise
|
|
163
149
|
yield self
|
164
150
|
end
|
165
151
|
|
152
|
+
# TODO Remove me on 1.1.0 final
|
153
|
+
def orm=(value)
|
154
|
+
ActiveSupport::Deprecation.warn "Devise.orm= and config.orm= are deprecated. " <<
|
155
|
+
"Just load \"devise/orm/\#{ORM_NAME}\" if Devise supports your ORM"
|
156
|
+
end
|
157
|
+
|
158
|
+
# TODO Remove me on 1.1.0 final
|
159
|
+
def default_url_options
|
160
|
+
ActiveSupport::Deprecation.warn "Devise.default_url_options and config.default_url_options are deprecated. " <<
|
161
|
+
"Just modify ApplicationController.default_url_options and Devise will automatically pick it up"
|
162
|
+
end
|
163
|
+
|
166
164
|
# Sets warden configuration using a block that will be invoked on warden
|
167
165
|
# initialization.
|
168
166
|
#
|
@@ -178,11 +176,6 @@ module Devise
|
|
178
176
|
@warden_config = block
|
179
177
|
end
|
180
178
|
|
181
|
-
# Configure default url options to be used within Devise and ActionController.
|
182
|
-
def default_url_options(&block)
|
183
|
-
Devise::Mapping.metaclass.send :define_method, :default_url_options, &block
|
184
|
-
end
|
185
|
-
|
186
179
|
# A method used internally to setup warden manager from the Rails initialize
|
187
180
|
# block.
|
188
181
|
def configure_warden(config) #:nodoc:
|
@@ -195,11 +188,6 @@ module Devise
|
|
195
188
|
@warden_config.try :call, config
|
196
189
|
end
|
197
190
|
|
198
|
-
# The class of the configured ORM
|
199
|
-
def orm_class
|
200
|
-
Devise::Orm.const_get(@@orm.to_s.camelize.to_sym)
|
201
|
-
end
|
202
|
-
|
203
191
|
# Generate a friendly string randomically to be used as token.
|
204
192
|
def friendly_token
|
205
193
|
ActiveSupport::SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
|
@@ -7,12 +7,6 @@ module Devise
|
|
7
7
|
included do
|
8
8
|
helper_method :warden, :signed_in?, :devise_controller?,
|
9
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
10
|
end
|
17
11
|
|
18
12
|
# The main accessor for the warden proxy instance
|
data/lib/devise/failure_app.rb
CHANGED
@@ -1,57 +1,54 @@
|
|
1
|
+
require "action_controller/metal"
|
2
|
+
|
1
3
|
module Devise
|
2
4
|
# Failure application that will be called every time :warden is thrown from
|
3
5
|
# any strategy or hook. Responsible for redirect the user to the sign in
|
4
6
|
# page based on current scope and mapping. If no scope is given, redirect
|
5
7
|
# to the default_url.
|
6
|
-
class FailureApp
|
7
|
-
|
8
|
-
include
|
8
|
+
class FailureApp < ActionController::Metal
|
9
|
+
include ActionController::RackDelegation
|
10
|
+
include ActionController::UrlFor
|
11
|
+
include ActionController::Redirecting
|
9
12
|
|
10
|
-
|
11
|
-
|
13
|
+
mattr_accessor :default_message
|
14
|
+
self.default_message = :unauthenticated
|
12
15
|
|
13
16
|
def self.call(env)
|
14
|
-
|
17
|
+
action(:respond).call(env)
|
15
18
|
end
|
16
19
|
|
17
|
-
def
|
18
|
-
|
20
|
+
def self.default_url_options(*args)
|
21
|
+
ApplicationController.default_url_options(*args)
|
19
22
|
end
|
20
23
|
|
21
|
-
def respond
|
22
|
-
|
23
|
-
scope = options[:scope]
|
24
|
-
|
25
|
-
redirect_path = if mapping = Devise.mappings[scope]
|
26
|
-
"#{mapping.parsed_path}/#{mapping.path_names[:sign_in]}"
|
27
|
-
else
|
28
|
-
"/#{default_url}"
|
29
|
-
end
|
30
|
-
query_string = query_string_for(options)
|
24
|
+
def respond
|
25
|
+
scope = warden_options[:scope]
|
31
26
|
store_location!(scope)
|
32
|
-
|
33
|
-
headers = {}
|
34
|
-
headers["Location"] = redirect_path
|
35
|
-
headers["Location"] << "?" << query_string unless query_string.empty?
|
36
|
-
headers["Content-Type"] = 'text/plain'
|
37
|
-
|
38
|
-
[302, headers, ["You are being redirected to #{redirect_path}"]]
|
27
|
+
redirect_to send(:"new_#{scope}_session_path", query_string_params)
|
39
28
|
end
|
40
29
|
|
41
|
-
|
42
|
-
def query_string_for(options)
|
43
|
-
message = @env['warden'].try(:message) || options[:message] || default_message
|
30
|
+
protected
|
44
31
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
32
|
+
# Build the proper query string based on the given message.
|
33
|
+
def query_string_params
|
34
|
+
message = warden.try(:message) || warden_options[:message] || self.class.default_message
|
35
|
+
|
36
|
+
case message
|
37
|
+
when Symbol
|
38
|
+
{ message => true }
|
39
|
+
when String
|
40
|
+
{ :message => message }
|
41
|
+
else
|
42
|
+
{}
|
52
43
|
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def warden
|
47
|
+
env['warden']
|
48
|
+
end
|
53
49
|
|
54
|
-
|
50
|
+
def warden_options
|
51
|
+
env['warden.options']
|
55
52
|
end
|
56
53
|
|
57
54
|
# Stores requested uri to redirect the user after signing in. We cannot use
|
data/lib/devise/mapping.rb
CHANGED
@@ -56,11 +56,6 @@ module Devise
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
# Default url options which can be used as prefix.
|
60
|
-
def self.default_url_options
|
61
|
-
{}
|
62
|
-
end
|
63
|
-
|
64
59
|
def initialize(name, options) #:nodoc:
|
65
60
|
@as = (options.delete(:as) || name).to_sym
|
66
61
|
@klass = (options.delete(:class_name) || name.to_s.classify).to_s
|
@@ -95,19 +90,10 @@ module Devise
|
|
95
90
|
end
|
96
91
|
|
97
92
|
# Returns the raw path using path_prefix and as.
|
98
|
-
def
|
93
|
+
def path
|
99
94
|
path_prefix + as.to_s
|
100
95
|
end
|
101
96
|
|
102
|
-
# Returns the parsed path taking into account the relative url root and raw path.
|
103
|
-
def parsed_path
|
104
|
-
returning (ActionController::Base.relative_url_root.to_s + raw_path) do |path|
|
105
|
-
self.class.default_url_options.each do |key, value|
|
106
|
-
path.gsub!(key.inspect, value.to_param)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
97
|
# Create magic predicates for verifying what module is activated by this map.
|
112
98
|
# Example:
|
113
99
|
#
|
data/lib/devise/models.rb
CHANGED
@@ -57,15 +57,12 @@ module Devise
|
|
57
57
|
#
|
58
58
|
def devise(*modules)
|
59
59
|
raise "You need to give at least one Devise module" if modules.empty?
|
60
|
-
options = modules.extract_options!
|
61
60
|
|
61
|
+
options = modules.extract_options!
|
62
62
|
@devise_modules = Devise::ALL & modules.map(&:to_sym).uniq
|
63
63
|
|
64
|
-
|
65
|
-
devise_modules.each
|
66
|
-
include Devise::Models.const_get(m.to_s.classify)
|
67
|
-
end
|
68
|
-
|
64
|
+
devise_modules_hook! do
|
65
|
+
devise_modules.each { |m| include Devise::Models.const_get(m.to_s.classify) }
|
69
66
|
options.each { |key, value| send(:"#{key}=", value) }
|
70
67
|
end
|
71
68
|
end
|
@@ -76,6 +73,12 @@ module Devise
|
|
76
73
|
@devise_modules ||= []
|
77
74
|
end
|
78
75
|
|
76
|
+
# The hook which is called inside devise. So your ORM can include devise
|
77
|
+
# compatibility stuff.
|
78
|
+
def devise_modules_hook!
|
79
|
+
yield
|
80
|
+
end
|
81
|
+
|
79
82
|
# Find an initialize a record setting an error if it can't be found.
|
80
83
|
def find_or_initialize_with_error_by(attribute, value, error=:invalid)
|
81
84
|
if value.present?
|
@@ -19,16 +19,13 @@ module Devise
|
|
19
19
|
# add_index "accounts", ["reset_password_token"], :name => "reset_password_token", :unique => true
|
20
20
|
#
|
21
21
|
module ActiveRecord
|
22
|
-
|
23
|
-
|
24
|
-
yield
|
25
|
-
end
|
26
|
-
|
27
|
-
include Devise::Schema
|
22
|
+
module Schema
|
23
|
+
include Devise::Schema
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
# Tell how to apply schema methods.
|
26
|
+
def apply_schema(name, type, options={})
|
27
|
+
column name, type.to_s.downcase.to_sym, options
|
28
|
+
end
|
32
29
|
end
|
33
30
|
end
|
34
31
|
end
|
@@ -36,6 +33,6 @@ end
|
|
36
33
|
|
37
34
|
if defined?(ActiveRecord)
|
38
35
|
ActiveRecord::Base.extend Devise::Models
|
39
|
-
ActiveRecord::ConnectionAdapters::Table.send :include, Devise::Orm::ActiveRecord
|
40
|
-
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Orm::ActiveRecord
|
36
|
+
ActiveRecord::ConnectionAdapters::Table.send :include, Devise::Orm::ActiveRecord::Schema
|
37
|
+
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Orm::ActiveRecord::Schema
|
41
38
|
end
|
@@ -1,83 +1,86 @@
|
|
1
1
|
module Devise
|
2
2
|
module Orm
|
3
3
|
module DataMapper
|
4
|
-
module
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module Hook
|
5
|
+
def devise_modules_hook!
|
6
|
+
extend Schema
|
7
|
+
include Compatibility
|
8
|
+
yield
|
9
|
+
return unless Devise.apply_schema
|
10
|
+
devise_modules.each { |m| send(m) if respond_to?(m, true) }
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
module Schema
|
15
|
+
include Devise::Schema
|
16
|
+
|
17
|
+
SCHEMA_OPTIONS = {
|
18
|
+
:null => :required,
|
19
|
+
:limit => :length
|
20
|
+
}
|
17
21
|
|
18
|
-
|
22
|
+
# Tell how to apply schema methods. This automatically maps :limit to
|
23
|
+
# :length and :null to :required.
|
24
|
+
def apply_schema(name, type, options={})
|
25
|
+
SCHEMA_OPTIONS.each do |old_key, new_key|
|
26
|
+
next unless options.key?(old_key)
|
27
|
+
options[new_key] = !options.delete(old_key)
|
28
|
+
end
|
19
29
|
|
20
|
-
|
21
|
-
klass.send(mod) if klass.respond_to?(mod)
|
30
|
+
property name, type, options
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
25
|
-
|
34
|
+
module Compatibility
|
35
|
+
extend ActiveSupport::Concern
|
26
36
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
37
|
+
module ClassMethods
|
38
|
+
# Hooks for confirmable
|
39
|
+
def before_create(*args)
|
40
|
+
wrap_hook(:before, *args)
|
41
|
+
end
|
31
42
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
43
|
+
def after_create(*args)
|
44
|
+
wrap_hook(:after, *args)
|
45
|
+
end
|
36
46
|
|
37
|
-
|
38
|
-
|
39
|
-
end
|
47
|
+
def wrap_hook(action, *args)
|
48
|
+
options = args.extract_options!
|
40
49
|
|
41
|
-
|
42
|
-
|
50
|
+
args.each do |callback|
|
51
|
+
send action, :create, callback
|
52
|
+
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
53
|
+
def #{callback}
|
54
|
+
super if #{options[:if] || true}
|
55
|
+
end
|
56
|
+
METHOD
|
57
|
+
end
|
58
|
+
end
|
43
59
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
60
|
+
# Add ActiveRecord like finder
|
61
|
+
def find(*args)
|
62
|
+
case args.first
|
63
|
+
when :first, :all
|
64
|
+
send(args.shift, *args)
|
65
|
+
else
|
66
|
+
get(*args)
|
49
67
|
end
|
50
|
-
|
68
|
+
end
|
51
69
|
end
|
52
|
-
end
|
53
70
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
case args.first
|
58
|
-
when :first
|
59
|
-
first(options)
|
60
|
-
when :all
|
61
|
-
all(options)
|
71
|
+
def save(options=nil)
|
72
|
+
if options.is_a?(Hash) && options[:validate] == false
|
73
|
+
save!
|
62
74
|
else
|
63
|
-
|
64
|
-
|
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
|
+
super()
|
76
|
+
end
|
75
77
|
end
|
76
|
-
|
77
|
-
property name, type, options
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
DataMapper::Model.
|
83
|
+
DataMapper::Model.class_eval do
|
84
|
+
extend Devise::ORM::DataMapper::Hook
|
85
|
+
include Devise::Models
|
86
|
+
end
|
@@ -1,39 +1,49 @@
|
|
1
1
|
module Devise
|
2
2
|
module Orm
|
3
3
|
module MongoMapper
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
module Hook
|
5
|
+
def devise_modules_hook!
|
6
|
+
extend Schema
|
7
|
+
include Compatibility
|
8
|
+
yield
|
9
|
+
return unless Devise.apply_schema
|
10
|
+
devise_modules.each { |m| send(m) if respond_to?(m, true) }
|
10
11
|
end
|
11
12
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
super
|
13
|
+
|
14
|
+
module Schema
|
15
|
+
include Devise::Schema
|
16
|
+
|
17
|
+
# Tell how to apply schema methods. This automatically converts DateTime
|
18
|
+
# to Time, since MongoMapper does not recognize the former.
|
19
|
+
def apply_schema(name, type, options={})
|
20
|
+
type = Time if type == DateTime
|
21
|
+
key name, type, options
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
25
|
-
include Devise::Schema
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
module Compatibility
|
26
|
+
extend ActiveSupport::Concern
|
27
|
+
|
28
|
+
module ClassMethods
|
29
|
+
def find(*args)
|
30
|
+
case args.first
|
31
|
+
when :first, :all
|
32
|
+
send(args.shift, *args)
|
33
|
+
else
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
33
38
|
end
|
39
|
+
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
38
|
-
MongoMapper::Document::
|
39
|
-
|
44
|
+
[MongoMapper::Document, MongoMapper::EmbeddedDocument].each do |mod|
|
45
|
+
mod::ClassMethods.class_eval do
|
46
|
+
include Devise::Models
|
47
|
+
include Devise::Orm::MongoMapper::Hook
|
48
|
+
end
|
49
|
+
end
|
data/lib/devise/rails.rb
CHANGED
data/lib/devise/rails/routes.rb
CHANGED
@@ -69,11 +69,13 @@ module ActionDispatch::Routing
|
|
69
69
|
#
|
70
70
|
# devise_for :users, :path_prefix => "/:locale"
|
71
71
|
#
|
72
|
-
# If you are using a dynamic prefix, like :locale above, you need to configure default_url_options
|
73
|
-
#
|
72
|
+
# If you are using a dynamic prefix, like :locale above, you need to configure default_url_options in your ApplicationController
|
73
|
+
# class level, so Devise can pick it:
|
74
74
|
#
|
75
|
-
#
|
76
|
-
#
|
75
|
+
# class ApplicationController < ActionController::Base
|
76
|
+
# def self.default_url_options
|
77
|
+
# { :locale => I18n.locale }
|
78
|
+
# end
|
77
79
|
# end
|
78
80
|
#
|
79
81
|
# * :controllers => the controller which should be used. All routes by default points to Devise controllers.
|
@@ -103,7 +105,7 @@ module ActionDispatch::Routing
|
|
103
105
|
protected
|
104
106
|
|
105
107
|
def authenticatable(mapping, controllers)
|
106
|
-
scope mapping.
|
108
|
+
scope mapping.path do
|
107
109
|
get mapping.path_names[:sign_in], :to => "#{controllers[:sessions]}#new", :as => :"new_#{mapping.name}_session"
|
108
110
|
post mapping.path_names[:sign_in], :to => "#{controllers[:sessions]}#create", :as => :"#{mapping.name}_session"
|
109
111
|
get mapping.path_names[:sign_out], :to => "#{controllers[:sessions]}#destroy", :as => :"destroy_#{mapping.name}_session"
|
@@ -111,26 +113,26 @@ module ActionDispatch::Routing
|
|
111
113
|
end
|
112
114
|
|
113
115
|
def recoverable(mapping, controllers)
|
114
|
-
scope mapping.
|
116
|
+
scope mapping.path, :name_prefix => mapping.name do
|
115
117
|
resource :password, :only => [:new, :create, :edit, :update], :as => mapping.path_names[:password], :controller => controllers[:passwords]
|
116
118
|
end
|
117
119
|
end
|
118
120
|
|
119
121
|
def confirmable(mapping, controllers)
|
120
|
-
scope mapping.
|
122
|
+
scope mapping.path, :name_prefix => mapping.name do
|
121
123
|
resource :confirmation, :only => [:new, :create, :show], :as => mapping.path_names[:confirmation], :controller => controllers[:confirmations]
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
125
127
|
def lockable(mapping, controllers)
|
126
|
-
scope mapping.
|
128
|
+
scope mapping.path, :name_prefix => mapping.name do
|
127
129
|
resource :unlock, :only => [:new, :create, :show], :as => mapping.path_names[:unlock], :controller => controllers[:unlocks]
|
128
130
|
end
|
129
131
|
end
|
130
132
|
|
131
133
|
def registerable(mapping, controllers)
|
132
134
|
scope :name_prefix => mapping.name do
|
133
|
-
resource :registration, :only => [:new, :create, :edit, :update, :destroy], :as => mapping.
|
135
|
+
resource :registration, :only => [:new, :create, :edit, :update, :destroy], :as => mapping.path[1..-1],
|
134
136
|
:path_names => { :new => mapping.path_names[:sign_up] }, :controller => controllers[:registrations]
|
135
137
|
end
|
136
138
|
end
|
@@ -14,7 +14,7 @@ module Devise
|
|
14
14
|
if resource = mapping.to.authenticate_with_http(username, password)
|
15
15
|
success!(resource)
|
16
16
|
else
|
17
|
-
custom!([401, custom_headers, [
|
17
|
+
custom!([401, custom_headers, [response_body]])
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -28,6 +28,12 @@ module Devise
|
|
28
28
|
ActiveSupport::Base64.decode64(request.authorization.split(' ', 2).last || '')
|
29
29
|
end
|
30
30
|
|
31
|
+
def response_body
|
32
|
+
body = "HTTP Basic: Access denied."
|
33
|
+
method = :"to_#{request.format.to_sym}"
|
34
|
+
{}.respond_to?(method) ? { :error => body }.send(method) : body
|
35
|
+
end
|
36
|
+
|
31
37
|
def custom_headers
|
32
38
|
{
|
33
39
|
"Content-Type" => request.format.to_s,
|
data/lib/devise/version.rb
CHANGED
@@ -63,8 +63,7 @@ Devise.setup do |config|
|
|
63
63
|
# ==> General configuration
|
64
64
|
# Load and configure the ORM. Supports :active_record (default), :mongo_mapper
|
65
65
|
# (requires mongo_ext installed) and :data_mapper (experimental).
|
66
|
-
|
67
|
-
# config.orm = :mongo_mapper
|
66
|
+
require 'devise/orm/active_record'
|
68
67
|
|
69
68
|
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
70
69
|
# "sessions/users/new". It's turned off by default because it's slower if you
|
@@ -93,10 +92,4 @@ Devise.setup do |config|
|
|
93
92
|
# end
|
94
93
|
# manager.default_strategies.unshift :twitter_oauth
|
95
94
|
# end
|
96
|
-
|
97
|
-
# Configure default_url_options if you are using dynamic segments in :path_prefix
|
98
|
-
# for devise_for.
|
99
|
-
# config.default_url_options do
|
100
|
-
# { :locale => I18n.locale }
|
101
|
-
# end
|
102
95
|
end
|
@@ -178,13 +178,4 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|
178
178
|
test 'is not a devise controller' do
|
179
179
|
assert_not @controller.devise_controller?
|
180
180
|
end
|
181
|
-
|
182
|
-
test 'default url options are retrieved from devise' do
|
183
|
-
begin
|
184
|
-
Devise.default_url_options {{ :locale => I18n.locale }}
|
185
|
-
assert_equal({ :locale => :en }, @controller.send(:default_url_options))
|
186
|
-
ensure
|
187
|
-
Devise.default_url_options {{ }}
|
188
|
-
end
|
189
|
-
end
|
190
181
|
end
|
data/test/failure_app_test.rb
CHANGED
@@ -7,6 +7,7 @@ class FailureTest < ActiveSupport::TestCase
|
|
7
7
|
env = {
|
8
8
|
'warden.options' => { :scope => :user },
|
9
9
|
'REQUEST_URI' => 'http://test.host/',
|
10
|
+
'HTTP_HOST' => 'test.host',
|
10
11
|
'REQUEST_METHOD' => 'GET',
|
11
12
|
'rack.session' => {}
|
12
13
|
}.merge!(env_params)
|
@@ -18,32 +19,28 @@ class FailureTest < ActiveSupport::TestCase
|
|
18
19
|
end
|
19
20
|
|
20
21
|
test 'return to the default redirect location' do
|
21
|
-
assert_equal '/users/sign_in?unauthenticated=true', call_failure.second['Location']
|
22
|
+
assert_equal 'http://test.host/users/sign_in?unauthenticated=true', call_failure.second['Location']
|
22
23
|
end
|
23
24
|
|
24
25
|
test 'uses the proxy failure message' do
|
25
26
|
warden = OpenStruct.new(:message => :test)
|
26
27
|
location = call_failure('warden' => warden).second['Location']
|
27
|
-
assert_equal '/users/sign_in?test=true', location
|
28
|
+
assert_equal 'http://test.host/users/sign_in?test=true', location
|
28
29
|
end
|
29
30
|
|
30
31
|
test 'uses the given message' do
|
31
32
|
warden = OpenStruct.new(:message => 'Hello world')
|
32
33
|
location = call_failure('warden' => warden).second['Location']
|
33
|
-
assert_equal '/users/sign_in?message=Hello+world', location
|
34
|
+
assert_equal 'http://test.host/users/sign_in?message=Hello+world', location
|
34
35
|
end
|
35
36
|
|
36
|
-
test '
|
37
|
-
|
38
|
-
location = call_failure('warden.options' => { :scope => nil }).second['Location']
|
39
|
-
assert_equal '/test/sign_in?unauthenticated=true', location
|
40
|
-
end
|
41
|
-
|
42
|
-
test 'set content type to default text/plain' do
|
43
|
-
assert_equal 'text/plain', call_failure.second['Content-Type']
|
37
|
+
test 'set content type to default text/html' do
|
38
|
+
assert_equal 'text/html; charset=utf-8', call_failure.second['Content-Type']
|
44
39
|
end
|
45
40
|
|
46
41
|
test 'setup a default message' do
|
47
|
-
|
42
|
+
assert_match /You are being/, call_failure.last.body
|
43
|
+
assert_match /redirected/, call_failure.last.body
|
44
|
+
assert_match /\?unauthenticated=true/, call_failure.last.body
|
48
45
|
end
|
49
46
|
end
|
@@ -20,6 +20,7 @@ class HttpAuthenticationTest < ActionController::IntegrationTest
|
|
20
20
|
sign_in_as_new_user_with_http("unknown", "123456", :xml)
|
21
21
|
assert_equal 401, status
|
22
22
|
assert_equal "application/xml", headers["Content-Type"]
|
23
|
+
assert response.body.include?("<error>HTTP Basic: Access denied.</error>")
|
23
24
|
end
|
24
25
|
|
25
26
|
test 'returns a custom response with www-authenticate and chosen realm' do
|
@@ -16,7 +16,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
16
16
|
assert_contain 'You have signed up successfully.'
|
17
17
|
assert warden.authenticated?(:admin)
|
18
18
|
|
19
|
-
admin = Admin.last
|
19
|
+
admin = Admin.last :order => "id"
|
20
20
|
assert_equal admin.email, 'new_user@test.com'
|
21
21
|
end
|
22
22
|
|
@@ -34,7 +34,7 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
34
34
|
|
35
35
|
assert_not warden.authenticated?(:user)
|
36
36
|
|
37
|
-
user = User.last
|
37
|
+
user = User.last :order => "id"
|
38
38
|
assert_equal user.email, 'new_user@test.com'
|
39
39
|
assert_not user.confirmed?
|
40
40
|
end
|
@@ -28,6 +28,14 @@ class RememberMeTest < ActionController::IntegrationTest
|
|
28
28
|
assert warden.user(:user) == user
|
29
29
|
end
|
30
30
|
|
31
|
+
test 'does not remember other scopes' do
|
32
|
+
user = create_user_and_remember
|
33
|
+
get root_path
|
34
|
+
assert_response :success
|
35
|
+
assert warden.authenticated?(:user)
|
36
|
+
assert_not warden.authenticated?(:admin)
|
37
|
+
end
|
38
|
+
|
31
39
|
test 'do not remember with invalid token' do
|
32
40
|
user = create_user_and_remember('add')
|
33
41
|
get users_path
|
data/test/mapping_test.rb
CHANGED
@@ -4,7 +4,6 @@ class MappingTest < ActiveSupport::TestCase
|
|
4
4
|
|
5
5
|
test 'store options' do
|
6
6
|
mapping = Devise.mappings[:user]
|
7
|
-
|
8
7
|
assert_equal User, mapping.to
|
9
8
|
assert_equal User.devise_modules, mapping.for
|
10
9
|
assert_equal :users, mapping.as
|
@@ -96,37 +95,9 @@ class MappingTest < ActiveSupport::TestCase
|
|
96
95
|
assert_equal 2, Devise.mappings[:manager].as_position
|
97
96
|
end
|
98
97
|
|
99
|
-
test '
|
100
|
-
assert_equal '/users', Devise.mappings[:user].
|
101
|
-
assert_equal '/:locale/accounts', Devise.mappings[:manager].
|
102
|
-
end
|
103
|
-
|
104
|
-
test 'raw path ignores the relative_url_root' do
|
105
|
-
swap ActionController::Base, :relative_url_root => "/abc" do
|
106
|
-
assert_equal '/users', Devise.mappings[:user].raw_path
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
test 'parsed path is returned' do
|
111
|
-
begin
|
112
|
-
Devise.default_url_options {{ :locale => I18n.locale }}
|
113
|
-
assert_equal '/users', Devise.mappings[:user].parsed_path
|
114
|
-
assert_equal '/en/accounts', Devise.mappings[:manager].parsed_path
|
115
|
-
ensure
|
116
|
-
Devise.default_url_options {{ }}
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
test 'parsed path adds in the relative_url_root' do
|
121
|
-
swap ActionController::Base, :relative_url_root => '/abc' do
|
122
|
-
assert_equal '/abc/users', Devise.mappings[:user].parsed_path
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
test 'parsed path deals with a nil relative_url_root' do
|
127
|
-
swap ActionController::Base, :relative_url_root => nil do
|
128
|
-
assert_equal '/users', Devise.mappings[:user].raw_path
|
129
|
-
end
|
98
|
+
test 'path is returned with path prefix and as' do
|
99
|
+
assert_equal '/users', Devise.mappings[:user].path
|
100
|
+
assert_equal '/:locale/accounts', Devise.mappings[:manager].path
|
130
101
|
end
|
131
102
|
|
132
103
|
test 'magic predicates' do
|
@@ -2,7 +2,7 @@ class Admin
|
|
2
2
|
include MongoMapper::Document
|
3
3
|
include MongoMapper::Plugins::Callbacks
|
4
4
|
|
5
|
-
devise :authenticatable, :timeoutable
|
5
|
+
devise :authenticatable, :timeoutable, :registerable
|
6
6
|
|
7
7
|
def self.find_for_authentication(conditions)
|
8
8
|
last(:conditions => conditions, :order => "email")
|
@@ -3,9 +3,9 @@ class User
|
|
3
3
|
|
4
4
|
key :created_at, DateTime
|
5
5
|
|
6
|
-
devise :authenticatable, :http_authenticatable, :confirmable, :recoverable,
|
7
|
-
:
|
8
|
-
:
|
6
|
+
devise :authenticatable, :http_authenticatable, :confirmable, :lockable, :recoverable,
|
7
|
+
:registerable, :rememberable, :timeoutable, :token_authenticatable,
|
8
|
+
:trackable, :validatable
|
9
9
|
|
10
10
|
# attr_accessible :username, :email, :password, :password_confirmation
|
11
11
|
end
|
@@ -38,7 +38,6 @@ Devise.setup do |config|
|
|
38
38
|
|
39
39
|
# Load and configure the ORM. Supports :active_record, :data_mapper and :mongo_mapper.
|
40
40
|
require "devise/orm/#{DEVISE_ORM}"
|
41
|
-
config.orm = DEVISE_ORM
|
42
41
|
|
43
42
|
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
44
43
|
# "sessions/users/new". It's turned off by default because it's slower if you
|
data/test/support/integration.rb
CHANGED
@@ -50,7 +50,7 @@ class ActionController::IntegrationTest
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def assert_current_path(path)
|
53
|
-
assert_equal
|
53
|
+
assert_equal(prepend_host(path), prepend_host(current_url))
|
54
54
|
end
|
55
55
|
|
56
56
|
# Fix assert_redirect_to in integration sessions because they don't take into
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.pre3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jos\xC3\xA9 Valim"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-02-
|
13
|
+
date: 2010-02-24 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
requirements:
|
22
22
|
- - ~>
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 0.9.
|
24
|
+
version: 0.9.4
|
25
25
|
version:
|
26
26
|
description: Flexible authentication solution for Rails with Warden
|
27
27
|
email: contact@plataformatec.com.br
|