FIX: Incorrect message when logging in via email

If `hide email address taken` was true, it would always display a
success message, rather than the non-comittal "maybe we emailed that
user" response.
This commit is contained in:
Robin Ward 2020-03-09 12:53:32 -04:00
parent 3ad5cb0cbc
commit ec21a15fa7
3 changed files with 12 additions and 4 deletions

View File

@ -296,8 +296,12 @@ export default Controller.extend(ModalFunctionality, {
"error" "error"
); );
} else { } else {
let postfix = data.hide_taken ? "" : "_found";
this.flash( this.flash(
I18n.t(`${key}_found`, { email: loginName, username: loginName }) I18n.t(`${key}${postfix}`, {
email: loginName,
username: loginName
})
); );
} }
}) })

View File

@ -748,6 +748,7 @@ class UsersController < ApplicationController
end end
json = success_json json = success_json
json[:hide_taken] = SiteSetting.hide_email_address_taken
json[:user_found] = user_presence unless SiteSetting.hide_email_address_taken json[:user_found] = user_presence unless SiteSetting.hide_email_address_taken
render json: json render json: json
rescue RateLimiter::LimitExceeded rescue RateLimiter::LimitExceeded

View File

@ -3455,7 +3455,6 @@ describe UsersController do
it 'should return the right response' do it 'should return the right response' do
post "/u/email-login.json", params: { login: user.email } post "/u/email-login.json", params: { login: user.email }
expect(response.status).to eq(404) expect(response.status).to eq(404)
end end
end end
@ -3465,7 +3464,9 @@ describe UsersController do
post "/u/email-login.json", params: { login: '@random' } post "/u/email-login.json", params: { login: '@random' }
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(JSON.parse(response.body)['user_found']).to eq(false) json = JSON.parse(response.body)
expect(json['user_found']).to eq(false)
expect(json['hide_taken']).to eq(false)
expect(Jobs::CriticalUserEmail.jobs).to eq([]) expect(Jobs::CriticalUserEmail.jobs).to eq([])
end end
end end
@ -3476,7 +3477,9 @@ describe UsersController do
post "/u/email-login.json", params: { login: user.email } post "/u/email-login.json", params: { login: user.email }
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(JSON.parse(response.body).has_key?('user_found')).to eq(false) json = JSON.parse(response.body)
expect(json.has_key?('user_found')).to eq(false)
expect(json['hide_taken']).to eq(true)
end end
end end