2018-01-11 14:18:17 +01:00
|
|
|
class Administrateurs::ActivateController < ApplicationController
|
|
|
|
layout "new_application"
|
|
|
|
|
|
|
|
def new
|
|
|
|
@administrateur = Administrateur.find_inactive_by_token(params[:token])
|
|
|
|
|
|
|
|
if !@administrateur
|
2018-02-28 17:37:44 +01:00
|
|
|
flash.alert = "Le lien de validation d'administrateur a expiré, contactez-nous à contact@demarches-simplifiees.fr pour obtenir un nouveau lien."
|
2018-01-11 14:18:17 +01:00
|
|
|
redirect_to root_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2018-04-11 17:15:44 +02:00
|
|
|
password = update_administrateur_params[:password]
|
2018-01-11 14:18:17 +01:00
|
|
|
administrateur = Administrateur.reset_password(
|
|
|
|
update_administrateur_params[:reset_password_token],
|
2018-04-11 17:15:44 +02:00
|
|
|
password
|
2018-01-11 14:18:17 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
if administrateur && administrateur.errors.empty?
|
|
|
|
sign_in(administrateur, scope: :administrateur)
|
2018-04-11 17:15:44 +02:00
|
|
|
try_to_authenticate(User, administrateur.email, password)
|
|
|
|
try_to_authenticate(Gestionnaire, administrateur.email, password)
|
2018-01-11 14:18:17 +01:00
|
|
|
flash.notice = "Mot de passe enregistré"
|
|
|
|
redirect_to admin_procedures_path
|
|
|
|
else
|
|
|
|
flash.alert = administrateur.errors.full_messages
|
|
|
|
redirect_to admin_activate_path(token: update_administrateur_params[:reset_password_token])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def update_administrateur_params
|
|
|
|
params.require(:administrateur).permit(:reset_password_token, :password)
|
|
|
|
end
|
2018-04-11 17:15:44 +02:00
|
|
|
|
|
|
|
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
|
2018-01-11 14:18:17 +01:00
|
|
|
end
|