After activating an admin account, log them into all of their roles

This commit is contained in:
Frederic Merizen 2018-04-11 17:15:44 +02:00
parent ee67e7b154
commit faeac3c31d

View file

@ -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