2024-04-29 00:17:15 +02:00
# frozen_string_literal: true
2018-01-11 14:18:17 +01:00
class Administrateurs :: ActivateController < ApplicationController
2018-10-30 18:24:29 +01:00
include TrustedDeviceConcern
2018-01-11 14:18:17 +01:00
def new
2019-08-12 13:42:30 +02:00
@token = params [ :token ]
2019-08-09 11:41:36 +02:00
user = User . with_reset_password_token ( @token )
@administrateur = user & . administrateur
2018-01-11 14:18:17 +01:00
2018-10-30 18:24:29 +01:00
if @administrateur
# the administrateur activates its account from an email
2019-02-19 12:40:19 +01:00
trust_device ( Time . zone . now )
2018-10-30 18:24:29 +01:00
else
2021-05-26 15:16:30 +02:00
flash . alert = " Le lien de validation d’ administrateur a expiré, #{ helpers . contact_link ( 'contactez-nous' , tags : 'lien expiré' ) } 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 ]
2019-08-09 11:41:36 +02:00
user = User . reset_password_by_token ( {
password : password ,
password_confirmation : password ,
reset_password_token : update_administrateur_params [ :reset_password_token ]
} )
2023-10-26 17:29:34 +02:00
if user & . errors & . empty?
2024-09-06 13:56:29 +02:00
user . update! ( email_verified_at : Time . zone . now )
2019-08-09 11:41:36 +02:00
sign_in ( user , scope : :user )
2018-01-11 14:18:17 +01:00
flash . notice = " Mot de passe enregistré "
redirect_to admin_procedures_path
else
2023-10-26 17:29:34 +02:00
flash . alert = user . errors . full_messages
2018-01-11 14:18:17 +01:00
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
end
end
2018-01-11 14:18:17 +01:00
end