Skip to content

Commit 7212cf0

Browse files
author
Mark Ericksen
committed
Forgot password now matches email without case consideration. Fixes #8861
Updates forgot_password to use newer (and already existing) named scopes for better searching. Uses a case-insensitive search by email that is supported on multiple databases. Additional minor refactor to clean up code and only do the search if an email is given. Blanks don't count anymore. Testing Notes: * Create a user with a CommunicationChannel email that has mixed case like "Tom.Thumb@example.com" * Doing a "forgot password" from login should now match and generate an email. Change-Id: I1bec847fbae8b43e949210b010aa2cfad438ce55 Reviewed-on: https://gerrit.instructure.com/11193 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Joe Tanner <joe@instructure.com>
1 parent 8e116ea commit 7212cf0

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

app/controllers/pseudonyms_controller.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,17 @@ def index
5959
def forgot_password
6060
email = params[:pseudonym_session][:unique_id_forgot] if params[:pseudonym_session]
6161
@ccs = []
62-
@ccs = CommunicationChannel.find_all_by_path_and_path_type_and_workflow_state(email, 'email', 'active')
63-
if @ccs.empty?
64-
@ccs += CommunicationChannel.find_all_by_path_and_path_type(email, 'email') if email and !email.empty?
65-
end
66-
if @domain_root_account && email && !email.empty?
67-
@domain_root_account.pseudonyms.active.custom_find_by_unique_id(email, :all).each do |p|
68-
cc = p.communication_channel if p.communication_channel && p.user
69-
cc ||= p.user.communication_channel rescue nil
70-
@ccs << cc
62+
if email.present?
63+
@ccs = CommunicationChannel.email.by_path(email).active.all
64+
if @ccs.empty?
65+
@ccs += CommunicationChannel.email.by_path(email).all
66+
end
67+
if @domain_root_account
68+
@domain_root_account.pseudonyms.active.custom_find_by_unique_id(email, :all).each do |p|
69+
cc = p.communication_channel if p.communication_channel && p.user
70+
cc ||= p.user.communication_channel rescue nil
71+
@ccs << cc
72+
end
7173
end
7274
end
7375
@ccs = @ccs.flatten.compact.uniq.select do |cc|

spec/controllers/pseudonyms_controller_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@
6262
assigns[:ccs].detect{|cc| cc == @cc}.messages_sent.should_not be_empty
6363
end
6464

65+
it "should use case insensitive match for CommunicationChannel email" do
66+
# Setup user with communication channel that has mixed case email
67+
user_with_pseudonym
68+
@cc = communication_channel_model(:user_id => @user.id, :workflow_state => 'active', :path => 'Victoria.Silvstedt@example.com')
69+
get 'forgot_password', :pseudonym_session => {:unique_id_forgot => 'victoria.silvstedt@example.com'}
70+
response.should be_redirect
71+
assigns[:ccs].should include(@cc)
72+
assigns[:ccs].detect{|cc| cc == @cc}.messages_sent.should_not be_nil
73+
assigns[:ccs].detect{|cc| cc == @cc}.messages_sent.should_not be_empty
74+
end
6575
it "should send password-change email case insensitively" do
6676
user_with_pseudonym(:username => 'user1@example.com')
6777
get 'forgot_password', :pseudonym_session => {:unique_id_forgot => 'USER1@EXAMPLE.COM'}

0 commit comments

Comments
 (0)