diff --git a/app/assets/stylesheets/new_design/new_footer.scss b/app/assets/stylesheets/new_design/new_footer.scss index 75e6df47d..a879bd4b4 100644 --- a/app/assets/stylesheets/new_design/new_footer.scss +++ b/app/assets/stylesheets/new_design/new_footer.scss @@ -14,7 +14,7 @@ footer { @include vertical-padding(72px); } -.dossier-footer { +.procedure-footer { @include vertical-padding(30px); line-height: 24px; } diff --git a/app/controllers/sessions/sessions_controller.rb b/app/controllers/sessions/sessions_controller.rb index ed30ce252..f555f49fc 100644 --- a/app/controllers/sessions/sessions_controller.rb +++ b/app/controllers/sessions/sessions_controller.rb @@ -1,6 +1,8 @@ class Sessions::SessionsController < Devise::SessionsController before_action :before_sign_in, only: [:create] + layout 'new_application' + def before_sign_in if user_signed_in? sign_out :user diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 06a7714d8..d63881c96 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -2,10 +2,12 @@ class Users::SessionsController < Sessions::SessionsController include TrustedDeviceConcern include ActionView::Helpers::DateHelper + layout 'procedure_context', only: [:new, :create] + # GET /resource/sign_in def new - if user_return_to_procedure_id.present? # WTF ? - @dossier = Dossier.new(procedure: Procedure.active(user_return_to_procedure_id)) + if user_return_to_procedure_id.present? + @procedure = Procedure.active(user_return_to_procedure_id) end @user = User.new diff --git a/app/views/layouts/commencer/_no_procedure.html.haml b/app/views/layouts/commencer/_no_procedure.html.haml new file mode 100644 index 000000000..34c054883 --- /dev/null +++ b/app/views/layouts/commencer/_no_procedure.html.haml @@ -0,0 +1,8 @@ +.no-procedure + = image_tag "landing/hero/dematerialiser.svg", class: "paperless-logo" + .baseline.center + %h3 Un outil simple + %p + pour gérer les formulaires + %br + administratifs dématérialisés. diff --git a/app/views/layouts/commencer/_procedure_description.html.haml b/app/views/layouts/commencer/_procedure_description.html.haml new file mode 100644 index 000000000..5df533231 --- /dev/null +++ b/app/views/layouts/commencer/_procedure_description.html.haml @@ -0,0 +1,8 @@ +.procedure-logos + = image_tag logo_img(procedure) + - if procedure.euro_flag + = image_tag "flag_of_europe.svg" +%h2.procedure-title + = procedure.libelle +.procedure-description + = h string_to_html(procedure.description) diff --git a/app/views/layouts/procedure_context.html.haml b/app/views/layouts/procedure_context.html.haml index 223bff4c2..2199d581b 100644 --- a/app/views/layouts/procedure_context.html.haml +++ b/app/views/layouts/procedure_context.html.haml @@ -1,22 +1,22 @@ +- procedure = @procedure || @dossier&.procedure || nil + - content_for :content do .two-columns.procedure-context .columns-container .column.procedure-preview - - procedure = @dossier.procedure - .procedure-logos - = image_tag logo_img(procedure) - - if procedure.euro_flag - = image_tag "flag_of_europe.svg" - %h2.procedure-title - = procedure.libelle - .procedure-description - = h string_to_html(procedure.description) + - if procedure + = render partial: 'layouts/commencer/procedure_description', locals: { procedure: procedure } + - else + = render partial: 'layouts/commencer/no_procedure' .column.procedure-context-content = yield - content_for :footer do - = render partial: "new_user/dossiers/dossier_footer", locals: { dossier: @dossier } + - if procedure + = render partial: 'new_user/procedure_footer', locals: { procedure: procedure, dossier: @dossier } + - else + = render partial: 'new_user/dossiers/index_footer' = render template: 'layouts/application' diff --git a/app/views/new_user/dossiers/_general_footer_row.html.haml b/app/views/new_user/_general_footer_row.html.haml similarity index 100% rename from app/views/new_user/dossiers/_general_footer_row.html.haml rename to app/views/new_user/_general_footer_row.html.haml diff --git a/app/views/new_user/dossiers/_dossier_footer.html.haml b/app/views/new_user/_procedure_footer.html.haml similarity index 79% rename from app/views/new_user/dossiers/_dossier_footer.html.haml rename to app/views/new_user/_procedure_footer.html.haml index 8c6f2d11f..2ac523da8 100644 --- a/app/views/new_user/dossiers/_dossier_footer.html.haml +++ b/app/views/new_user/_procedure_footer.html.haml @@ -1,6 +1,6 @@ -%footer.dossier-footer +%footer.procedure-footer .container - - service = dossier.procedure.service + - service = procedure.service - if service.present? %ul.footer-row.footer-columns %li.footer-column @@ -15,12 +15,12 @@ %li.footer-column %h3.footer-header Poser une question sur votre dossier : %p - - if dossier.brouillon? - Par email : - = link_to service.email, "mailto:#{service.email}" - - else + - if dossier.present? && !dossier.brouillon? Directement = link_to "par la messagerie", messagerie_dossier_path(dossier) + - else + Par email : + = link_to service.email, "mailto:#{service.email}" %p Par téléphone : @@ -29,7 +29,7 @@ %p Horaires : #{ service.horaires.sub(/\S/, &:downcase) } - - politiques = politiques_conservation_de_donnees(dossier.procedure) + - politiques = politiques_conservation_de_donnees(procedure) - if politiques.present? %li.footer-column %h3.footer-header Conservation des données : @@ -37,4 +37,4 @@ %p= politique .footer-row.footer-bottom-line - = render partial: "new_user/dossiers/general_footer_row", locals: { dossier: @dossier } + = render partial: 'new_user/general_footer_row', locals: { dossier: dossier } diff --git a/app/views/new_user/dossiers/_index_footer.html.haml b/app/views/new_user/dossiers/_index_footer.html.haml index 241ba25d7..77dbec78e 100644 --- a/app/views/new_user/dossiers/_index_footer.html.haml +++ b/app/views/new_user/dossiers/_index_footer.html.haml @@ -1,4 +1,4 @@ -%footer.dossier-footer +%footer.procedure-footer .container .footer-row.footer-bottom-line - = render partial: "new_user/dossiers/general_footer_row", locals: { dossier: nil } + = render partial: "new_user/general_footer_row", locals: { dossier: nil } diff --git a/app/views/new_user/dossiers/brouillon.html.haml b/app/views/new_user/dossiers/brouillon.html.haml index 03296a576..c131e8fc7 100644 --- a/app/views/new_user/dossiers/brouillon.html.haml +++ b/app/views/new_user/dossiers/brouillon.html.haml @@ -1,7 +1,7 @@ - content_for(:title, "Modification du brouillon nº #{@dossier.id} (#{@dossier.procedure.libelle})") - content_for :footer do - = render partial: "new_user/dossiers/dossier_footer", locals: { dossier: @dossier } + = render partial: "new_user/procedure_footer", locals: { procedure: @dossier.procedure, dossier: @dossier } .dossier-header.sub-header .container diff --git a/app/views/new_user/dossiers/demande.html.haml b/app/views/new_user/dossiers/demande.html.haml index b29f8db7f..0f46abe02 100644 --- a/app/views/new_user/dossiers/demande.html.haml +++ b/app/views/new_user/dossiers/demande.html.haml @@ -1,7 +1,7 @@ - content_for(:title, "Demande · Dossier nº #{@dossier.id} (#{@dossier.procedure.libelle})") - content_for :footer do - = render partial: "new_user/dossiers/dossier_footer", locals: { dossier: @dossier } + = render partial: "new_user/procedure_footer", locals: { procedure: @dossier.procedure, dossier: @dossier } #dossier-show = render partial: 'new_user/dossiers/show/header', locals: { dossier: @dossier } diff --git a/app/views/new_user/dossiers/etablissement.html.haml b/app/views/new_user/dossiers/etablissement.html.haml index 21bd3755a..60a7f5619 100644 --- a/app/views/new_user/dossiers/etablissement.html.haml +++ b/app/views/new_user/dossiers/etablissement.html.haml @@ -1,7 +1,7 @@ - content_for(:title, "Informations sur l’établissement") - content_for :footer do - = render partial: "new_user/dossiers/dossier_footer", locals: { dossier: @dossier } + = render partial: "new_user/procedure_footer", locals: { procedure: @dossier.procedure, dossier: @dossier } .etablissement .container diff --git a/app/views/new_user/dossiers/merci.html.haml b/app/views/new_user/dossiers/merci.html.haml index 6c14d0122..b148bd365 100644 --- a/app/views/new_user/dossiers/merci.html.haml +++ b/app/views/new_user/dossiers/merci.html.haml @@ -1,7 +1,7 @@ - content_for(:title, "Dossier bien envoyé (#{@dossier.procedure.libelle})") - content_for :footer do - = render partial: "new_user/dossiers/dossier_footer", locals: { dossier: @dossier } + = render partial: "new_user/procedure_footer", locals: { procedure: @dossier.procedure, dossier: @dossier } .merci .container diff --git a/app/views/new_user/dossiers/messagerie.html.haml b/app/views/new_user/dossiers/messagerie.html.haml index 9cac5fe77..93a18f347 100644 --- a/app/views/new_user/dossiers/messagerie.html.haml +++ b/app/views/new_user/dossiers/messagerie.html.haml @@ -1,7 +1,7 @@ - content_for(:title, "Messagerie · Dossier nº #{@dossier.id} (#{@dossier.procedure.libelle})") - content_for :footer do - = render partial: "new_user/dossiers/dossier_footer", locals: { dossier: @dossier } + = render partial: "new_user/procedure_footer", locals: { procedure: @dossier.procedure, dossier: @dossier } #dossier-show = render partial: 'new_user/dossiers/show/header', locals: { dossier: @dossier } diff --git a/app/views/new_user/dossiers/modifier.html.haml b/app/views/new_user/dossiers/modifier.html.haml index 7341db4fd..0c46b66fa 100644 --- a/app/views/new_user/dossiers/modifier.html.haml +++ b/app/views/new_user/dossiers/modifier.html.haml @@ -1,7 +1,7 @@ - content_for(:title, "Modifier · Dossier nº #{@dossier.id} (#{@dossier.procedure.libelle})") - content_for :footer do - = render partial: "new_user/dossiers/dossier_footer", locals: { dossier: @dossier } + = render partial: "new_user/procedure_footer", locals: { procedure: @dossier.procedure, dossier: @dossier } #dossier-show = render partial: 'new_user/dossiers/show/header', locals: { dossier: @dossier } diff --git a/app/views/new_user/dossiers/show.html.haml b/app/views/new_user/dossiers/show.html.haml index 57b944251..40fb9603f 100644 --- a/app/views/new_user/dossiers/show.html.haml +++ b/app/views/new_user/dossiers/show.html.haml @@ -1,7 +1,7 @@ - content_for(:title, "Résumé · Dossier nº #{@dossier.id} (#{@dossier.procedure.libelle})") - content_for :footer do - = render partial: "new_user/dossiers/dossier_footer", locals: { dossier: @dossier } + = render partial: "new_user/procedure_footer", locals: { procedure: @dossier.procedure, dossier: @dossier } #dossier-show = render partial: 'new_user/dossiers/show/header', locals: { dossier: @dossier } diff --git a/app/views/users/sessions/new.html.haml b/app/views/users/sessions/new.html.haml index b3f6bd9bb..721df7b30 100644 --- a/app/views/users/sessions/new.html.haml +++ b/app/views/users/sessions/new.html.haml @@ -1,63 +1,39 @@ -.two-columns.auth - .columns-container - .column.procedure-preview - - if !@dossier - = image_tag "landing/hero/dematerialiser.svg", class: "paperless-logo" - .baseline.center - %h3 Un outil simple - %p - pour gérer les formulaires - %br - administratifs dématérialisés. - - else +.auth-form.sign-in-form + - if resource_name == :user + %p.register + %span + Nouveau sur demarches-simplifiees.fr ? + = link_to "Créer un compte", new_registration_path(resource_name), class: "button primary auth-signup-button" + + %hr + + = form_for @user, url: user_session_path, html: { class: "form" } do |f| + %h1 Connectez-vous + + = f.label :email, "Email" + = f.text_field :email, autofocus: true + + = f.label :password, "Mot de passe" + = f.password_field :password, value: @user.password, placeholder: "8 caractères minimum" + + .auth-options + - if devise_mapping.rememberable? + %div + = f.check_box :remember_me, as: :boolean + = f.label :remember_me, "Se souvenir de moi", class: 'remember-me' + + - if [:user, :gestionnaire].include?(resource_name) .text-right - = link_to "Fermer", users_no_procedure_url, class: "link close-procedure" - .procedure-logos - = image_tag logo_img(@dossier.procedure) - - if @dossier.procedure.euro_flag - = image_tag "flag_of_europe.svg" + = link_to "Mot de passe oublié ?", new_password_path(resource_name), class: "link" - %h2.procedure-title - = @dossier.procedure.libelle - .procedure-description - = h simple_format(@dossier.procedure.description) + = f.submit "Se connecter", class: "button large primary expand" - .column.procedure-context-content.auth-form.sign-in-form - - if resource_name == :user - %p.register - %span - Nouveau sur demarches-simplifiees.fr ? - = link_to "Créer un compte", new_registration_path(resource_name), class: "button primary auth-signup-button" + .separation.center + ou - %hr + .center + = image_tag "login-with-fc-hover.svg", style: "display: none" + = link_to "", france_connect_particulier_path, class: "login-with-fc" - = form_for @user, url: user_session_path, html: { class: "form" } do |f| - %h1 Connectez-vous - - = f.label :email, "Email" - = f.text_field :email, autofocus: true - - = f.label :password, "Mot de passe" - = f.password_field :password, value: @user.password, placeholder: "8 caractères minimum" - - .auth-options - - if devise_mapping.rememberable? - %div - = f.check_box :remember_me, as: :boolean - = f.label :remember_me, "Se souvenir de moi", class: 'remember-me' - - - if [:user, :gestionnaire].include?(resource_name) - .text-right - = link_to "Mot de passe oublié ?", new_password_path(resource_name), class: "link" - - = f.submit "Se connecter", class: "button large primary expand" - - .separation.center - ou - - .center - = image_tag "login-with-fc-hover.svg", style: "display: none" - = link_to "", france_connect_particulier_path, class: "login-with-fc" - - .center - = link_to "Qu’est-ce que FranceConnect ?", "https://franceconnect.gouv.fr/", target: "_blank", class: "link" + .center + = link_to "Qu’est-ce que FranceConnect ?", "https://franceconnect.gouv.fr/", target: "_blank", class: "link" diff --git a/spec/features/sessions/sign_up_spec.rb b/spec/features/new_user/sign_up_spec.rb similarity index 100% rename from spec/features/sessions/sign_up_spec.rb rename to spec/features/new_user/sign_up_spec.rb diff --git a/spec/features/sessions/sign_in_spec.rb b/spec/features/sessions/sign_in_spec.rb new file mode 100644 index 000000000..93aa780ed --- /dev/null +++ b/spec/features/sessions/sign_in_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +feature 'Signin in:' do + let!(:user) { create(:user, password: password) } + let(:password) { 'testpassword' } + + scenario 'an existing user can sign-in' do + visit root_path + click_on 'Connexion' + + sign_in_with user.email, password + + expect(page).to have_current_path dossiers_path + end + + context 'when visiting a procedure' do + let(:procedure) { create :simple_procedure, :with_service } + + before do + visit commencer_path(path: procedure.path) + end + + scenario 'an existing user can sign-in and fill the procedure' do + expect(page).to have_current_path new_user_session_path + expect(page).to have_content procedure.libelle + expect(page).to have_content procedure.description + expect(page).to have_content procedure.service.email + + sign_in_with user.email, password + + expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last) + expect(page).to have_content procedure.libelle + expect(page).to have_content procedure.description + expect(page).to have_content "Données d'identité" + end + end + + context 'when a user is not confirmed yet' do + let!(:user) { create(:user, password: password, confirmed_at: nil) } + + # Ideally, when signing-in with an unconfirmed account, + # the user would be redirected to the "resend email confirmation" page. + # + # However the check for unconfirmed accounts is made by Warden every time a page is loaded – + # and much earlier than SessionsController#create. + # + # For now only test the default behavior (an error message is displayed). + scenario 'they get an error message' do + visit root_path + click_on 'Connexion' + + sign_in_with user.email, password + expect(page).to have_content 'Vous devez confirmer votre adresse email pour continuer' + end + end +end diff --git a/spec/views/layouts/procedure_context.html.haml_spec.rb b/spec/views/layouts/procedure_context.html.haml_spec.rb index 2c9e51856..062a2d39d 100644 --- a/spec/views/layouts/procedure_context.html.haml_spec.rb +++ b/spec/views/layouts/procedure_context.html.haml_spec.rb @@ -4,25 +4,61 @@ describe 'layouts/procedure_context.html.haml', type: :view do let(:procedure) { create(:simple_procedure, :with_service) } let(:dossier) { create(:dossier, procedure: procedure) } - before do - assign(:dossier, dossier) - end - subject do render html: 'Column content', layout: 'layouts/procedure_context.html.haml' end - it 'renders a description of the procedure' do - expect(subject).to have_text(dossier.procedure.libelle) - expect(subject).to have_text(dossier.procedure.description) + context 'when a procedure is assigned' do + before do + assign(:procedure, procedure) + end + + it 'renders a description of the procedure' do + expect(subject).to have_text(procedure.libelle) + expect(subject).to have_text(procedure.description) + end + + it 'renders the inner content' do + expect(subject).to have_text('Column content') + end + + it 'renders the procedure footer' do + expect(subject).to have_text(procedure.service.nom) + expect(subject).to have_text(procedure.service.email) + end end - it 'renders the inner content' do - expect(subject).to have_text('Column content') + context 'when a dossier is assigned' do + before do + assign(:dossier, dossier) + end + + it 'renders a description of the procedure' do + expect(subject).to have_text(dossier.procedure.libelle) + expect(subject).to have_text(dossier.procedure.description) + end + + it 'renders the inner content' do + expect(subject).to have_text('Column content') + end + + it 'renders the procedure footer' do + expect(subject).to have_text(dossier.procedure.service.nom) + expect(subject).to have_text(dossier.procedure.service.email) + end end - it 'renders the dossier footer' do - expect(subject).to have_text(dossier.procedure.service.nom) - expect(subject).to have_text(dossier.procedure.service.email) + context 'when neither procedure or dossier are assigned' do + it 'renders a placeholder for the procedure' do + expect(subject).to have_selector('.no-procedure') + end + + it 'renders the inner content' do + expect(subject).to have_text('Column content') + end + + it 'renders a generic footer' do + expect(subject).to have_text('Mentions légales') + end end end diff --git a/spec/views/new_user/dossiers/_dossier_footer.html.haml_spec.rb b/spec/views/new_user/_procedure_footer.html.haml_spec.rb similarity index 82% rename from spec/views/new_user/dossiers/_dossier_footer.html.haml_spec.rb rename to spec/views/new_user/_procedure_footer.html.haml_spec.rb index 21ef07687..a870abe50 100644 --- a/spec/views/new_user/dossiers/_dossier_footer.html.haml_spec.rb +++ b/spec/views/new_user/_procedure_footer.html.haml_spec.rb @@ -1,4 +1,4 @@ -describe 'new_user/dossiers/_dossier_footer.html.haml', type: :view do +describe 'new_user/procedure_footer.html.haml', type: :view do let(:service) { create(:service) } let(:dossier) { dossier = create(:dossier) @@ -6,7 +6,7 @@ describe 'new_user/dossiers/_dossier_footer.html.haml', type: :view do return dossier } - subject { render 'new_user/dossiers/dossier_footer.html.haml', dossier: dossier } + subject { render 'new_user/procedure_footer.html.haml', procedure: dossier.procedure, dossier: dossier } it "affiche les informations de contact" do expect(subject).to have_text(service.nom) diff --git a/spec/views/users/sessions/new.html.haml_spec.rb b/spec/views/users/sessions/new.html.haml_spec.rb index 714817335..3ffddef9f 100644 --- a/spec/views/users/sessions/new.html.haml_spec.rb +++ b/spec/views/users/sessions/new.html.haml_spec.rb @@ -10,24 +10,12 @@ describe 'users/sessions/new.html.haml', type: :view do before do assign(:user, User.new) + render end - context 'when user_return_to session params contains a procedure_id' do - before do - assign(:dossier, dossier) - render - end - - it { expect(rendered).to have_selector('.procedure-logos') } - it { expect(rendered).to have_content(dossier.procedure.libelle) } - it { expect(rendered).to have_content(dossier.procedure.description) } - end - - context 'when user_return_to session params not contains a procedure_id' do - before do - render - end - - it { expect(rendered).to have_content('Un outil simple') } + it 'renders' do + expect(rendered).to have_field('Email') + expect(rendered).to have_field('Mot de passe') + expect(rendered).to have_button('Se connecter') end end