Skip to content

Commit

Permalink
never require manual intervention
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Sep 11, 2024
1 parent 5e17980 commit 034541c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
19 changes: 4 additions & 15 deletions app/controllers/auth/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,10 @@ def try_login!
# If no identity exist, we want to check if it is a new user or an existing user using a new provider
# Try to find an existing user
user = find_user_in_institution
# If we found an existing user, which already has an identity for this provider
# This will require a manual intervention by the development team, notify the user and the team
return redirect_duplicate_email_for_provider! if user&.providers&.exists?(id: provider.id)
# If we found an existing user with the same username or email within the same institution
# We will ask the user to verify if this was the user they wanted to sign in to
# if yes => redirect to a previously used provider for this user
# if no => contact dodona for a manual intervention
# if no => create a new user or contact support
return redirect_to_known_provider!(user) if user.present?

# Try to find if the email address is already in use in an other institution
Expand Down Expand Up @@ -373,6 +370,9 @@ def redirect_with_flash!(message)
end

def redirect_to_known_provider!(user)
# information required if the user wants to create a new account
store_hash_in_session!
# information required if the user wants to link the new sign in method to an existing account
store_identity_in_session!
session[:auth_original_user_id] = user.id
@provider = provider
Expand All @@ -386,17 +386,6 @@ def redirect_to_confirm_new_user!
redirect_to confirm_new_user_path
end

def redirect_duplicate_email_for_provider!
ApplicationMailer.with(
authinfo: auth_hash,
errors: I18n.t('devise.omniauth_callbacks.duplicate_email_for_provider', email_address: auth_email, provider: provider.class.sym.to_s)
).user_unable_to_log_in.deliver_later

set_flash_message :alert, :duplicate_email_for_provider, email_address: auth_email, provider: provider.class.sym.to_s
flash[:options] = [{ url: contact_path, message: I18n.t('pages.contact.prompt') }]
redirect_to root_path
end

def flash_wrong_provider(tried_provider, user_provider)
set_flash_message :alert, :wrong_provider,
tried_email_address: auth_email,
Expand Down
7 changes: 7 additions & 0 deletions app/views/auth/redirect_to_known_provider.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
<%= render partial: 'auth/provider_button', locals: { provider: provider } %>
<% end %>
</div>
<div class="row">
<h2><%= t ".new_account" %></h2>
<p><%= t ".new_account_help"%></p>
<div>
<%= link_to t(".create_new_account"), confirm_new_user_path, method: :post, class: "btn btn-filled" %>
</div>
</div>
<div class="row">
<p><%= t ".contact_support_html", form: link_to(t(".contact_form"), contact_path)%></p>
</div>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/views/auth/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ en:
message_p1_personal: "A user with the same username (**%{username}**) or email address (**%{email}**) already exists on Dodona. This is probably you, but you have used a different sign in method on previous occasions."
message_p2: "Before you can access your data using **%{provider}**, we have to link your existing account. To proceed, click on one of the sign in methods below and sign in again."
providers_title: "Link accounts"
new_account: "Create new account"
new_account_help: "If the existing account is not yours, or if you want to create a new account, click on the button below."
create_new_account: "Create new account"
"contact_support_html": "If this isn't you or you keep having issues? Fill in the %{form} and we will assist you as soon as possible."
contact_form: "contact form"
privacy_prompt:
Expand Down
3 changes: 3 additions & 0 deletions config/locales/views/auth/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ nl:
message_p1_personal: "Er bestaat al een gebruiker met dezelfde gebruikersnaam (**%{username}**) of hetzelfde e-mailadres (**%{email}**) op Dodona. Waarschijnlijk ben jij dit, maar gebruikte je vorige keer een andere loginmethode."
message_p2: "Om ook via **%{provider}** aan je gegevens te kunnen, moeten we even je bestaande account koppelen. Klik daarvoor op de aanmeldknop hieronder en log nogmaals in."
providers_title: "Accounts koppelen"
new_account: "Nieuwe account aanmaken"
new_account_help: "Als het bestaande account niet van jou is, of als je een nieuwe account wilt aanmaken, klik dan op de knop hieronder."
create_new_account: "Maak een nieuwe account"
"contact_support_html": "Ben jij dit niet of blijf je problemen hebben? Vul het %{form} in en we helpen je zo snel mogelijk verder."
contact_form: "contactformulier"
privacy_prompt:
Expand Down

0 comments on commit 034541c

Please sign in to comment.