layouts: migrate sign_in to the shared layout
This commit is contained in:
parent
13f1d4c7d9
commit
d36696442b
9 changed files with 140 additions and 97 deletions
|
@ -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
|
||||
|
|
|
@ -2,6 +2,8 @@ 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 ?
|
||||
|
|
8
app/views/layouts/commencer/_no_procedure.html.haml
Normal file
8
app/views/layouts/commencer/_no_procedure.html.haml
Normal file
|
@ -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.
|
|
@ -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)
|
|
@ -3,20 +3,17 @@
|
|||
.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 @dossier
|
||||
= render partial: 'layouts/commencer/procedure_description', locals: { procedure: @dossier.procedure }
|
||||
- else
|
||||
= render partial: 'layouts/commencer/no_procedure'
|
||||
|
||||
.column.procedure-context-content
|
||||
= yield
|
||||
|
||||
- content_for :footer do
|
||||
= render partial: 'new_user/procedure_footer', locals: { dossier: @dossier }
|
||||
/ TODO: display the procedure footer even if there is no dossier yet
|
||||
- if @dossier
|
||||
= render partial: 'new_user/procedure_footer', locals: { dossier: @dossier }
|
||||
|
||||
= render template: 'layouts/application'
|
||||
|
|
|
@ -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"
|
||||
|
|
56
spec/features/sessions/sign_in_spec.rb
Normal file
56
spec/features/sessions/sign_in_spec.rb
Normal file
|
@ -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
|
|
@ -4,25 +4,31 @@ 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)
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue