devise 0.8.2 → 0.9.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 +21 -2
- data/README.rdoc +40 -54
- data/Rakefile +1 -1
- data/TODO +1 -3
- data/app/controllers/confirmations_controller.rb +9 -20
- data/app/controllers/passwords_controller.rb +9 -20
- data/app/controllers/sessions_controller.rb +9 -9
- data/app/controllers/unlocks_controller.rb +22 -0
- data/app/models/devise_mailer.rb +6 -1
- data/app/views/confirmations/new.html.erb +1 -5
- data/app/views/devise_mailer/unlock_instructions.html.erb +7 -0
- data/app/views/passwords/edit.html.erb +1 -5
- data/app/views/passwords/new.html.erb +1 -5
- data/app/views/sessions/new.html.erb +1 -7
- data/app/views/shared/_devise_links.erb +15 -0
- data/app/views/unlocks/new.html.erb +12 -0
- data/generators/devise/templates/migration.rb +2 -0
- data/generators/devise/templates/model.rb +4 -1
- data/generators/devise_install/templates/devise.rb +20 -10
- data/lib/devise.rb +62 -18
- data/lib/devise/controllers/common.rb +24 -0
- data/lib/devise/controllers/helpers.rb +160 -80
- data/lib/devise/controllers/internal_helpers.rb +120 -0
- data/lib/devise/controllers/url_helpers.rb +2 -10
- data/lib/devise/encryptors/bcrypt.rb +2 -2
- data/lib/devise/hooks/activatable.rb +1 -4
- data/lib/devise/hooks/rememberable.rb +30 -0
- data/lib/devise/hooks/timeoutable.rb +4 -2
- data/lib/devise/locales/en.yml +9 -2
- data/lib/devise/mapping.rb +15 -11
- data/lib/devise/models.rb +16 -35
- data/lib/devise/models/activatable.rb +1 -1
- data/lib/devise/models/authenticatable.rb +1 -9
- data/lib/devise/models/confirmable.rb +6 -2
- data/lib/devise/models/lockable.rb +142 -0
- data/lib/devise/models/rememberable.rb +19 -2
- data/lib/devise/models/timeoutable.rb +1 -2
- data/lib/devise/orm/active_record.rb +2 -0
- data/lib/devise/orm/data_mapper.rb +1 -1
- data/lib/devise/orm/mongo_mapper.rb +12 -1
- data/lib/devise/rails/routes.rb +5 -1
- data/lib/devise/rails/warden_compat.rb +13 -13
- data/lib/devise/schema.rb +7 -0
- data/lib/devise/strategies/authenticatable.rb +1 -3
- data/lib/devise/strategies/base.rb +1 -1
- data/lib/devise/strategies/rememberable.rb +37 -0
- data/lib/devise/test_helpers.rb +1 -1
- data/lib/devise/version.rb +1 -1
- data/test/controllers/helpers_test.rb +155 -33
- data/test/controllers/internal_helpers_test.rb +55 -0
- data/test/devise_test.rb +24 -3
- data/test/encryptors_test.rb +3 -1
- data/test/integration/lockable_test.rb +83 -0
- data/test/integration/rememberable_test.rb +1 -1
- data/test/mailers/unlock_instructions_test.rb +62 -0
- data/test/models/authenticatable_test.rb +0 -23
- data/test/models/lockable_test.rb +202 -0
- data/test/models/timeoutable_test.rb +7 -7
- data/test/models/validatable_test.rb +2 -2
- data/test/models_test.rb +9 -76
- data/test/orm/active_record.rb +1 -0
- data/test/orm/mongo_mapper.rb +0 -1
- data/test/rails_app/app/active_record/admin.rb +1 -1
- data/test/rails_app/app/active_record/user.rb +2 -1
- data/test/rails_app/app/mongo_mapper/admin.rb +1 -1
- data/test/rails_app/app/mongo_mapper/user.rb +2 -1
- data/test/rails_app/config/initializers/devise.rb +13 -10
- data/test/rails_app/config/routes.rb +5 -3
- data/test/routes_test.rb +5 -0
- data/test/support/integration_tests_helper.rb +1 -0
- metadata +16 -12
- data/lib/devise/controllers/filters.rb +0 -186
- data/lib/devise/models/cookie_serializer.rb +0 -21
- data/lib/devise/models/session_serializer.rb +0 -19
- data/lib/devise/serializers/base.rb +0 -23
- data/lib/devise/serializers/cookie.rb +0 -43
- data/lib/devise/serializers/session.rb +0 -22
- data/test/controllers/filters_test.rb +0 -177
- data/test/rails_app/app/active_record/account.rb +0 -7
- data/test/rails_app/app/mongo_mapper/account.rb +0 -9
data/CHANGELOG.rdoc
CHANGED
@@ -1,15 +1,34 @@
|
|
1
|
+
== 0.9.0
|
2
|
+
|
3
|
+
* deprecation
|
4
|
+
* devise :all is deprecated
|
5
|
+
* :success and :failure flash messages are now :notice and :alert
|
6
|
+
|
7
|
+
* enhancements
|
8
|
+
* Added devise lockable (by github.com/mhfs)
|
9
|
+
* Warden 0.9.0 compatibility
|
10
|
+
* Mongomapper 0.6.10 compatibility
|
11
|
+
* Added Devise.add_module as hooks for extensions (by github.com/grimen)
|
12
|
+
* Ruby 1.9.1 compatibility (by github.com/grimen)
|
13
|
+
|
14
|
+
* bug fix
|
15
|
+
* Accept path prefix not starting with slash
|
16
|
+
* url helpers should rely on find_scope!
|
17
|
+
|
1
18
|
== 0.8.2
|
2
19
|
|
3
20
|
* enhancements
|
4
|
-
* Allow Devise.mailer_sender to be a proc (by github/grimen)
|
21
|
+
* Allow Devise.mailer_sender to be a proc (by github.com/grimen)
|
5
22
|
|
6
23
|
* bug fix
|
7
|
-
* Fix bug with passenger, update is required to anyone deploying on passenger (by github/dvdpalm)
|
24
|
+
* Fix bug with passenger, update is required to anyone deploying on passenger (by github.com/dvdpalm)
|
8
25
|
|
9
26
|
== 0.8.1
|
10
27
|
|
11
28
|
* enhancements
|
12
29
|
* Move salt to encryptors
|
30
|
+
* Devise::Lockable
|
31
|
+
* Moved view links into partial and I18n'ed them
|
13
32
|
|
14
33
|
* bug fix
|
15
34
|
* Bcrypt generator was not being loaded neither setting the proper salt
|
data/README.rdoc
CHANGED
@@ -7,7 +7,7 @@ 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 nine modules:
|
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.
|
@@ -15,11 +15,9 @@ Right now it's composed of six modules included by default when you invoke "devi
|
|
15
15
|
* Rememberable: manages generating and clearing token for remember the user from a saved cookie.
|
16
16
|
* Trackable: tracks sign in count, timestamps and ip.
|
17
17
|
* Validatable: creates all needed validations for email and password. It's totally optional, so you're able to to customize validations by yourself.
|
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
18
|
* Timeoutable: expires sessions without activity in a certain period of time.
|
19
|
+
* Lockable: takes care of locking an account based on the number of failed sign in attempts. Handles unlock via expire and email.
|
20
|
+
* Activatable: if you need to activate accounts by other means, which are not through confirmation, use this module.
|
23
21
|
|
24
22
|
There's an example application using Devise at http://github.com/plataformatec/devise_example .
|
25
23
|
|
@@ -50,15 +48,23 @@ Run the generator:
|
|
50
48
|
|
51
49
|
ruby script/generate devise_install
|
52
50
|
|
53
|
-
And you're ready to go. The generator will install an initializer which describes Devise's configuration options
|
51
|
+
And you're ready to go. The generator will install an initializer which describes ALL Devise's configuration options, so be sure to take a look at it and the documentation as well:
|
52
|
+
|
53
|
+
http://rdoc.info/projects/plataformatec/devise
|
54
54
|
|
55
55
|
== Basic Usage
|
56
56
|
|
57
|
-
This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration. You
|
57
|
+
This is a walkthrough with all steps you need to setup a devise resource, including model, migration, route files, and optional configuration. You MUST also check out the *Generators* section below to help you start.
|
58
58
|
|
59
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.
|
60
60
|
|
61
|
-
We're assuming here you want a User model
|
61
|
+
We're assuming here you want a User model with some modules, as outlined below:
|
62
|
+
|
63
|
+
class User < ActiveRecord::Base
|
64
|
+
devise :authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
|
65
|
+
end
|
66
|
+
|
67
|
+
After you choose which modules to use, you need to setup your migrations. Luckily, devise has some helpers to save you from this boring work:
|
62
68
|
|
63
69
|
create_table :users do |t|
|
64
70
|
t.authenticatable
|
@@ -69,48 +75,22 @@ We're assuming here you want a User model. First of all you have to setup a migr
|
|
69
75
|
t.timestamps
|
70
76
|
end
|
71
77
|
|
72
|
-
You may also want to add some indexes to improve performance:
|
73
|
-
|
74
|
-
add_index :your_table, :email
|
75
|
-
add_index :your_table, :confirmation_token # for confirmable
|
76
|
-
add_index :your_table, :reset_password_token # for recoverable
|
77
|
-
|
78
|
-
Now let's setup a User model adding the devise line:
|
79
|
-
|
80
|
-
class User < ActiveRecord::Base
|
81
|
-
devise :all
|
82
|
-
end
|
83
|
-
|
84
|
-
This will include the six default modules outlined at the beginning. You can exclude and remove any module at will:
|
85
|
-
|
86
|
-
# Include timeout configuration
|
87
|
-
devise :all, :timeoutable
|
88
|
-
|
89
|
-
# Remove validations
|
90
|
-
devise :all, :except => :validatable
|
91
|
-
|
92
78
|
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.
|
93
79
|
|
94
|
-
|
95
|
-
|
96
|
-
In addition to :except, you can provide :pepper, :stretches, :encryptor, :authentication_keys, :confirm_within, :remember_for and :timeout as options to devise method.
|
97
|
-
|
98
|
-
All those options are described in "config/initializers/devise.rb", which is generated when you invoke `ruby script/generate devise_install` in your application root.
|
99
|
-
|
100
|
-
== Routes
|
101
|
-
|
102
|
-
The next step after setting up your model is to configure your routes for devise. You do this by opening up your config/routes.rb and adding:
|
80
|
+
The next setup after setting up your model is to configure your routes. You do this by opening up your config/routes.rb and adding:
|
103
81
|
|
104
82
|
map.devise_for :users
|
105
83
|
|
106
84
|
This is going to look inside you User model and create a set of needed routes (you can see them by running `rake routes`).
|
107
85
|
|
108
|
-
There are also some options available for configuring your routes, as :class_name (to set the class for that route), :as and :path_names, where the last two have the same meaning as in common routes. The available :path_names are:
|
86
|
+
There are also some options available for configuring your routes, as :class_name (to set the class for that route), :path_prefix, :as and :path_names, where the last two have the same meaning as in common routes. The available :path_names are:
|
109
87
|
|
110
|
-
map.devise_for :users, :as => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
|
88
|
+
map.devise_for :users, :as => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock' }
|
111
89
|
|
112
90
|
Be sure to check devise_for documentation for detailed description.
|
113
91
|
|
92
|
+
After this steps, run your migrations, and you are ready to go! But don't finish reading, we still have a lot to tell you:
|
93
|
+
|
114
94
|
== Controller filters and helpers
|
115
95
|
|
116
96
|
Devise is gonna create some helpers to use inside your controllers and views. To setup a controller that needs user authentication, just add this before_filter:
|
@@ -129,32 +109,29 @@ You have also access to the session for this scope:
|
|
129
109
|
|
130
110
|
user_session
|
131
111
|
|
132
|
-
After signing in a user, confirming it's account or updating it's password, devise will look for a scoped root path to redirect. Example: For a :user resource, it will use user_root_path if it exists, otherwise default root_path will be used.
|
112
|
+
After signing in a user, confirming it's account or updating it's password, devise will look for a scoped root path to redirect. Example: For a :user resource, it will use user_root_path if it exists, otherwise default root_path will be used. This means that you need to set the root inside your routes:
|
133
113
|
|
134
114
|
map.root :controller => 'home'
|
135
115
|
|
136
116
|
You can also overwrite after_sign_in_path_for and after_sign_out_path_for to customize better your redirect hooks.
|
137
117
|
|
138
|
-
Finally,
|
118
|
+
Finally, you also need to setup default url options for the mailer in each environment. Here's is the configuration for config/environments/development.rb:
|
139
119
|
|
140
120
|
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
141
121
|
|
142
|
-
== Views
|
143
|
-
|
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.
|
145
|
-
|
146
122
|
== Tidying up
|
147
123
|
|
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:
|
124
|
+
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, lockable and timeoutable stuff and none of confirmation or password recovery. Just follow the same steps:
|
149
125
|
|
150
126
|
# Create a migration with the required fields
|
151
127
|
create_table :admins do |t|
|
152
128
|
t.authenticatable
|
129
|
+
t.lockable
|
153
130
|
t.trackable
|
154
131
|
end
|
155
132
|
|
156
133
|
# Inside your Admin model
|
157
|
-
devise :authenticatable, :trackable, :timeoutable
|
134
|
+
devise :authenticatable, :trackable, :timeoutable, :lockable
|
158
135
|
|
159
136
|
# Inside your routes
|
160
137
|
map.devise_for :admin
|
@@ -179,11 +156,23 @@ This will generate an initializer, with a description of all configuration value
|
|
179
156
|
|
180
157
|
A model configured with all devise modules and attr_accessible for default fields will be created. The generator will also create the migration and configure your routes for devise.
|
181
158
|
|
182
|
-
|
159
|
+
== Model configuration
|
160
|
+
|
161
|
+
The devise method in your models also accept some options to configure its modules. For example, you can chose which encryptor to use in authenticatable:
|
162
|
+
|
163
|
+
devise :authenticatable, :confirmable, :recoverable, :encryptor => :bcrypt
|
164
|
+
|
165
|
+
Besides :encryptor, you can provide :pepper, :stretches, :confirm_within, :remember_for, :timeout_in, :unlock_in and others. All those are describer in the initializer created when you invoke the devise_install generator describer above.
|
166
|
+
|
167
|
+
== Views
|
168
|
+
|
169
|
+
Since devise is an engine, it has all default views inside the gem. They are good to get you started, but you will want to customize them at some point. And Devise has a generator to make copy them all to your application:
|
183
170
|
|
184
171
|
ruby script/generate devise_views
|
185
172
|
|
186
|
-
|
173
|
+
By default Devise will use the same views for all 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 "config/initializers/devise.rb".
|
174
|
+
|
175
|
+
After doing so you will be able to have views based on the scope like 'sessions/users/new' and 'sessions/admin/new'. If no view is found within the scope, Devise will fallback to the default view.
|
187
176
|
|
188
177
|
== I18n
|
189
178
|
|
@@ -240,8 +229,7 @@ Devise implements encryption strategies for Clearance, Authlogic and Restful-Aut
|
|
240
229
|
|
241
230
|
== Other ORMs
|
242
231
|
|
243
|
-
Devise
|
244
|
-
To use it, just set Devise.orm or configure it in the initialization file (which is created with devise_install).
|
232
|
+
Devise supports both ActiveRecord (default) and MongoMapper, and has experimental Datamapper supports (in a sense that Devise test suite does not run completely with Datamapper). To choose other ORM, you just need to configure it in the initializer file.
|
245
233
|
|
246
234
|
== TODO
|
247
235
|
|
@@ -254,9 +242,7 @@ Please refer to TODO file.
|
|
254
242
|
|
255
243
|
== Contributors
|
256
244
|
|
257
|
-
|
258
|
-
* Cyril Mougel (http://github.com/shingara)
|
259
|
-
* Jonas Grimfelt (http://github.com/grimen)
|
245
|
+
We have a long running list of contributors. Check them in the CHANGELOG or do `git shortlog -s -n` in the cloned repository.
|
260
246
|
|
261
247
|
== Bugs and Feedback
|
262
248
|
|
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.9.0")
|
48
48
|
end
|
49
49
|
|
50
50
|
Jeweler::GemcutterTasks.new
|
data/TODO
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
* Make test run with DataMapper
|
1
|
+
* Make test run with DataMapper
|
2
2
|
* Add Registerable support
|
3
3
|
* Add http authentication support
|
4
|
-
* Extract SessionSerializer tests from Authenticatable
|
5
|
-
* Extract CookieSerializer tests from Authenticatable
|
6
4
|
* Extract Activatable tests from Confirmable
|
@@ -1,33 +1,22 @@
|
|
1
1
|
class ConfirmationsController < ApplicationController
|
2
|
-
include Devise::Controllers::
|
3
|
-
|
4
|
-
# GET /resource/confirmation/new
|
5
|
-
def new
|
6
|
-
build_resource
|
7
|
-
render_with_scope :new
|
8
|
-
end
|
9
|
-
|
10
|
-
# POST /resource/confirmation
|
11
|
-
def create
|
12
|
-
self.resource = resource_class.send_confirmation_instructions(params[resource_name])
|
13
|
-
|
14
|
-
if resource.errors.empty?
|
15
|
-
set_flash_message :success, :send_instructions
|
16
|
-
redirect_to new_session_path(resource_name)
|
17
|
-
else
|
18
|
-
render_with_scope :new
|
19
|
-
end
|
20
|
-
end
|
2
|
+
include Devise::Controllers::InternalHelpers
|
3
|
+
include Devise::Controllers::Common
|
21
4
|
|
22
5
|
# GET /resource/confirmation?confirmation_token=abcdef
|
23
6
|
def show
|
24
7
|
self.resource = resource_class.confirm!(:confirmation_token => params[:confirmation_token])
|
25
8
|
|
26
9
|
if resource.errors.empty?
|
27
|
-
set_flash_message :
|
10
|
+
set_flash_message :notice, :confirmed
|
28
11
|
sign_in_and_redirect(resource_name, resource)
|
29
12
|
else
|
30
13
|
render_with_scope :new
|
31
14
|
end
|
32
15
|
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def send_instructions_with
|
20
|
+
:send_confirmation_instructions
|
21
|
+
end
|
33
22
|
end
|
@@ -1,26 +1,9 @@
|
|
1
1
|
class PasswordsController < ApplicationController
|
2
|
-
include Devise::Controllers::
|
2
|
+
include Devise::Controllers::InternalHelpers
|
3
|
+
include Devise::Controllers::Common
|
3
4
|
|
4
5
|
before_filter :require_no_authentication
|
5
6
|
|
6
|
-
# GET /resource/password/new
|
7
|
-
def new
|
8
|
-
build_resource
|
9
|
-
render_with_scope :new
|
10
|
-
end
|
11
|
-
|
12
|
-
# POST /resource/password
|
13
|
-
def create
|
14
|
-
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
|
15
|
-
|
16
|
-
if resource.errors.empty?
|
17
|
-
set_flash_message :success, :send_instructions
|
18
|
-
redirect_to new_session_path(resource_name)
|
19
|
-
else
|
20
|
-
render_with_scope :new
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
7
|
# GET /resource/password/edit?reset_password_token=abcdef
|
25
8
|
def edit
|
26
9
|
self.resource = resource_class.new
|
@@ -33,10 +16,16 @@ class PasswordsController < ApplicationController
|
|
33
16
|
self.resource = resource_class.reset_password!(params[resource_name])
|
34
17
|
|
35
18
|
if resource.errors.empty?
|
36
|
-
set_flash_message :
|
19
|
+
set_flash_message :notice, :updated
|
37
20
|
sign_in_and_redirect(resource_name, resource)
|
38
21
|
else
|
39
22
|
render_with_scope :edit
|
40
23
|
end
|
41
24
|
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def send_instructions_with
|
29
|
+
:send_reset_password_instructions
|
30
|
+
end
|
42
31
|
end
|
@@ -1,24 +1,24 @@
|
|
1
1
|
class SessionsController < ApplicationController
|
2
|
-
include Devise::Controllers::
|
2
|
+
include Devise::Controllers::InternalHelpers
|
3
|
+
include Devise::Controllers::Common
|
3
4
|
|
4
5
|
before_filter :require_no_authentication, :only => [ :new, :create ]
|
5
6
|
|
6
7
|
# GET /resource/sign_in
|
7
8
|
def new
|
8
9
|
Devise::FLASH_MESSAGES.each do |message|
|
9
|
-
set_now_flash_message :
|
10
|
+
set_now_flash_message :alert, message if params.try(:[], message) == "true"
|
10
11
|
end
|
11
|
-
|
12
|
-
render_with_scope :new
|
12
|
+
super
|
13
13
|
end
|
14
14
|
|
15
15
|
# POST /resource/sign_in
|
16
16
|
def create
|
17
|
-
if authenticate(resource_name)
|
18
|
-
set_flash_message :
|
19
|
-
sign_in_and_redirect(resource_name)
|
17
|
+
if resource = authenticate(resource_name)
|
18
|
+
set_flash_message :notice, :signed_in
|
19
|
+
sign_in_and_redirect(resource_name, resource, true)
|
20
20
|
else
|
21
|
-
set_now_flash_message :
|
21
|
+
set_now_flash_message :alert, warden.message || :invalid
|
22
22
|
build_resource
|
23
23
|
render_with_scope :new
|
24
24
|
end
|
@@ -26,7 +26,7 @@ class SessionsController < ApplicationController
|
|
26
26
|
|
27
27
|
# GET /resource/sign_out
|
28
28
|
def destroy
|
29
|
-
set_flash_message :
|
29
|
+
set_flash_message :notice, :signed_out if signed_in?(resource_name)
|
30
30
|
sign_out_and_redirect(resource_name)
|
31
31
|
end
|
32
32
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class UnlocksController < ApplicationController
|
2
|
+
include Devise::Controllers::InternalHelpers
|
3
|
+
include Devise::Controllers::Common
|
4
|
+
|
5
|
+
# GET /resource/unlock?unlock_token=abcdef
|
6
|
+
def show
|
7
|
+
self.resource = resource_class.unlock!(:unlock_token => params[:unlock_token])
|
8
|
+
|
9
|
+
if resource.errors.empty?
|
10
|
+
set_flash_message :notice, :unlocked
|
11
|
+
sign_in_and_redirect(resource_name, resource)
|
12
|
+
else
|
13
|
+
render_with_scope :new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def send_instructions_with
|
20
|
+
:send_unlock_instructions
|
21
|
+
end
|
22
|
+
end
|
data/app/models/devise_mailer.rb
CHANGED
@@ -11,6 +11,10 @@ class DeviseMailer < ::ActionMailer::Base
|
|
11
11
|
setup_mail(record, :reset_password_instructions)
|
12
12
|
end
|
13
13
|
|
14
|
+
def unlock_instructions(record)
|
15
|
+
setup_mail(record, :unlock_instructions)
|
16
|
+
end
|
17
|
+
|
14
18
|
private
|
15
19
|
|
16
20
|
# Configure default email options
|
@@ -40,7 +44,8 @@ class DeviseMailer < ::ActionMailer::Base
|
|
40
44
|
|
41
45
|
def mailer_sender(mapping)
|
42
46
|
if Devise.mailer_sender.is_a?(Proc)
|
43
|
-
Devise.mailer_sender.
|
47
|
+
block_args = mapping.name if Devise.mailer_sender.arity > 0
|
48
|
+
Devise.mailer_sender.call(*block_args)
|
44
49
|
else
|
45
50
|
Devise.mailer_sender
|
46
51
|
end
|
@@ -9,8 +9,4 @@
|
|
9
9
|
<p><%= f.submit "Resend confirmation instructions" %></p>
|
10
10
|
<% end %>
|
11
11
|
|
12
|
-
<%=
|
13
|
-
|
14
|
-
<%- if devise_mapping.recoverable? %>
|
15
|
-
<%= link_to "Forgot password?", new_password_path(resource_name) %><br />
|
16
|
-
<% end -%>
|
12
|
+
<%= render :partial => "shared/devise_links" %>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Hello <%= @resource.email %>!
|
2
|
+
|
3
|
+
Your account has been locked due to an excessive amount of unsuccessful sign in attempts.
|
4
|
+
|
5
|
+
Click the link below to unlock your account:
|
6
|
+
|
7
|
+
<%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %>
|
@@ -13,8 +13,4 @@
|
|
13
13
|
<p><%= f.submit "Change my password" %></p>
|
14
14
|
<% end %>
|
15
15
|
|
16
|
-
<%=
|
17
|
-
|
18
|
-
<%- if devise_mapping.confirmable? %>
|
19
|
-
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
|
20
|
-
<% end -%>
|
16
|
+
<%= render :partial => "shared/devise_links" %>
|