diff --git a/app/assets/javascripts/controllers/profile.coffee b/app/assets/javascripts/controllers/profile.coffee.erb
similarity index 86%
rename from app/assets/javascripts/controllers/profile.coffee
rename to app/assets/javascripts/controllers/profile.coffee.erb
index f2f542b31..781f12995 100644
--- a/app/assets/javascripts/controllers/profile.coffee
+++ b/app/assets/javascripts/controllers/profile.coffee.erb
@@ -1,8 +1,8 @@
'use strict'
-Application.Controllers.controller "CompleteProfileController", ["$scope", "$rootScope", "$state", "$window", "_t", "growl", "CSRF", "Auth", "Member", "settingsPromise", "activeProviderPromise", "groupsPromise", "cguFile", "memberPromise", "Session"
-, ($scope, $rootScope, $state, $window, _t, growl, CSRF, Auth, Member, settingsPromise, activeProviderPromise, groupsPromise, cguFile, memberPromise, Session) ->
+Application.Controllers.controller "CompleteProfileController", ["$scope", "$rootScope", "$state", "$window", "_t", "growl", "CSRF", "Auth", "Member", "settingsPromise", "activeProviderPromise", "groupsPromise", "cguFile", "memberPromise", "Session", "dialogs", "AuthProvider"
+, ($scope, $rootScope, $state, $window, _t, growl, CSRF, Auth, Member, settingsPromise, activeProviderPromise, groupsPromise, cguFile, memberPromise, Session, dialogs, AuthProvider) ->
@@ -141,6 +141,27 @@ Application.Controllers.controller "CompleteProfileController", ["$scope", "$roo
+ ##
+ # Ask for email confirmation and send the SSO merging token again
+ # @param $event {Object} jQuery event object
+ ##
+ $scope.resendCode = (event) ->
+ event.preventDefault()
+ event.stopPropagation()
+ dialogs.confirm
+ templateUrl: '<%= asset_path "profile/resend_code_modal.html" %>'
+ resolve:
+ object: ->
+ email: memberPromise.email
+ , (email) ->
+ # Request the server to send an auth-migration email to the current user
+ AuthProvider.send_code {email: email}, (res) ->
+ growl.info(_t('code_successfully_sent_again'))
+ , (err) ->
+ growl.error(err.data.error)
+
+
+
##
# Disconnect and re-connect the user to the SSO to force the synchronisation of the profile's data
##
diff --git a/app/assets/javascripts/services/authProvider.coffee b/app/assets/javascripts/services/authProvider.coffee
index 4acb0b731..e9928ba8f 100644
--- a/app/assets/javascripts/services/authProvider.coffee
+++ b/app/assets/javascripts/services/authProvider.coffee
@@ -11,4 +11,7 @@ Application.Services.factory 'AuthProvider', ["$resource", ($resource)->
active:
method: 'GET'
url: '/api/auth_providers/active'
+ send_code:
+ method: 'POST'
+ url: '/api/auth_providers/send_code'
]
diff --git a/app/assets/templates/profile/_token.html.erb b/app/assets/templates/profile/_token.html.erb
index f4a8b0404..3017b18ed 100644
--- a/app/assets/templates/profile/_token.html.erb
+++ b/app/assets/templates/profile/_token.html.erb
@@ -3,6 +3,7 @@
{{ 'do_you_already_have_an_account' }}
{{ 'do_not_fill_the_form_beside_but_specify_here_the_code_you_ve_received_by_email_to_recover_your_access' }}
{{ 'just_specify_code_here_to_recover_access' }}
+ {{ 'i_did_not_receive_the_code' }}
diff --git a/app/assets/templates/profile/resend_code_modal.html b/app/assets/templates/profile/resend_code_modal.html
new file mode 100644
index 000000000..b3e04dd02
--- /dev/null
+++ b/app/assets/templates/profile/resend_code_modal.html
@@ -0,0 +1,26 @@
+
+
+
diff --git a/app/controllers/api/auth_providers_controller.rb b/app/controllers/api/auth_providers_controller.rb
index 3797dc743..173e401a7 100644
--- a/app/controllers/api/auth_providers_controller.rb
+++ b/app/controllers/api/auth_providers_controller.rb
@@ -1,7 +1,6 @@
class API::AuthProvidersController < API::ApiController
before_action :set_provider, only: [:show, :update, :destroy]
-
def index
@providers = policy_scope(AuthProvider)
end
@@ -48,6 +47,25 @@ class API::AuthProvidersController < API::ApiController
@provider = AuthProvider.active
end
+
+ def send_code
+ authorize AuthProvider
+ user = User.find_by(email: params[:email])
+
+ if user&.auth_token
+ if AuthProvider.active.providable_type != DatabaseProvider.name
+ NotificationCenter.call type: 'notify_user_auth_migration',
+ receiver: user,
+ attached_object: user
+ render json: {status: 'processing'}, status: :ok
+ else
+ render json: {status: 'error', error: I18n.t('members.current_authentication_method_no_code')}, status: :bad_request
+ end
+ else
+ render json: {status: 'error', error: I18n.t('members.requested_account_does_not_exists')}, status: :bad_request
+ end
+ end
+
private
def set_provider
diff --git a/app/policies/auth_provider_policy.rb b/app/policies/auth_provider_policy.rb
index a12119570..96c73884a 100644
--- a/app/policies/auth_provider_policy.rb
+++ b/app/policies/auth_provider_policy.rb
@@ -16,4 +16,7 @@ class AuthProviderPolicy < ApplicationPolicy
user
end
+ def send_code?
+ user
+ end
end
diff --git a/config/locales/app.logged.en.yml b/config/locales/app.logged.en.yml
index 533e1bbe7..c2d4ed3b0 100644
--- a/config/locales/app.logged.en.yml
+++ b/config/locales/app.logged.en.yml
@@ -18,9 +18,14 @@ en:
do_you_already_have_an_account: "Do you already have an account?"
do_not_fill_the_form_beside_but_specify_here_the_code_you_ve_received_by_email_to_recover_your_access: "Do not fill the form beside but specify here the code you've received by email, to recover your access."
just_specify_code_here_to_recover_access: "Just specify here the code you've received by email to recover your access."
+ i_did_not_receive_the_code: "I didn't receive the code"
authentification_code: "Authentification code"
confirm_my_code: "Confirm my code"
an_unexpected_error_occurred_check_your_authentication_code: "An unexpected error occurred, please check your authentication code."
+ send_code_again: "Send the code again"
+ email_address_associated_with_your_account: "Email address associated with your account"
+ email_format_is_incorrect: "Email format is incorrect"
+ code_successfully_sent_again: "Code successfully sent again"
dashboard:
# dashboard: public profile
diff --git a/config/locales/app.logged.fr.yml b/config/locales/app.logged.fr.yml
index ea0e901dc..26373a2cc 100644
--- a/config/locales/app.logged.fr.yml
+++ b/config/locales/app.logged.fr.yml
@@ -18,9 +18,14 @@ fr:
do_you_already_have_an_account: "Vous possédez déjà un compte ?"
do_not_fill_the_form_beside_but_specify_here_the_code_you_ve_received_by_email_to_recover_your_access: "Ne remplissez pas le formulaire à gauche mais indiquez ici le code qui vous a été fourni par e-mail, cela vous permettra de récupérer l'accès à votre compte."
just_specify_code_here_to_recover_access: "Indiquez simplement ici le code que vous avez reçu par e-mail, cela vous permettra de récupérer l'accès à votre compte."
+ i_did_not_receive_the_code: "Je n'ai pas reçu le code"
authentification_code: "Code d'authentification"
confirm_my_code: "Valider mon code"
an_unexpected_error_occurred_check_your_authentication_code: "Une erreur inattendue est survenue, vérifiez votre code d'authentification."
+ send_code_again: "Renvoyer le code"
+ email_address_associated_with_your_account: "Adresse électronique associée à votre compte"
+ email_format_is_incorrect: "Le format de l'adresse email est incorrect"
+ code_successfully_sent_again: "Le code a bien été renvoyé"
dashboard:
# tableau de bord: profile publique
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 56ff141a4..4694aea87 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -63,6 +63,8 @@ en:
unable_to_change_the_group_while_a_subscription_is_running: "Unable to change the group while a subscription is running"
please_input_the_authentication_code_sent_to_the_address: "Please input the authentication code sent to the e-mail address %{EMAIL}"
your_authentication_code_is_not_valid: "Your authentication code is not valid."
+ current_authentication_method_no_code: "The current authentication method does not require any migration code"
+ requested_account_does_not_exists: "The requested account does not exist"
invoices:
# PDF invoices generation
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index 5a17e3fa4..26b8f7d83 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -63,6 +63,8 @@ fr:
unable_to_change_the_group_while_a_subscription_is_running: "Impossible de changer le groupe tant qu'un abonnement est en cours"
please_input_the_authentication_code_sent_to_the_address: "Merci d'enter le code d'authentification qui a été envoyé à l'adresse de courriel %{EMAIL}"
your_authentication_code_is_not_valid: "Votre code d'authentification n'est pas valide."
+ current_authentication_method_no_code: "La méthode d'authentification actuelle ne requiert pas de code de migration"
+ requested_account_does_not_exists: "Le compte utilisateur demandé n'existe pas"
invoices:
# génération des factures en PDF
diff --git a/config/routes.rb b/config/routes.rb
index b6afce9ff..496ba1594 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -114,6 +114,7 @@ Rails.application.routes.draw do
resources :auth_providers do
get 'mapping_fields', on: :collection
get 'active', action: 'active', on: :collection
+ post 'send_code', action: 'send_code', on: :collection
end
resources :abuses, only: [:create]
resources :open_api_clients, only: [:index, :create, :update, :destroy] do