Custom errors for when Email is invalid via SSO

This commit is contained in:
Robin Ward 2017-03-21 14:37:21 -04:00
parent 52d78294cc
commit aeaf5075bf
3 changed files with 19 additions and 2 deletions

View File

@ -129,6 +129,7 @@ class SessionController < ApplicationController
render_sso_error(text: I18n.t("sso.not_found"), status: 500)
end
rescue ActiveRecord::RecordInvalid => e
if SiteSetting.verbose_sso_logging
Rails.logger.warn(<<-EOF)
Verbose SSO log: Record was invalid: #{e.record.class.name} #{e.record.id}\n
@ -137,7 +138,17 @@ class SessionController < ApplicationController
#{sso.diagnostics}
EOF
end
render_sso_error(text: I18n.t("sso.unknown_error"), status: 500)
text = nil
# If there's a problem with the email we can explain that
if (e.record.is_a?(User) && e.record.errors[:email].present?)
text = e.record.email.blank? ? I18n.t("sso.no_email") : I18n.t("sso.email_error")
end
render_sso_error(text: text || I18n.t("sso.unknown_error"), status: 500)
rescue => e
message = "Failed to create or lookup user: #{e}."
message << "\n\n" << "-" * 100 << "\n\n"

View File

@ -1,2 +1,5 @@
<h1><%= @sso_error %></h1>
<h1><%=t 'sso.login_error' %></h1>
<br/>
<p><%= @sso_error %></p>

View File

@ -1544,10 +1544,13 @@ en:
user: 'Users'
sso:
login_error: "Login Error"
not_found: "Your account couldn't be found. Please contact the site's administrator."
account_not_approved: "Your account is pending approval. You will receive an email notification when you are approved."
unknown_error: "There is a problem with your account. Please contact the site's administrator."
timeout_expired: "Account login timed out, please try logging in again."
no_email: "No email address was provided. Please contact the site's administrator."
email_error: "An account could not be registered with that email address. Please contact the site's administrator."
original_poster: "Original Poster"
most_posts: "Most Posts"