devise 0.7.5 → 0.8.0
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/README.rdoc +21 -30
- data/Rakefile +1 -1
- data/app/models/devise_mailer.rb +1 -12
- data/generators/devise/devise_generator.rb +0 -7
- data/generators/devise_install/devise_install_generator.rb +2 -0
- data/generators/devise_install/templates/README +18 -0
- data/generators/devise_install/templates/devise.rb +17 -7
- data/lib/devise.rb +22 -15
- data/lib/devise/controllers/helpers.rb +5 -1
- data/lib/devise/encryptors/bcrypt.rb +24 -0
- data/lib/devise/hooks/trackable.rb +1 -1
- data/lib/devise/mapping.rb +1 -1
- data/lib/devise/models/timeoutable.rb +0 -1
- data/lib/devise/orm/data_mapper.rb +28 -12
- data/lib/devise/rails.rb +2 -2
- data/lib/devise/rails/routes.rb +1 -1
- data/lib/devise/test_helpers.rb +4 -4
- data/lib/devise/version.rb +1 -1
- data/test/devise_test.rb +10 -50
- data/test/encryptors_test.rb +8 -0
- data/test/integration/authenticatable_test.rb +20 -6
- data/test/integration/confirmable_test.rb +8 -0
- data/test/integration/trackable_test.rb +1 -1
- data/test/mailers/confirmation_instructions_test.rb +1 -1
- data/test/mailers/reset_password_instructions_test.rb +1 -1
- data/test/rails_app/config/environment.rb +1 -0
- data/test/rails_app/config/initializers/new_rails_defaults.rb +4 -1
- data/test/rails_app/config/routes.rb +1 -0
- metadata +6 -4
- data/generators/devise/templates/README +0 -22
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
* enhancements
|
2
|
+
* Warden 0.8.0 compatibility
|
3
|
+
* Add an easy for map.connect "sign_in", :controller => "sessions", :action => "new" to work
|
4
|
+
* Added :bcrypt encryptor (by github.com/capotej)
|
5
|
+
|
6
|
+
* bug fix
|
7
|
+
* sign_in_count is also increased when user signs in via password change, confirmation, etc..
|
8
|
+
* More DataMapper compatibility (by github.com/lancecarlson)
|
9
|
+
|
10
|
+
* deprecation
|
11
|
+
* Removed DeviseMailer.sender
|
12
|
+
|
1
13
|
== 0.7.5
|
2
14
|
|
3
15
|
* enhancements
|
data/README.rdoc
CHANGED
@@ -7,22 +7,25 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
|
|
7
7
|
* Allows you to have multiple roles (or models/scopes) signed in at the same time;
|
8
8
|
* Is based on a modularity concept: use just what you really need.
|
9
9
|
|
10
|
-
Right now it's composed of
|
10
|
+
Right now it's composed of six modules included by default when you invoke "devise :all" in your models:
|
11
11
|
|
12
12
|
* Authenticatable: responsible for encrypting password and validating authenticity of a user while signing in.
|
13
13
|
* Confirmable: responsible for verifying whether an account is already confirmed to sign in, and to send emails with confirmation instructions.
|
14
14
|
* Recoverable: takes care of reseting the user password and send reset instructions.
|
15
15
|
* Rememberable: manages generating and clearing token for remember the user from a saved cookie.
|
16
|
-
* Activatable: if you need to activate accounts by other means, which are not through confirmation, use this module.
|
17
|
-
* Timeoutable: expires sessions without activity in a certain period of time.
|
18
16
|
* Trackable: tracks sign in count, timestamps and ip.
|
19
17
|
* Validatable: creates all needed validations for email and password. It's totally optional, so you're able to to customize validations by yourself.
|
20
18
|
|
19
|
+
And it also includes the optional modules:
|
20
|
+
|
21
|
+
* Activatable: if you need to activate accounts by other means, which are not through confirmation, use this module.
|
22
|
+
* Timeoutable: expires sessions without activity in a certain period of time.
|
23
|
+
|
21
24
|
There's an example application using Devise at http://github.com/plataformatec/devise_example .
|
22
25
|
|
23
26
|
== Dependencies
|
24
27
|
|
25
|
-
Devise is based on Warden (http://github.com/hassox/warden), a Rack Authentication Framework so you need to install it as a gem. Please ensure you have it installed in order to use devise (see
|
28
|
+
Devise is based on Warden (http://github.com/hassox/warden), a Rack Authentication Framework so you need to install it as a gem. Please ensure you have it installed in order to use devise (see installation below).
|
26
29
|
|
27
30
|
== Installation
|
28
31
|
|
@@ -53,7 +56,7 @@ And you're ready to go. The generator will install an initializer which describe
|
|
53
56
|
|
54
57
|
This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration. You can also check out the *Generators* section below to help you start.
|
55
58
|
|
56
|
-
Devise must be set up within the model (or models) you want to use, and devise routes must be created inside your routes.rb file.
|
59
|
+
Devise must be set up within the model (or models) you want to use, and devise routes must be created inside your config/routes.rb file.
|
57
60
|
|
58
61
|
We're assuming here you want a User model. First of all you have to setup a migration with the following fields:
|
59
62
|
|
@@ -62,6 +65,7 @@ We're assuming here you want a User model. First of all you have to setup a migr
|
|
62
65
|
t.confirmable
|
63
66
|
t.recoverable
|
64
67
|
t.rememberable
|
68
|
+
t.trackable
|
65
69
|
t.timestamps
|
66
70
|
end
|
67
71
|
|
@@ -71,35 +75,21 @@ You may also want to add some indexes to improve performance:
|
|
71
75
|
add_index :your_table, :confirmation_token # for confirmable
|
72
76
|
add_index :your_table, :reset_password_token # for recoverable
|
73
77
|
|
74
|
-
Now let's setup a User model adding the devise line
|
78
|
+
Now let's setup a User model adding the devise line:
|
75
79
|
|
76
80
|
class User < ActiveRecord::Base
|
77
|
-
devise :
|
81
|
+
devise :all
|
78
82
|
end
|
79
83
|
|
80
|
-
This
|
81
|
-
|
82
|
-
You could also include the other devise modules as below:
|
83
|
-
|
84
|
-
# Include only authenticatable stuff
|
85
|
-
devise :authenticatable
|
86
|
-
|
87
|
-
# Include authenticatable + confirmable
|
88
|
-
devise :authenticatable, :confirmable
|
89
|
-
|
90
|
-
# Include authenticatable + recoverable + rememberable
|
91
|
-
devise :authenticatable, :recoverable, :rememberable
|
92
|
-
|
93
|
-
# Include authenticatable + timeoutable
|
94
|
-
devise :authenticatable, :timeoutable
|
84
|
+
This will include the six default modules outlined at the beginning. You can exclude and remove any module at will:
|
95
85
|
|
96
|
-
# Include
|
97
|
-
devise :all
|
86
|
+
# Include timeout configuration
|
87
|
+
devise :all, :timeoutable
|
98
88
|
|
99
|
-
#
|
100
|
-
devise :all, :except => :
|
89
|
+
# Remove validations
|
90
|
+
devise :all, :except => :validatable
|
101
91
|
|
102
|
-
|
92
|
+
Remember that Devise don't rely on _attr_accessible_ or _attr_protected_ inside its modules, so be sure to setup what attributes are accessible or protected in your model.
|
103
93
|
|
104
94
|
== Model configuration
|
105
95
|
|
@@ -151,19 +141,20 @@ Finally, if you are using confirmable or recoverable, you also need to setup def
|
|
151
141
|
|
152
142
|
== Views
|
153
143
|
|
154
|
-
By default devise will use the same views for all scopes/roles you have. But what if you need so different views to each of them? Devise also has an easy way to accomplish it: just setup
|
144
|
+
By default devise will use the same views for all scopes/roles you have. But what if you need so different views to each of them? Devise also has an easy way to accomplish it: just setup config,scoped_views to true inside your devise config file, and you will be able to have views based on scope like 'sessions/users/new' and 'sessions/admin/new'. If no view is found within the scope, Devise will fallback to the default view.
|
155
145
|
|
156
146
|
== Tidying up
|
157
147
|
|
158
|
-
Devise let's you setup as many roles as you want, so let's say you already have this User model and also want an Admin model with
|
148
|
+
Devise let's you setup as many roles as you want, so let's say you already have this User model and also want an Admin model with just authentication, trackable and timeoutable stuff and none of confirmation or password recovery. Just follow the same steps:
|
159
149
|
|
160
150
|
# Create a migration with the required fields
|
161
151
|
create_table :admins do |t|
|
162
152
|
t.authenticatable
|
153
|
+
t.trackable
|
163
154
|
end
|
164
155
|
|
165
156
|
# Inside your Admin model
|
166
|
-
devise :authenticatable, :
|
157
|
+
devise :authenticatable, :trackable, :timeoutable
|
167
158
|
|
168
159
|
# Inside your routes
|
169
160
|
map.devise_for :admin
|
data/Rakefile
CHANGED
@@ -44,7 +44,7 @@ begin
|
|
44
44
|
s.description = "Flexible authentication solution for Rails with Warden"
|
45
45
|
s.authors = ['José Valim', 'Carlos Antônio']
|
46
46
|
s.files = FileList["[A-Z]*", "{app,config,generators,lib}/**/*", "init.rb"]
|
47
|
-
s.add_dependency("warden", "~> 0.
|
47
|
+
s.add_dependency("warden", "~> 0.8.0")
|
48
48
|
end
|
49
49
|
|
50
50
|
Jeweler::GemcutterTasks.new
|
data/app/models/devise_mailer.rb
CHANGED
@@ -1,16 +1,5 @@
|
|
1
1
|
class DeviseMailer < ::ActionMailer::Base
|
2
2
|
|
3
|
-
# Sets who is sending the e-mail
|
4
|
-
def self.sender=(value)
|
5
|
-
@@sender = value
|
6
|
-
end
|
7
|
-
|
8
|
-
# Reads who is sending the e-mail
|
9
|
-
def self.sender
|
10
|
-
@@sender
|
11
|
-
end
|
12
|
-
self.sender = nil
|
13
|
-
|
14
3
|
# Deliver confirmation instructions when the user is created or its email is
|
15
4
|
# updated, and also when confirmation is manually requested
|
16
5
|
def confirmation_instructions(record)
|
@@ -30,7 +19,7 @@ class DeviseMailer < ::ActionMailer::Base
|
|
30
19
|
raise "Invalid devise resource #{record}" unless mapping
|
31
20
|
|
32
21
|
subject translate(mapping, key)
|
33
|
-
from
|
22
|
+
from Devise.mailer_sender
|
34
23
|
recipients record.email
|
35
24
|
sent_on Time.now
|
36
25
|
content_type 'text/html'
|
@@ -4,18 +4,11 @@ class DeviseGenerator < Rails::Generator::NamedBase
|
|
4
4
|
|
5
5
|
def manifest
|
6
6
|
record do |m|
|
7
|
-
# Model
|
8
7
|
m.directory(File.join('app', 'models', class_path))
|
9
8
|
m.template 'model.rb', File.join('app', 'models', "#{file_path}.rb")
|
10
9
|
|
11
|
-
# Migration
|
12
10
|
m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "devise_create_#{table_name}"
|
13
|
-
|
14
|
-
# Routing
|
15
11
|
m.route_devise table_name
|
16
|
-
|
17
|
-
# Readme
|
18
|
-
m.readme "README"
|
19
12
|
end
|
20
13
|
end
|
21
14
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
===============================================================================
|
3
|
+
|
4
|
+
Some setup you must do manually if you haven't yet:
|
5
|
+
|
6
|
+
1. Setup default url options for your specific environment. Here is an
|
7
|
+
example of development environment:
|
8
|
+
|
9
|
+
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
10
|
+
|
11
|
+
This is a required Rails configuration. In production is must be the
|
12
|
+
actual host of your application
|
13
|
+
|
14
|
+
2. Ensure you have defined root_url to *something* in your config/routes.rb:
|
15
|
+
|
16
|
+
map.root :controller => 'home'
|
17
|
+
|
18
|
+
===============================================================================
|
@@ -10,6 +10,9 @@ Devise.setup do |config|
|
|
10
10
|
# to check the docs for a complete set.
|
11
11
|
config.all = [:authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable]
|
12
12
|
|
13
|
+
# Configure the e-mail address which will be shown in DeviseMailer.
|
14
|
+
config.mailer_sender = "please-change-me@config-initializers-devise.com"
|
15
|
+
|
13
16
|
# Invoke `rake secret` and use the printed value to setup a pepper to generate
|
14
17
|
# the encrypted password. By default no pepper is used.
|
15
18
|
# config.pepper = "rake secret output"
|
@@ -18,10 +21,10 @@ Devise.setup do |config|
|
|
18
21
|
# config.stretches = 10
|
19
22
|
|
20
23
|
# Define which will be the encryption algorithm. Supported algorithms are :sha1
|
21
|
-
# (default) and :
|
22
|
-
#
|
23
|
-
# above to 20 for default behavior) and :restful_authentication_sha1
|
24
|
-
# should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
|
24
|
+
# (default), :sha512 and :bcrypt. Devise also supports encryptors from others
|
25
|
+
# authentication tools as :clearance_sha1, :authlogic_sha512 (then you should set
|
26
|
+
# stretches above to 20 for default behavior) and :restful_authentication_sha1
|
27
|
+
# (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
|
25
28
|
# config.encryptor = :sha1
|
26
29
|
|
27
30
|
# Configure which keys are used when authenticating an user. By default is
|
@@ -42,9 +45,6 @@ Devise.setup do |config|
|
|
42
45
|
# time the user will be asked for credentials again.
|
43
46
|
# config.timeout_in = 10.minutes
|
44
47
|
|
45
|
-
# Configure the e-mail address which will be shown in DeviseMailer.
|
46
|
-
config.mailer_sender = "please-change-me@config-initializers-devise.com"
|
47
|
-
|
48
48
|
# Load and configure the ORM. Supports :active_record, :data_mapper and :mongo_mapper.
|
49
49
|
# require 'devise/orm/mongo_mapper'
|
50
50
|
# config.orm = :mongo_mapper
|
@@ -54,6 +54,16 @@ Devise.setup do |config|
|
|
54
54
|
# are using only default views.
|
55
55
|
# config.scoped_views = true
|
56
56
|
|
57
|
+
# By default, devise detects the role accessed based on the url. So whenever
|
58
|
+
# accessing "/users/sign_in", it knows you are accessing an User. This makes
|
59
|
+
# routes as "/sign_in" not possible, unless you tell Devise to use the default
|
60
|
+
# scope, setting true below.
|
61
|
+
# config.use_default_scope = true
|
62
|
+
|
63
|
+
# Configure the default scope used by Devise. By default it's the first devise
|
64
|
+
# role declared in your routes.
|
65
|
+
# config.default_scope = :user
|
66
|
+
|
57
67
|
# If you want to use other strategies, that are not (yet) supported by Devise,
|
58
68
|
# you can configure them inside the config.warden block. The example below
|
59
69
|
# allows you to setup OAuth, using http://github.com/roman/warden_oauth
|
data/lib/devise.rb
CHANGED
@@ -16,6 +16,7 @@ module Devise
|
|
16
16
|
autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
|
17
17
|
autoload :Sha512, 'devise/encryptors/sha512'
|
18
18
|
autoload :Sha1, 'devise/encryptors/sha1'
|
19
|
+
autoload :BCrypt, 'devise/encryptors/bcrypt'
|
19
20
|
end
|
20
21
|
|
21
22
|
module Orm
|
@@ -103,6 +104,18 @@ module Devise
|
|
103
104
|
mattr_accessor :scoped_views
|
104
105
|
@@scoped_views = false
|
105
106
|
|
107
|
+
# Tell when to use the default scope, if one cannot be found from routes.
|
108
|
+
mattr_accessor :use_default_scope
|
109
|
+
@@use_default_scope
|
110
|
+
|
111
|
+
# The default scope which is used by warden.
|
112
|
+
mattr_accessor :default_scope
|
113
|
+
@@default_scope = nil
|
114
|
+
|
115
|
+
# Address which sends Devise e-mails.
|
116
|
+
mattr_accessor :mailer_sender
|
117
|
+
@@mailer_sender
|
118
|
+
|
106
119
|
class << self
|
107
120
|
# Default way to setup Devise. Run script/generate devise_install to create
|
108
121
|
# a fresh initializer with all configuration values.
|
@@ -110,12 +123,6 @@ module Devise
|
|
110
123
|
yield self
|
111
124
|
end
|
112
125
|
|
113
|
-
# Sets the sender in DeviseMailer.
|
114
|
-
def mailer_sender=(value)
|
115
|
-
DeviseMailer.sender = value
|
116
|
-
end
|
117
|
-
alias :sender= :mailer_sender=
|
118
|
-
|
119
126
|
# Sets warden configuration using a block that will be invoked on warden
|
120
127
|
# initialization.
|
121
128
|
#
|
@@ -138,15 +145,16 @@ module Devise
|
|
138
145
|
|
139
146
|
# A method used internally to setup warden manager from the Rails initialize
|
140
147
|
# block.
|
141
|
-
def
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
148
|
+
def configure_warden(config) #:nodoc:
|
149
|
+
config.default_strategies *Devise::STRATEGIES
|
150
|
+
config.default_serializers *Devise::SERIALIZERS
|
151
|
+
config.failure_app = Devise::FailureApp
|
152
|
+
config.silence_missing_strategies!
|
153
|
+
config.silence_missing_serializers!
|
154
|
+
config.default_scope = Devise.default_scope
|
147
155
|
|
148
156
|
# If the user provided a warden hook, call it now.
|
149
|
-
@warden_config.try :call,
|
157
|
+
@warden_config.try :call, config
|
150
158
|
end
|
151
159
|
|
152
160
|
# The class of the configured ORM
|
@@ -171,6 +179,5 @@ end
|
|
171
179
|
# Clear some Warden default configuration which will be overwritten
|
172
180
|
Warden::Strategies.clear!
|
173
181
|
Warden::Serializers.clear!
|
174
|
-
Warden::Manager.default_scope = nil
|
175
182
|
|
176
|
-
require 'devise/rails'
|
183
|
+
require 'devise/rails'
|
@@ -35,7 +35,11 @@ module Devise
|
|
35
35
|
|
36
36
|
# Attempt to find the mapped route for devise based on request path
|
37
37
|
def devise_mapping
|
38
|
-
@devise_mapping ||=
|
38
|
+
@devise_mapping ||= begin
|
39
|
+
mapping = Devise::Mapping.find_by_path(request.path)
|
40
|
+
mapping ||= Devise.mappings[Devise.default_scope] if Devise.use_default_scope
|
41
|
+
mapping
|
42
|
+
end
|
39
43
|
end
|
40
44
|
|
41
45
|
# Overwrites devise_controller? to return true
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "bcrypt"
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
# Implements a way of adding different encryptions.
|
5
|
+
# The class should implement a self.digest method that taks the following params:
|
6
|
+
# - password
|
7
|
+
# - stretches: the number of times the encryption will be applied
|
8
|
+
# - salt: the password salt as defined by devise
|
9
|
+
# - pepper: Devise config option
|
10
|
+
#
|
11
|
+
module Encryptors
|
12
|
+
# = BCrypt
|
13
|
+
# Uses the BCrypt hash algorithm to encrypt passwords.
|
14
|
+
class BCrypt
|
15
|
+
|
16
|
+
# Gererates a default password digest based on stretches, salt, pepper and the
|
17
|
+
# incoming password. We don't strech it ourselves since BCrypt does so internally.
|
18
|
+
def self.digest(password, stretches, salt, pepper)
|
19
|
+
::BCrypt::Engine.hash_secret(password, [salt, pepper].flatten.join('xx'), stretches)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# After each sign in, update sign in time, sign in count and sign in IP.
|
2
|
-
Warden::Manager.
|
2
|
+
Warden::Manager.after_set_user :event => [:authentication, :set_user] do |record, warden, options|
|
3
3
|
scope = options[:scope]
|
4
4
|
if Devise.mappings[scope].try(:trackable?) && warden.authenticated?(scope)
|
5
5
|
old_current, new_current = record.current_sign_in_at, Time.now
|
data/lib/devise/mapping.rb
CHANGED
@@ -29,7 +29,7 @@ module Devise
|
|
29
29
|
def self.find_by_path(path)
|
30
30
|
Devise.mappings.each_value do |mapping|
|
31
31
|
route = path.split("/")[mapping.as_position]
|
32
|
-
return mapping if mapping.as == route.to_sym
|
32
|
+
return mapping if route && mapping.as == route.to_sym
|
33
33
|
end
|
34
34
|
nil
|
35
35
|
end
|
@@ -1,8 +1,20 @@
|
|
1
1
|
module Devise
|
2
2
|
module Orm
|
3
3
|
module DataMapper
|
4
|
+
module InstanceMethods
|
5
|
+
def save(flag=nil)
|
6
|
+
if flag == false
|
7
|
+
save!
|
8
|
+
else
|
9
|
+
super()
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
4
14
|
def self.included_modules_hook(klass, modules)
|
5
15
|
klass.send :extend, self
|
16
|
+
klass.send :include, InstanceMethods
|
17
|
+
|
6
18
|
yield
|
7
19
|
|
8
20
|
modules.each do |mod|
|
@@ -19,11 +31,24 @@ module Devise
|
|
19
31
|
|
20
32
|
# Hooks for confirmable
|
21
33
|
def before_create(*args)
|
22
|
-
before
|
34
|
+
wrap_hook(:before, *args)
|
23
35
|
end
|
24
36
|
|
25
37
|
def after_create(*args)
|
26
|
-
after
|
38
|
+
wrap_hook(:after, *args)
|
39
|
+
end
|
40
|
+
|
41
|
+
def wrap_hook(action, *args)
|
42
|
+
options = args.extract_options!
|
43
|
+
|
44
|
+
args.each do |callback|
|
45
|
+
send action, :create, callback
|
46
|
+
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
47
|
+
def #{callback}
|
48
|
+
super if #{options[:if] || true}
|
49
|
+
end
|
50
|
+
METHOD
|
51
|
+
end
|
27
52
|
end
|
28
53
|
|
29
54
|
# Add ActiveRecord like finder
|
@@ -39,15 +64,6 @@ module Devise
|
|
39
64
|
end
|
40
65
|
end
|
41
66
|
|
42
|
-
# In Datamapper, we need to call save! if we don't want to execute callbacks.
|
43
|
-
def save(flag=nil)
|
44
|
-
if flag == false
|
45
|
-
save!
|
46
|
-
else
|
47
|
-
super()
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
67
|
# Tell how to apply schema methods. This automatically maps :limit to
|
52
68
|
# :length and :null to :nullable.
|
53
69
|
def apply_schema(name, type, options={})
|
@@ -64,4 +80,4 @@ module Devise
|
|
64
80
|
end
|
65
81
|
end
|
66
82
|
|
67
|
-
DataMapper::Model.send(:include, Devise::Models)
|
83
|
+
DataMapper::Model.send(:include, Devise::Models)
|
data/lib/devise/rails.rb
CHANGED
@@ -6,8 +6,8 @@ Rails.configuration.after_initialize do
|
|
6
6
|
|
7
7
|
# Adds Warden Manager to Rails middleware stack, configuring default devise
|
8
8
|
# strategy and also the failure app.
|
9
|
-
Rails.configuration.middleware.use Warden::Manager do |
|
10
|
-
Devise.
|
9
|
+
Rails.configuration.middleware.use Warden::Manager do |config|
|
10
|
+
Devise.configure_warden(config)
|
11
11
|
end
|
12
12
|
|
13
13
|
I18n.load_path.unshift File.expand_path(File.join(File.dirname(__FILE__), 'locales', 'en.yml'))
|
data/lib/devise/rails/routes.rb
CHANGED
@@ -82,7 +82,7 @@ module ActionController::Routing
|
|
82
82
|
resources.map!(&:to_sym)
|
83
83
|
resources.each do |resource|
|
84
84
|
mapping = Devise::Mapping.new(resource, options.dup)
|
85
|
-
|
85
|
+
Devise.default_scope ||= mapping.name
|
86
86
|
Devise.mappings[mapping.name] = mapping
|
87
87
|
|
88
88
|
route_options = mapping.route_options.merge(:path_prefix => mapping.raw_path, :name_prefix => "#{mapping.name}_")
|
data/lib/devise/test_helpers.rb
CHANGED
@@ -7,17 +7,17 @@ module Devise
|
|
7
7
|
end
|
8
8
|
|
9
9
|
# This is a Warden::Proxy customized for functional tests. It's meant to
|
10
|
-
# some of Warden::Manager
|
10
|
+
# some of Warden::Manager responsibilities, as retrieving configuration
|
11
11
|
# options and calling the FailureApp.
|
12
12
|
class TestWarden < Warden::Proxy #:nodoc:
|
13
13
|
attr_reader :controller
|
14
14
|
|
15
15
|
def initialize(controller)
|
16
16
|
@controller = controller
|
17
|
-
manager = Warden::Manager.new(nil) do |
|
18
|
-
Devise.
|
17
|
+
manager = Warden::Manager.new(nil) do |config|
|
18
|
+
Devise.configure_warden(config)
|
19
19
|
end
|
20
|
-
super(controller.request.env, manager
|
20
|
+
super(controller.request.env, manager)
|
21
21
|
end
|
22
22
|
|
23
23
|
def authenticate!(*args)
|
data/lib/devise/version.rb
CHANGED
data/test/devise_test.rb
CHANGED
@@ -7,43 +7,6 @@ module Devise
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class DeviseTest < ActiveSupport::TestCase
|
10
|
-
class MockManager
|
11
|
-
attr_accessor :failure_app
|
12
|
-
attr_reader :default_strategies, :silence_missing_strategies
|
13
|
-
|
14
|
-
def silence_missing_strategies!
|
15
|
-
@silence_missing_strategies = true
|
16
|
-
end
|
17
|
-
|
18
|
-
def silence_missing_serializers!
|
19
|
-
@silence_missing_serializers = true
|
20
|
-
end
|
21
|
-
|
22
|
-
def default_strategies(*args)
|
23
|
-
if args.empty?
|
24
|
-
@default_strategies
|
25
|
-
else
|
26
|
-
@default_strategies = args
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def default_serializers(*args)
|
31
|
-
if args.empty?
|
32
|
-
@default_serializers
|
33
|
-
else
|
34
|
-
@default_serializers = args
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
test 'DeviseMailer.sender can be configured through Devise' do
|
40
|
-
swap DeviseMailer, :sender => "foo@bar" do
|
41
|
-
assert_equal "foo@bar", DeviseMailer.sender
|
42
|
-
Devise.mailer_sender = "bar@foo"
|
43
|
-
assert_equal "bar@foo", DeviseMailer.sender
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
10
|
test 'model options can be configured through Devise' do
|
48
11
|
swap Devise, :confirm_within => 113, :pepper => "foo" do
|
49
12
|
assert_equal 113, Devise.confirm_within
|
@@ -58,28 +21,25 @@ class DeviseTest < ActiveSupport::TestCase
|
|
58
21
|
end
|
59
22
|
|
60
23
|
test 'warden manager configuration' do
|
61
|
-
|
62
|
-
Devise.
|
63
|
-
|
64
|
-
assert_equal Devise::FailureApp, manager.failure_app
|
65
|
-
assert_equal [:authenticatable], manager.default_strategies
|
66
|
-
assert manager.silence_missing_strategies
|
67
|
-
end
|
24
|
+
config = Warden::Config.new
|
25
|
+
Devise.configure_warden(config)
|
68
26
|
|
69
|
-
|
70
|
-
assert_equal :
|
27
|
+
assert_equal Devise::FailureApp, config.failure_app
|
28
|
+
assert_equal [:authenticatable], config.default_strategies
|
29
|
+
assert_equal :user, config.default_scope
|
30
|
+
assert config.silence_missing_strategies?
|
31
|
+
assert config.silence_missing_serializers?
|
71
32
|
end
|
72
33
|
|
73
34
|
test 'warden manager user configuration through a block' do
|
74
35
|
begin
|
75
36
|
@executed = false
|
76
|
-
Devise.warden do |
|
37
|
+
Devise.warden do |config|
|
77
38
|
@executed = true
|
78
|
-
assert_kind_of
|
39
|
+
assert_kind_of Warden::Config, config
|
79
40
|
end
|
80
41
|
|
81
|
-
|
82
|
-
Devise.configure_warden_manager(manager)
|
42
|
+
Devise.configure_warden(Warden::Config.new)
|
83
43
|
assert @executed
|
84
44
|
ensure
|
85
45
|
Devise.clean_warden_config!
|
data/test/encryptors_test.rb
CHANGED
@@ -17,6 +17,14 @@ class Encryptors < ActiveSupport::TestCase
|
|
17
17
|
encryptor = Devise::Encryptors::ClearanceSha1.digest('123mudar', nil, '65c58472c207c829f28c68619d3e3aefed18ab3f', nil)
|
18
18
|
assert_equal clearance, encryptor
|
19
19
|
end
|
20
|
+
|
21
|
+
test 'should match a password created by bcrypt' do
|
22
|
+
bcrypt = "$2a$10$81UWRL4S01M6zxjMPyBame1He8EHYgdFm26rQh0qKzglf2ijtEyfa"
|
23
|
+
encryptor = Devise::Encryptors::BCrypt.digest('123mudar', 4, '$2a$10$81UWRL4S01M6zxjMPyBame', '')
|
24
|
+
assert_equal bcrypt, encryptor
|
25
|
+
end
|
26
|
+
|
27
|
+
|
20
28
|
|
21
29
|
Devise::ENCRYPTORS_LENGTH.each do |key, value|
|
22
30
|
test "should have length #{value} for #{key.inspect}" do
|
@@ -154,12 +154,6 @@ class AuthenticationTest < ActionController::IntegrationTest
|
|
154
154
|
assert_contain 'You need to sign in or sign up before continuing.'
|
155
155
|
end
|
156
156
|
|
157
|
-
test 'render 404 on roles without permission' do
|
158
|
-
get 'admin_area/password/new'
|
159
|
-
assert_response :not_found
|
160
|
-
assert_not_contain 'Send me reset password instructions'
|
161
|
-
end
|
162
|
-
|
163
157
|
test 'return to default url if no other was requested' do
|
164
158
|
sign_in_as_user
|
165
159
|
|
@@ -221,4 +215,24 @@ class AuthenticationTest < ActionController::IntegrationTest
|
|
221
215
|
end
|
222
216
|
end
|
223
217
|
end
|
218
|
+
|
219
|
+
test 'render 404 on roles without permission' do
|
220
|
+
get 'admin_area/password/new'
|
221
|
+
assert_response :not_found
|
222
|
+
assert_not_contain 'Send me reset password instructions'
|
223
|
+
end
|
224
|
+
|
225
|
+
test 'render 404 on roles without mapping' do
|
226
|
+
get 'sign_in'
|
227
|
+
assert_response :not_found
|
228
|
+
assert_not_contain 'Sign in'
|
229
|
+
end
|
230
|
+
|
231
|
+
test 'uses the mapping from the default scope if specified' do
|
232
|
+
swap Devise, :use_default_scope => true do
|
233
|
+
get 'sign_in'
|
234
|
+
assert_response :ok
|
235
|
+
assert_contain 'Sign in'
|
236
|
+
end
|
237
|
+
end
|
224
238
|
end
|
@@ -60,6 +60,14 @@ class ConfirmationTest < ActionController::IntegrationTest
|
|
60
60
|
assert warden.authenticated?(:user)
|
61
61
|
end
|
62
62
|
|
63
|
+
test 'increases sign count when signed in through confirmation' do
|
64
|
+
user = create_user(:confirm => false)
|
65
|
+
visit_user_confirmation_with_token(user.confirmation_token)
|
66
|
+
|
67
|
+
user.reload
|
68
|
+
assert_equal 1, user.sign_in_count
|
69
|
+
end
|
70
|
+
|
63
71
|
test 'not confirmed user with setup to block without confirmation should not be able to sign in' do
|
64
72
|
swap Devise, :confirm_within => 0.days do
|
65
73
|
sign_in_as_user(:confirm => false)
|
@@ -51,7 +51,7 @@ class TrackableHooksTest < ActionController::IntegrationTest
|
|
51
51
|
assert_equal 2, user.sign_in_count
|
52
52
|
end
|
53
53
|
|
54
|
-
test "does not update anything if user
|
54
|
+
test "does not update anything if user has signed out along the way" do
|
55
55
|
swap Devise, :confirm_within => 0 do
|
56
56
|
user = create_user(:confirm => false)
|
57
57
|
sign_in_as_user
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
# Specifies gem version of Rails to use when vendor/rails is not present
|
4
4
|
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
|
5
|
+
DEVISE_ORM = :active_record unless defined? DEVISE_ORM
|
5
6
|
|
6
7
|
# Bootstrap the Rails environment, frameworks, and default configuration
|
7
8
|
require File.join(File.dirname(__FILE__), 'boot')
|
@@ -18,4 +18,7 @@ ActiveSupport.use_standard_json_time_format = true
|
|
18
18
|
|
19
19
|
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
|
20
20
|
# if you're including raw json in an HTML page.
|
21
|
-
ActiveSupport.escape_html_entities_in_json = false
|
21
|
+
ActiveSupport.escape_html_entities_in_json = false
|
22
|
+
|
23
|
+
# Clean up silencers
|
24
|
+
Rails.backtrace_cleaner.remove_silencers!
|
@@ -12,6 +12,7 @@ ActionController::Routing::Routes.draw do |map|
|
|
12
12
|
map.connect '/admin_area/password/new', :controller => "passwords", :action => "new"
|
13
13
|
map.admin_root '/admin_area/home', :controller => "admins", :action => "index"
|
14
14
|
|
15
|
+
map.connect '/sign_in', :controller => "sessions", :action => "new"
|
15
16
|
map.connect ':controller/:action/:id'
|
16
17
|
map.connect ':controller/:action/:id.:format'
|
17
18
|
end
|
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: 0.
|
4
|
+
version: 0.8.0
|
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-01-
|
13
|
+
date: 2010-01-07 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.
|
24
|
+
version: 0.8.0
|
25
25
|
version:
|
26
26
|
description: Flexible authentication solution for Rails with Warden
|
27
27
|
email: contact@plataformatec.com.br
|
@@ -31,6 +31,7 @@ extensions: []
|
|
31
31
|
|
32
32
|
extra_rdoc_files:
|
33
33
|
- README.rdoc
|
34
|
+
- TODO
|
34
35
|
files:
|
35
36
|
- CHANGELOG.rdoc
|
36
37
|
- MIT-LICENSE
|
@@ -50,11 +51,11 @@ files:
|
|
50
51
|
- generators/devise/USAGE
|
51
52
|
- generators/devise/devise_generator.rb
|
52
53
|
- generators/devise/lib/route_devise.rb
|
53
|
-
- generators/devise/templates/README
|
54
54
|
- generators/devise/templates/migration.rb
|
55
55
|
- generators/devise/templates/model.rb
|
56
56
|
- generators/devise_install/USAGE
|
57
57
|
- generators/devise_install/devise_install_generator.rb
|
58
|
+
- generators/devise_install/templates/README
|
58
59
|
- generators/devise_install/templates/devise.rb
|
59
60
|
- generators/devise_views/USAGE
|
60
61
|
- generators/devise_views/devise_views_generator.rb
|
@@ -64,6 +65,7 @@ files:
|
|
64
65
|
- lib/devise/controllers/helpers.rb
|
65
66
|
- lib/devise/controllers/url_helpers.rb
|
66
67
|
- lib/devise/encryptors/authlogic_sha512.rb
|
68
|
+
- lib/devise/encryptors/bcrypt.rb
|
67
69
|
- lib/devise/encryptors/clearance_sha1.rb
|
68
70
|
- lib/devise/encryptors/restful_authentication_sha1.rb
|
69
71
|
- lib/devise/encryptors/sha1.rb
|
@@ -1,22 +0,0 @@
|
|
1
|
-
|
2
|
-
================================================================================
|
3
|
-
|
4
|
-
Some setup you must do manually if you haven't yet:
|
5
|
-
|
6
|
-
1. Setup defaut url options for your specific environment. Here is an example of development environment:
|
7
|
-
|
8
|
-
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
9
|
-
|
10
|
-
It's a Rails required configuration. In production it must be the actual host your application is deployed to.
|
11
|
-
|
12
|
-
2. Setup default sender for mails. In config/environment.rb:
|
13
|
-
|
14
|
-
DeviseMailer.sender = "test@example.com"
|
15
|
-
|
16
|
-
You can also configure this value by running script/generate devise_install and setting config.mailer_sender,
|
17
|
-
|
18
|
-
3. Ensure you have defined root_url to *something* in your config/routes.rb:
|
19
|
-
|
20
|
-
map.root :controller => 'home'
|
21
|
-
|
22
|
-
================================================================================
|