From faeac3c31d51881d19037d7ec591ffc042ffc726 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 11 Apr 2018 17:15:44 +0200 Subject: [PATCH] After activating an admin account, log them into all of their roles --- .../administrateurs/activate_controller.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/administrateurs/activate_controller.rb b/app/controllers/administrateurs/activate_controller.rb index bd1c1b529..5049a67e7 100644 --- a/app/controllers/administrateurs/activate_controller.rb +++ b/app/controllers/administrateurs/activate_controller.rb @@ -11,13 +11,16 @@ class Administrateurs::ActivateController < ApplicationController end def create + password = update_administrateur_params[:password] administrateur = Administrateur.reset_password( update_administrateur_params[:reset_password_token], - update_administrateur_params[:password] + password ) if administrateur && administrateur.errors.empty? sign_in(administrateur, scope: :administrateur) + try_to_authenticate(User, administrateur.email, password) + try_to_authenticate(Gestionnaire, administrateur.email, password) flash.notice = "Mot de passe enregistré" redirect_to admin_procedures_path else @@ -31,4 +34,13 @@ class Administrateurs::ActivateController < ApplicationController def update_administrateur_params params.require(:administrateur).permit(:reset_password_token, :password) end + + def try_to_authenticate(klass, email, password) + resource = klass.find_for_database_authentication(email: email) + + if resource&.valid_password?(password) + sign_in resource + resource.force_sync_credentials + end + end end