Feature #21421 » 0003-Send-a-security-notification-when-a-user-s-password-.patch
| app/controllers/account_controller.rb | ||
|---|---|---|
|
@user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
||
|
if @user.save
|
||
|
@token.destroy
|
||
|
Mailer.security_notification(@user,
|
||
|
message: :mail_body_security_notification_change,
|
||
|
field: :field_password,
|
||
|
title: :button_change_password,
|
||
|
url: {controller: 'my', action: 'password'}
|
||
|
).deliver
|
||
|
flash[:notice] = l(:notice_account_password_updated)
|
||
|
redirect_to signin_path
|
||
|
return
|
||
| app/controllers/my_controller.rb | ||
|---|---|---|
|
if @user.save
|
||
|
# The session token was destroyed by the password change, generate a new one
|
||
|
session[:tk] = @user.generate_session_token
|
||
|
Mailer.security_notification(@user,
|
||
|
message: :mail_body_security_notification_change,
|
||
|
field: :field_password,
|
||
|
title: :button_change_password,
|
||
|
url: {controller: 'my', action: 'password'}
|
||
|
).deliver
|
||
|
flash[:notice] = l(:notice_account_password_updated)
|
||
|
redirect_to my_account_path
|
||
|
end
|
||
| test/functional/account_controller_test.rb | ||
|---|---|---|
|
end
|
||
|
def test_post_lost_password_with_token_should_change_the_user_password
|
||
|
ActionMailer::Base.deliveries.clear
|
||
|
user = User.find(2)
|
||
|
token = Token.create!(:action => 'recovery', :user => user)
|
||
| ... | ... | |
|
user.reload
|
||
|
assert user.check_password?('newpass123')
|
||
|
assert_nil Token.find_by_id(token.id), "Token was not deleted"
|
||
|
assert_not_nil (mail = ActionMailer::Base.deliveries.last)
|
||
|
assert_select_email do
|
||
|
assert_select 'a[href^=?]', 'http://localhost:3000/my/password', :text => 'Change password'
|
||
|
end
|
||
|
end
|
||
|
def test_post_lost_password_with_token_for_non_active_user_should_fail
|
||
| test/functional/my_controller_test.rb | ||
|---|---|---|
|
assert_redirected_to '/my/account'
|
||
|
end
|
||
|
def test_change_password_should_send_security_notification
|
||
|
ActionMailer::Base.deliveries.clear
|
||
|
post :password, :password => 'jsmith',
|
||
|
:new_password => 'secret123',
|
||
|
:new_password_confirmation => 'secret123'
|
||
|
assert_not_nil (mail = ActionMailer::Base.deliveries.last)
|
||
|
assert_mail_body_no_match 'secret123', mail # just to be sure: pw should never be sent!
|
||
|
assert_select_email do
|
||
|
assert_select 'a[href^=?]', 'http://localhost:3000/my/password', :text => 'Change password'
|
||
|
end
|
||
|
end
|
||
|
def test_page_layout
|
||
|
get :page_layout
|
||
|
assert_response :success
|
||