diff --git a/app/assets/images/user/confirmation-email.svg b/app/assets/images/user/confirmation-email.svg new file mode 100644 index 000000000..18883ebe4 --- /dev/null +++ b/app/assets/images/user/confirmation-email.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/stylesheets/new_design/_colors.scss b/app/assets/stylesheets/new_design/_colors.scss index b07ace308..a437d8530 100644 --- a/app/assets/stylesheets/new_design/_colors.scss +++ b/app/assets/stylesheets/new_design/_colors.scss @@ -15,4 +15,5 @@ $light-green: lighten($green, 25%); $dark-green: darken($green, 20%); $orange: #F28900; $orange-bg: lighten($orange, 35%); +$yellow: #FEF3B8; $light-yellow: #FFFFDE; diff --git a/app/assets/stylesheets/new_design/confirmations.scss b/app/assets/stylesheets/new_design/confirmations.scss new file mode 100644 index 000000000..7c59e979b --- /dev/null +++ b/app/assets/stylesheets/new_design/confirmations.scss @@ -0,0 +1,64 @@ +@import "colors"; +@import "constants"; + +.devise-confirmations { + .one-column-centered { + max-width: 600px; + } + + .confirmation-icon, + .confirmation-preamble, + .confirmation-instructions, + .confirmation-separator { + font-size: 1.15em; + margin-bottom: $default-padding * 3; + } + + .confirmation-icon { + display: block; + margin-left: auto; + margin-right: auto; + } + + .confirmation-instructions { + color: #000000; + background-color: $yellow; + margin-left: -15px; + margin-right: -15px; + padding: 15px 20px 17px 20px; + } + + .confirmation-separator { + height: 1px; + margin-left: -12px; + margin-right: -12px; + border: none; + border-top: 1px solid #DDDDDD; + } + + .confirmation-resend { + p { + margin-bottom: $default-padding; + } + + .form { + display: flex; + flex-wrap: wrap; + + input, + button { + margin-bottom: $default-spacer; + } + + input[type=email] { + width: auto; + flex-grow: 1; + margin-right: $default-spacer; + } + } + + label { + display: none; + } + } +} diff --git a/app/assets/stylesheets/new_design/new_footer.scss b/app/assets/stylesheets/new_design/new_footer.scss index b17ff187d..75e6df47d 100644 --- a/app/assets/stylesheets/new_design/new_footer.scss +++ b/app/assets/stylesheets/new_design/new_footer.scss @@ -22,7 +22,7 @@ footer { .footer-columns { @extend %horizontal-list; justify-content: flex-start; - margin: 0 -20px; + margin: 0 -15px; } .footer-column { diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb index 927f44bc9..b60e2deeb 100644 --- a/app/controllers/users/confirmations_controller.rb +++ b/app/controllers/users/confirmations_controller.rb @@ -4,9 +4,10 @@ class Users::ConfirmationsController < Devise::ConfirmationsController layout "new_application" # GET /resource/confirmation/new - # def new - # super - # end + def new + # Allow displaying the user email in the message + self.resource = resource_class.new(email: user_email_param) + end # POST /resource/confirmation # def create @@ -20,6 +21,10 @@ class Users::ConfirmationsController < Devise::ConfirmationsController # protected + def user_email_param + params.permit(user: :email).dig(:user, :email) + end + # The path used after resending confirmation instructions. # def after_resending_confirmation_instructions_path_for(resource_name) # super(resource_name) diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 85964b628..980740240 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -22,18 +22,20 @@ class Users::RegistrationsController < Devise::RegistrationsController # POST /resource def create - user = User.find_by(email: params[:user][:email]) - if user.present? - if user.confirmed? - UserMailer.new_account_warning(user).deliver_later + # Handle existing user trying to sign up again + existing_user = User.find_by(email: params[:user][:email]) + if existing_user.present? + if existing_user.confirmed? + UserMailer.new_account_warning(existing_user).deliver_later + flash.notice = t('devise.registrations.signed_up_but_unconfirmed') + return redirect_to root_path else - user.resend_confirmation_instructions + existing_user.resend_confirmation_instructions + return redirect_to after_inactive_sign_up_path_for(existing_user) end - flash.notice = t('devise.registrations.signed_up_but_unconfirmed') - redirect_to root_path - else - super end + + super end # GET /resource/edit @@ -78,7 +80,8 @@ class Users::RegistrationsController < Devise::RegistrationsController # end # The path used after sign up for inactive accounts. - # def after_inactive_sign_up_path_for(resource) - # super(resource) - # end + def after_inactive_sign_up_path_for(resource) + flash.discard(:notice) # Remove devise's default message (as we have a custom page to explain it) + new_confirmation_path(resource, :user => { email: resource.email }) + end end diff --git a/app/views/users/confirmations/new.html.haml b/app/views/users/confirmations/new.html.haml index 0f7e6534a..83c389e61 100644 --- a/app/views/users/confirmations/new.html.haml +++ b/app/views/users/confirmations/new.html.haml @@ -1,17 +1,31 @@ -- content_for(:title, 'Renvoyer les instructions de confirmation de compte') +- content_for(:title, 'Confirmer votre adresse email') - content_for :footer do = render partial: 'root/footer' -.container.devise-container +.container.devise-container.devise-confirmations .one-column-centered = devise_error_messages! - = form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { class: 'form' }) do |f| + %img.confirmation-icon{ src: image_url("user/confirmation-email.svg"), alt: "" } - %h1 Renvoyer les instructions de confirmation de compte + %p.confirmation-preamble + = succeed '.' do + Avant d’effectuer votre démarche, nous avons besoin de vérifier votre adresse + - if resource.email.present? + %strong= resource.email - = f.label :email, 'Email' - = f.email_field :email, autofocus: true + %p.confirmation-instructions + Ouvrez votre boîte email, et + %strong cliquez sur le lien d’activation + dans le message que vous avez reçu. - = f.submit 'Renvoyer les instructions de confirmation', class: 'button primary' + %hr.confirmation-separator + + .confirmation-resend + %p Si vous n’avez pas reçu notre message, nous pouvons vous le renvoyer. + + = form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { class: 'form' }) do |f| + = f.label :email, 'Email' + = f.email_field :email, placeholder: 'Email', class: 'small', autofocus: true + = f.submit 'Renvoyer un email de confirmation', class: 'button' diff --git a/spec/controllers/users/registrations_controller_spec.rb b/spec/controllers/users/registrations_controller_spec.rb index 14af91a6a..2f3c80463 100644 --- a/spec/controllers/users/registrations_controller_spec.rb +++ b/spec/controllers/users/registrations_controller_spec.rb @@ -74,8 +74,7 @@ describe Users::RegistrationsController, type: :controller do subject end - it { expect(response).to redirect_to(root_path) } - it { expect(flash.notice).to eq(I18n.t('devise.registrations.signed_up_but_unconfirmed')) } + it { expect(response).to redirect_to(new_user_confirmation_path(user: { email: user[:email] })) } it { expect(UserMailer).not_to have_received(:new_account_warning) } end end diff --git a/spec/features/new_user/invite_spec.rb b/spec/features/new_user/invite_spec.rb index e5774c883..d07efb73d 100644 --- a/spec/features/new_user/invite_spec.rb +++ b/spec/features/new_user/invite_spec.rb @@ -37,7 +37,7 @@ feature 'Invitations' do # Create the account sign_up_with invite.email, user_password - expect(page).to have_content("lien d'activation") + expect(page).to have_content('lien d’activation') # Confirm the account # (The user should be redirected to the dossier they was invited on) diff --git a/spec/features/sessions/sign_up_spec.rb b/spec/features/sessions/sign_up_spec.rb index 54750eb01..efd0929c4 100644 --- a/spec/features/sessions/sign_up_spec.rb +++ b/spec/features/sessions/sign_up_spec.rb @@ -1,15 +1,18 @@ require 'spec_helper' feature 'Signin up:' do + let(:user_email) { generate :user_email } + let(:user_password) { 'testpassword' } + scenario 'a new user can sign-up' do visit root_path click_on 'Connexion' click_on 'Créer un compte' - sign_up_with 'testuser@exemple.fr' - expect(page).to have_content "Nous vous avons envoyé un email contenant un lien d'activation" + sign_up_with user_email, user_password + expect(page).to have_content "nous avons besoin de vérifier votre adresse #{user_email}" - click_confirmation_link_for 'testuser@exemple.fr' + click_confirmation_link_for user_email expect(page).to have_content 'Votre compte a été activé' expect(page).to have_current_path dossiers_path end @@ -25,12 +28,37 @@ feature 'Signin up:' do expect(page).to have_current_path new_user_session_path click_on 'Créer un compte' - sign_up_with 'testuser@exemple.fr' - expect(page).to have_content "Nous vous avons envoyé un email contenant un lien d'activation" + sign_up_with user_email, user_password + expect(page).to have_content "nous avons besoin de vérifier votre adresse #{user_email}" - click_confirmation_link_for 'testuser@exemple.fr' + click_confirmation_link_for user_email expect(page).to have_content 'Votre compte a été activé' expect(page).to have_content procedure.libelle end end + + context 'when a user is not confirmed yet' do + before do + visit root_path + click_on 'Connexion' + click_on 'Créer un compte' + + sign_up_with user_email, user_password + end + + # 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, user_password + expect(page).to have_content 'Vous devez confirmer votre adresse email pour continuer' + end + end end