Merge pull request #3034 from fantasticfears/filter_system_user

disable sending email or show presence when forgot system user password
This commit is contained in:
Robin Ward 2014-12-19 16:52:01 -05:00
commit 9bb2ab6265
2 changed files with 16 additions and 3 deletions

View file

@ -153,14 +153,15 @@ class SessionController < ApplicationController
RateLimiter.new(nil, "forgot-password-min-#{request.remote_ip}", 3, 1.minute).performed! RateLimiter.new(nil, "forgot-password-min-#{request.remote_ip}", 3, 1.minute).performed!
user = User.find_by_username_or_email(params[:login]) user = User.find_by_username_or_email(params[:login])
if user.present? user_presence = user.present? && user.id != Discourse::SYSTEM_USER_ID
if user_presence
email_token = user.email_tokens.create(email: user.email) email_token = user.email_tokens.create(email: user.email)
Jobs.enqueue(:user_email, type: :forgot_password, user_id: user.id, email_token: email_token.token) Jobs.enqueue(:user_email, type: :forgot_password, user_id: user.id, email_token: email_token.token)
end end
json = { result: "ok" } json = { result: "ok" }
unless SiteSetting.forgot_password_strict unless SiteSetting.forgot_password_strict
json[:user_found] = user.present? json[:user_found] = user_presence
end end
render json: json render json: json

View file

@ -189,7 +189,7 @@ describe SessionController do
@sso.name = @reversed_name @sso.name = @reversed_name
@suggested_username = UserNameSuggester.suggest(@sso.username || @sso.name || @sso.email) @suggested_username = UserNameSuggester.suggest(@sso.username || @sso.name || @sso.email)
@suggested_name = User.suggest_name(@sso.name || @sso.username || @sso.email) @suggested_name = User.suggest_name(@sso.name || @sso.username || @sso.email)
@user.create_single_sign_on_record(external_id: '997', last_payload: '') @user.create_single_sign_on_record(external_id: '997', last_payload: '')
end end
@ -486,6 +486,18 @@ describe SessionController do
end end
end end
context 'do nothing to system username' do
let(:user) { Discourse.system_user }
it 'generates no token for system username' do
lambda { xhr :post, :forgot_password, login: user.username}.should_not change(EmailToken, :count)
end
it 'enqueues no email' do
Jobs.expects(:enqueue).never
xhr :post, :forgot_password, login: user.username
end
end
end end
describe '.current' do describe '.current' do