2019-08-07 15:52:38 +02:00
class Users :: ActivateController < ApplicationController
include TrustedDeviceConcern
def new
@user = User . with_reset_password_token ( params [ :token ] )
if @user
# the user activates its account from an email
trust_device ( Time . zone . now )
else
flash . alert = " Le lien de validation du compte instructeur a expiré, #{ helpers . contact_link ( 'contactez-nous' , tags : 'lien expiré' ) } pour obtenir un nouveau lien. "
redirect_to root_path
end
end
def create
user = User . reset_password_by_token ( {
2019-08-11 19:22:03 +02:00
password : user_params [ :password ] ,
reset_password_token : user_params [ :reset_password_token ]
2019-08-07 15:52:38 +02:00
} )
2019-08-11 19:22:03 +02:00
if user . valid?
2019-08-07 15:52:38 +02:00
sign_in ( user , scope : :user )
2019-08-09 10:38:27 +02:00
2019-08-07 15:52:38 +02:00
flash . notice = " Mot de passe enregistré "
redirect_to instructeur_procedures_path
else
flash . alert = user . errors . full_messages
2019-08-11 19:22:03 +02:00
redirect_to users_activate_path ( token : user_params [ :reset_password_token ] )
2019-08-07 15:52:38 +02:00
end
end
2024-07-10 10:57:26 +02:00
def confirm_email
user = User . find_by ( confirmation_token : params [ :token ] )
if user && user . email_verified_at
flash [ :notice ] = " Votre email est déjà vérifié "
2024-07-11 17:50:02 +02:00
elsif user && 2 . days . ago < user . confirmation_sent_at
2024-07-10 10:57:26 +02:00
user . update! ( email_verified_at : Time . zone . now )
flash [ :notice ] = 'Votre email a bien été vérifié'
else
2024-07-15 11:30:30 +02:00
if user . present?
flash [ :alert ] = " Ce lien n'est plus valable, un nouveau lien a été envoyé à l'adresse #{ user . email } "
User . create_or_promote_to_tiers ( user . email , SecureRandom . hex )
else
flash [ :alert ] = " Un problème est survenu, vous pouvez nous contacter sur #{ Current . contact_email } "
end
2024-07-10 10:57:26 +02:00
end
redirect_to root_path ( user )
end
2019-08-07 15:52:38 +02:00
private
2019-08-11 19:22:03 +02:00
def user_params
2019-08-07 15:52:38 +02:00
params . require ( :user ) . permit ( :reset_password_token , :password )
end
end