Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
b8ff38b1
Commit
b8ff38b1
authored
Oct 01, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor PasswordsController to use before_actions
parent
c7b43126
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
22 deletions
+22
-22
app/controllers/passwords_controller.rb
app/controllers/passwords_controller.rb
+21
-21
spec/features/password_reset_spec.rb
spec/features/password_reset_spec.rb
+1
-1
No files found.
app/controllers/passwords_controller.rb
View file @
b8ff38b1
class
PasswordsController
<
Devise
::
PasswordsController
def
create
email
=
resource_params
[
:email
]
self
.
resource
=
resource_class
.
find_by_email
(
email
)
if
resource
&&
resource
.
ldap_user?
flash
[
:alert
]
=
"Cannot reset password for LDAP user."
respond_with
({},
location:
after_sending_reset_password_instructions_path_for
(
resource_name
))
and
return
end
unless
can_send_reset_email?
flash
[
:alert
]
=
"Instructions about how to reset your password have already been sent recently. Please wait a few minutes to try again."
respond_with
({},
location:
new_password_path
(
resource_name
))
and
return
end
super
end
before_action
:resource_from_email
,
only:
[
:create
]
before_action
:prevent_ldap_reset
,
only:
[
:create
]
before_action
:throttle_reset
,
only:
[
:create
]
def
edit
super
...
...
@@ -37,10 +23,24 @@ class PasswordsController < Devise::PasswordsController
end
end
private
protected
def
resource_from_email
email
=
resource_params
[
:email
]
self
.
resource
=
resource_class
.
find_by_email
(
email
)
end
def
prevent_ldap_reset
return
unless
resource
&&
resource
.
ldap_user?
redirect_to
after_sending_reset_password_instructions_path_for
(
resource_name
),
alert:
"Cannot reset password for LDAP user."
end
def
throttle_reset
return
unless
resource
&&
resource
.
recently_sent_password_reset?
def
can_send_reset_email?
resource
&&
(
resource
.
reset_password_sent_at
.
blank?
||
resource
.
reset_password_sent_at
<
1
.
minute
.
ago
)
redirect_to
new_password_path
(
resource_name
),
alert:
I18n
.
t
(
'devise.passwords.recently_reset'
)
end
end
spec/features/password_reset_spec.rb
View file @
b8ff38b1
...
...
@@ -29,7 +29,7 @@ feature 'Password reset', feature: true do
visit
root_path
forgot_password
(
user
)
expect
(
page
).
to
have_content
(
"Instructions about how to reset your password have already been sent recently. Please wait a few minutes to try again."
)
expect
(
page
).
to
have_content
(
I18n
.
t
(
'devise.passwords.recently_reset'
)
)
expect
(
current_path
).
to
eq
new_user_password_path
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment