Code cleanup.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9943 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
a1d0acd632
commit
193b571e67
|
@ -63,11 +63,17 @@ class AccountController < ApplicationController
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
if request.post?
|
if request.post?
|
||||||
user = User.find_by_mail(params[:mail])
|
user = User.find_by_mail(params[:mail].to_s)
|
||||||
# user not found in db
|
# user not found or not active
|
||||||
(flash.now[:error] = l(:notice_account_unknown_email); return) unless user
|
unless user && user.active?
|
||||||
# user uses an external authentification
|
flash.now[:error] = l(:notice_account_unknown_email)
|
||||||
(flash.now[:error] = l(:notice_can_t_change_password); return) if user.auth_source_id
|
return
|
||||||
|
end
|
||||||
|
# user cannot change its password
|
||||||
|
unless user.change_password_allowed?
|
||||||
|
flash.now[:error] = l(:notice_can_t_change_password)
|
||||||
|
return
|
||||||
|
end
|
||||||
# create a new token for password recovery
|
# create a new token for password recovery
|
||||||
token = Token.new(:user => user, :action => "recovery")
|
token = Token.new(:user => user, :action => "recovery")
|
||||||
if token.save
|
if token.save
|
||||||
|
|
|
@ -141,4 +141,45 @@ class AccountControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_get_lost_password_should_display_lost_password_form
|
||||||
|
get :lost_password
|
||||||
|
assert_response :success
|
||||||
|
assert_select 'input[name=mail]'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_lost_password_for_active_user_should_create_a_token
|
||||||
|
assert_difference 'ActionMailer::Base.deliveries.size' do
|
||||||
|
assert_difference 'Token.count' do
|
||||||
|
with_settings :host_name => 'mydomain.foo', :protocol => 'http' do
|
||||||
|
post :lost_password, :mail => 'JSmith@somenet.foo'
|
||||||
|
assert_redirected_to '/login'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
token = Token.order('id DESC').first
|
||||||
|
assert_equal User.find(2), token.user
|
||||||
|
assert_equal 'recovery', token.action
|
||||||
|
|
||||||
|
assert_select_email do
|
||||||
|
assert_select "a[href=?]", "http://mydomain.foo/account/lost_password?token=#{token.value}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_lost_password_for_unknown_user_should_fail
|
||||||
|
assert_no_difference 'Token.count' do
|
||||||
|
post :lost_password, :mail => 'invalid@somenet.foo'
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_lost_password_for_non_active_user_should_fail
|
||||||
|
assert User.find(2).lock!
|
||||||
|
|
||||||
|
assert_no_difference 'Token.count' do
|
||||||
|
post :lost_password, :mail => 'JSmith@somenet.foo'
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue