From aeaf5075bfc05ca0f33abac368150725692ae46b Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 21 Mar 2017 14:37:21 -0400 Subject: [PATCH] Custom errors for when Email is invalid via SSO --- app/controllers/session_controller.rb | 13 ++++++++++++- app/views/session/sso_login.html.erb | 5 ++++- config/locales/server.en.yml | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/controllers/session_controller.rb b/app/controllers/session_controller.rb index 218c1b718d7..a7dafa586ff 100644 --- a/app/controllers/session_controller.rb +++ b/app/controllers/session_controller.rb @@ -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" diff --git a/app/views/session/sso_login.html.erb b/app/views/session/sso_login.html.erb index ecb1c645b43..9a18faf1a81 100644 --- a/app/views/session/sso_login.html.erb +++ b/app/views/session/sso_login.html.erb @@ -1,2 +1,5 @@ -

<%= @sso_error %>

+

<%=t 'sso.login_error' %>

+
+ +

<%= @sso_error %>

diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index dd8df3b108d..bfbfc86cf91 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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"