From 277c1a17c62bcad8c78d505f6832a2cc3efd2a06 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Fri, 6 Sep 2024 13:56:29 +0200 Subject: [PATCH] set verified_email when admin set its password from email link --- app/controllers/administrateurs/activate_controller.rb | 2 ++ .../administrateurs/activate_controller_spec.rb | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/administrateurs/activate_controller.rb b/app/controllers/administrateurs/activate_controller.rb index 56805d090..9747a9c9c 100644 --- a/app/controllers/administrateurs/activate_controller.rb +++ b/app/controllers/administrateurs/activate_controller.rb @@ -28,6 +28,8 @@ class Administrateurs::ActivateController < ApplicationController }) if user&.errors&.empty? + user.update!(email_verified_at: Time.zone.now) + sign_in(user, scope: :user) flash.notice = "Mot de passe enregistré" diff --git a/spec/controllers/administrateurs/activate_controller_spec.rb b/spec/controllers/administrateurs/activate_controller_spec.rb index 59c7b39c7..9de80460c 100644 --- a/spec/controllers/administrateurs/activate_controller_spec.rb +++ b/spec/controllers/administrateurs/activate_controller_spec.rb @@ -28,8 +28,12 @@ describe Administrateurs::ActivateController, type: :controller do before { post :create, params: { administrateur: { reset_password_token: token, password: password } } } context 'when the token is ok' do - it { expect(administrateur.user.reload.valid_password?(password)).to be true } - it { expect(response).to redirect_to(admin_procedures_path) } + it do + admin_user = administrateur.user.reload + expect(admin_user.valid_password?(password)).to be true + expect(admin_user.email_verified_at).to be_present + expect(response).to redirect_to(admin_procedures_path) + end end context 'when the password is not strong' do