fix: fix activate gestionnaire and activate administrateur
This commit is contained in:
parent
6203b1fd05
commit
a5d95b2d9d
9 changed files with 163 additions and 3 deletions
|
@ -25,13 +25,13 @@ class Administrateurs::ActivateController < ApplicationController
|
|||
reset_password_token: update_administrateur_params[:reset_password_token]
|
||||
})
|
||||
|
||||
if user&.administrateur&.errors&.empty?
|
||||
if user&.errors&.empty?
|
||||
sign_in(user, scope: :user)
|
||||
|
||||
flash.notice = "Mot de passe enregistré"
|
||||
redirect_to admin_procedures_path
|
||||
else
|
||||
flash.alert = user.administrateur.errors.full_messages
|
||||
flash.alert = user.errors.full_messages
|
||||
redirect_to admin_activate_path(token: update_administrateur_params[:reset_password_token])
|
||||
end
|
||||
end
|
||||
|
|
52
app/controllers/gestionnaires/activate_controller.rb
Normal file
52
app/controllers/gestionnaires/activate_controller.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
class Gestionnaires::ActivateController < ApplicationController
|
||||
include TrustedDeviceConcern
|
||||
|
||||
def new
|
||||
@token = params[:token]
|
||||
|
||||
user = User.with_reset_password_token(@token)
|
||||
@gestionnaire = user&.gestionnaire
|
||||
|
||||
if @gestionnaire
|
||||
# the gestionnaire activates its account from an email
|
||||
trust_device(Time.zone.now)
|
||||
else
|
||||
flash.alert = "Le lien de validation de gestionnaire a expiré, #{helpers.contact_link('contactez-nous', tags: 'lien expiré')} pour obtenir un nouveau lien."
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
password = update_gestionnaire_params[:password]
|
||||
|
||||
user = User.reset_password_by_token({
|
||||
password: password,
|
||||
password_confirmation: password,
|
||||
reset_password_token: update_gestionnaire_params[:reset_password_token]
|
||||
})
|
||||
|
||||
if user&.errors&.empty?
|
||||
sign_in(user, scope: :user)
|
||||
|
||||
flash.notice = "Mot de passe enregistré"
|
||||
redirect_to gestionnaire_groupe_gestionnaires_path
|
||||
else
|
||||
flash.alert = user.errors.full_messages
|
||||
redirect_to gestionnaires_activate_path(token: update_gestionnaire_params[:reset_password_token])
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_gestionnaire_params
|
||||
params.require(:gestionnaire).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
|
||||
end
|
||||
end
|
||||
end
|
26
app/views/gestionnaires/activate/new.html.haml
Normal file
26
app/views/gestionnaires/activate/new.html.haml
Normal file
|
@ -0,0 +1,26 @@
|
|||
- content_for(:title, t('.title'))
|
||||
|
||||
- content_for :footer do
|
||||
= render partial: "root/footer"
|
||||
|
||||
.fr-container.fr-my-5w
|
||||
.fr-grid-row.fr-grid-row--center
|
||||
.fr-col-lg-6
|
||||
= form_for @gestionnaire, url: { controller: 'gestionnaires/activate', action: :create } do |f|
|
||||
= f.hidden_field :reset_password_token, value: @token
|
||||
|
||||
%fieldset.fr-mb-0.fr-fieldset{ aria: { labelledby: 'edit-password-legend' } }
|
||||
%legend.fr-fieldset__legend#edit-password-legend
|
||||
%h1.fr-h2= t('.title')
|
||||
|
||||
.fr-fieldset__element
|
||||
= render Dsfr::InputComponent.new(form: f, attribute: :email, opts: { disabled: true })
|
||||
|
||||
.fr-fieldset__element
|
||||
= render Dsfr::InputComponent.new(form: f, attribute: :password, input_type: :password_field,
|
||||
opts: { autofocus: 'true', autocomplete: 'new-password', data: { controller: 'turbo-input', turbo_input_url_value: show_password_complexity_path }})
|
||||
|
||||
#password_complexity
|
||||
= render PasswordComplexityComponent.new
|
||||
|
||||
= f.submit t('.continue'), id: 'submit-password', class: "fr-btn fr-btn--lg fr-mt-2w", data: { disable_with: t('views.users.passwords.edit.submit_loading') }
|
|
@ -8,6 +8,6 @@
|
|||
|
||||
%p
|
||||
Votre compte a été créé pour l'adresse email #{@user.email}. Pour l’activer, nous vous invitons à cliquer sur le lien suivant :
|
||||
= link_to(users_activate_url(token: @reset_password_token), users_activate_url(token: @reset_password_token))
|
||||
= link_to(gestionnaires_activate_url(token: @reset_password_token), gestionnaires_activate_url(token: @reset_password_token))
|
||||
|
||||
= render partial: "layouts/mailers/signature"
|
||||
|
|
|
@ -797,6 +797,11 @@ en:
|
|||
updated_at: updated at
|
||||
closed_at: closed at
|
||||
auto_archive_on: will close at
|
||||
gestionnaires:
|
||||
activate:
|
||||
new:
|
||||
title: Pick a password
|
||||
continue: Continue
|
||||
users:
|
||||
dossiers:
|
||||
test_procedure: "This file is submitted on a test procedure. Any modification of the procedure by the administrator (addition of a field, publication of the procedure, etc.) will result in the removal of the file."
|
||||
|
|
|
@ -895,6 +895,11 @@ fr:
|
|||
explication_html: "<p>API Particulier facilite l’accès des administrations aux données familiales (CAF), aux données fiscales (DGFiP), au statut pôle-emploi et au statut étudiant d’un citoyen pour simplifier les démarches administratives mises en œuvre par les collectivités et les administrations.<br> Cela permet aux administrations d’accéder à des informations certifiées à la source et ainsi : </p> <ul> <li>de s’affranchir des pièces justificatives lors des démarches en ligne,</li> <li>de réduire le nombre d’erreurs de saisie,</li> <li>d’écarter le risque de fraude documentaire.</li> </ul> <p> <strong>Important :</strong> les disposition de l’article <a href='https://www.legifrance.gouv.fr/affichCodeArticle.do?cidTexte=LEGITEXT000031366350&idArticle=LEGIARTI000031367412&dateTexte=&categorieLien=cid'>L144-8</a> n’autorisent que l’échange des informations strictement nécessaires pour traiter une démarche.<br /><br />En conséquence, ne sélectionnez ici que les données auxquelles vous aurez accès d’un point de vue légal.</p>"
|
||||
update:
|
||||
sources_ok: 'Mise à jour effectuée'
|
||||
gestionnaires:
|
||||
activate:
|
||||
new:
|
||||
title: Choix du mot de passe
|
||||
continue: Continuer
|
||||
zones:
|
||||
ministeres: Ministères
|
||||
france_connect:
|
||||
|
|
|
@ -517,6 +517,11 @@ Rails.application.routes.draw do
|
|||
resources :commentaires, controller: 'groupe_gestionnaire_commentaires', only: [:index, :show, :create, :destroy]
|
||||
end
|
||||
end
|
||||
|
||||
namespace :gestionnaires do
|
||||
get 'activate' => '/gestionnaires/activate#new'
|
||||
patch 'activate' => '/gestionnaires/activate#create'
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
|
|
|
@ -17,4 +17,31 @@ describe Administrateurs::ActivateController, type: :controller do
|
|||
it { expect(controller).not_to have_received(:trust_device) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
let!(:administrateur) { create(:administrateur) }
|
||||
let(:token) { administrateur.user.send(:set_reset_password_token) }
|
||||
let(:password) { 'Another-password-ok!@#123?' }
|
||||
|
||||
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) }
|
||||
end
|
||||
|
||||
context 'when the password is not strong' do
|
||||
let(:password) { 'another-password-ok?' }
|
||||
|
||||
it { expect(administrateur.user.reload.valid_password?(password)).to be false }
|
||||
it { expect(response).to redirect_to(admin_activate_path(token: token)) }
|
||||
end
|
||||
|
||||
context 'when the token is bad' do
|
||||
let(:token) { 'bad' }
|
||||
|
||||
it { expect(administrateur.user.reload.valid_password?(password)).to be false }
|
||||
it { expect(response).to redirect_to(admin_activate_path(token: token)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
40
spec/controllers/gestionnaires/activate_controller_spec.rb
Normal file
40
spec/controllers/gestionnaires/activate_controller_spec.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
describe Gestionnaires::ActivateController, type: :controller do
|
||||
describe '#new' do
|
||||
let(:gestionnaire) { create(:gestionnaire) }
|
||||
let(:token) { gestionnaire.user.send(:set_reset_password_token) }
|
||||
|
||||
before { allow(controller).to receive(:trust_device) }
|
||||
|
||||
context 'when the token is ok' do
|
||||
before { get :new, params: { token: token } }
|
||||
|
||||
it { expect(controller).to have_received(:trust_device) }
|
||||
end
|
||||
|
||||
context 'when the token is bad' do
|
||||
before { get :new, params: { token: 'bad' } }
|
||||
|
||||
it { expect(controller).not_to have_received(:trust_device) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
let!(:gestionnaire) { create(:gestionnaire) }
|
||||
let(:token) { gestionnaire.user.send(:set_reset_password_token) }
|
||||
let(:password) { 'another-password-ok?' }
|
||||
|
||||
before { post :create, params: { gestionnaire: { reset_password_token: token, password: password } } }
|
||||
|
||||
context 'when the token is ok' do
|
||||
it { expect(gestionnaire.user.reload.valid_password?(password)).to be true }
|
||||
it { expect(response).to redirect_to(gestionnaire_groupe_gestionnaires_path) }
|
||||
end
|
||||
|
||||
context 'when the token is bad' do
|
||||
let(:token) { 'bad' }
|
||||
|
||||
it { expect(gestionnaire.user.reload.valid_password?(password)).to be false }
|
||||
it { expect(response).to redirect_to(gestionnaires_activate_path(token: token)) }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue