refactor(ujs): france_connect controller to use turbo
This commit is contained in:
parent
921f38833d
commit
b0aa777315
9 changed files with 19 additions and 39 deletions
|
@ -53,7 +53,7 @@ class FranceConnect::ParticulierController < ApplicationController
|
|||
if !user.can_france_connect?
|
||||
flash.alert = t('errors.messages.france_connect.forbidden_html', reset_link: new_user_password_path)
|
||||
|
||||
render js: ajax_redirect(root_path)
|
||||
redirect_to root_path
|
||||
else
|
||||
@fci.update(user: user)
|
||||
@fci.delete_merge_token!
|
||||
|
@ -63,8 +63,6 @@ class FranceConnect::ParticulierController < ApplicationController
|
|||
end
|
||||
else
|
||||
flash.alert = t('france_connect.particulier.flash.invalid_password')
|
||||
|
||||
render js: helpers.render_flash
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -112,10 +110,7 @@ class FranceConnect::ParticulierController < ApplicationController
|
|||
if @fci.nil? || !@fci.valid_for_merge?
|
||||
flash.alert = t('france_connect.particulier.flash.merger_token_expired', application_name: APPLICATION_NAME)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to root_path }
|
||||
format.js { render js: ajax_redirect(root_path) }
|
||||
end
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -134,12 +129,7 @@ class FranceConnect::ParticulierController < ApplicationController
|
|||
|
||||
user.update_attribute('loged_in_with_france_connect', User.loged_in_with_france_connects.fetch(:particulier))
|
||||
|
||||
redirection_location = stored_location_for(current_user) || root_path(current_user)
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to redirection_location }
|
||||
format.js { render js: ajax_redirect(root_path) }
|
||||
end
|
||||
redirect_to stored_location_for(current_user) || root_path(current_user)
|
||||
end
|
||||
|
||||
def redirect_france_connect_error_connection
|
||||
|
|
|
@ -28,11 +28,7 @@ import {
|
|||
acceptEmailSuggestion,
|
||||
discardEmailSuggestionBox
|
||||
} from '../new_design/user-sign_up';
|
||||
import {
|
||||
showFusion,
|
||||
showNewAccount,
|
||||
showNewAccountPasswordConfirmation
|
||||
} from '../new_design/fc-fusion';
|
||||
import { showFusion, showNewAccount } from '../new_design/fc-fusion';
|
||||
|
||||
const application = Application.start();
|
||||
registerControllers(application);
|
||||
|
@ -46,7 +42,6 @@ const DS = {
|
|||
showImportJustificatif,
|
||||
showFusion,
|
||||
showNewAccount,
|
||||
showNewAccountPasswordConfirmation,
|
||||
replaceSemicolonByComma,
|
||||
acceptEmailSuggestion,
|
||||
discardEmailSuggestionBox
|
||||
|
|
|
@ -11,9 +11,3 @@ export function showNewAccount() {
|
|||
show(document.querySelector('.new-account'));
|
||||
hide(document.querySelector('.new-account-password-confirmation'));
|
||||
}
|
||||
|
||||
export function showNewAccountPasswordConfirmation() {
|
||||
hide(document.querySelector('.fusion'));
|
||||
hide(document.querySelector('.new-account'));
|
||||
show(document.querySelector('.new-account-password-confirmation'));
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
%br
|
||||
= t('.fill_in_password')
|
||||
|
||||
= form_tag france_connect_particulier_merge_with_existing_account_path, remote: true, class: 'mt-2 form fconnect-form' do
|
||||
= form_tag france_connect_particulier_merge_with_existing_account_path, data: { turbo: true }, class: 'mt-2 form fconnect-form' do
|
||||
= hidden_field_tag :merge_token, merge_token
|
||||
= hidden_field_tag :email, email
|
||||
= label_tag :password, t('views.registrations.new.password_label', min_length: 8)
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
.fusion.hidden
|
||||
%p= t('.title_fill_in_password')
|
||||
|
||||
= form_tag france_connect_particulier_merge_with_existing_account_path, remote: true, class: 'mt-2 form fconnect-form' do
|
||||
= hidden_field_tag :merge_token, @fci.merge_token
|
||||
= hidden_field_tag :email, @fci.email_france_connect
|
||||
= form_tag france_connect_particulier_merge_with_existing_account_path, data: { turbo: true }, class: 'mt-2 form fconnect-form' do
|
||||
= hidden_field_tag :merge_token, @fci.merge_token, id: dom_id(@fci, :fusion_merge_token)
|
||||
= hidden_field_tag :email, @fci.email_france_connect, id: dom_id(@fci, :fusion_email)
|
||||
|
||||
= label_tag :password, t('views.registrations.new.password_label', min_length: 8)
|
||||
= password_field_tag :password, nil, autocomplete: 'current-password', class: 'mb-1'
|
||||
|
@ -36,10 +36,10 @@
|
|||
.new-account.hidden
|
||||
%p= t('.title_fill_in_email', application_name: APPLICATION_NAME)
|
||||
|
||||
= form_tag france_connect_particulier_merge_with_new_account_path, remote: true, class: 'mt-2 form' do
|
||||
= hidden_field_tag :merge_token, @fci.merge_token
|
||||
= label_tag :email, t('views.registrations.new.email_label')
|
||||
= email_field_tag :email, "", required: true
|
||||
= form_tag france_connect_particulier_merge_with_new_account_path, data: { turbo: true }, class: 'mt-2 form' do
|
||||
= hidden_field_tag :merge_token, @fci.merge_token, id: dom_id(@fci, :new_account_merge_token)
|
||||
= label_tag :email, t('views.registrations.new.email_label'), for: dom_id(@fci, :new_account_email)
|
||||
= email_field_tag :email, "", required: true, id: dom_id(@fci, :new_account_email)
|
||||
= submit_tag t('.button_use_this_email'), class: 'button primary'
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
<%= render_to_element('.new-account-password-confirmation', partial: 'password_confirmation', locals: { email: @email, merge_token: @merge_token }) %>
|
||||
|
||||
DS.showNewAccountPasswordConfirmation();
|
|
@ -0,0 +1,4 @@
|
|||
= turbo_stream.update '.new-account-password-confirmation', partial: 'password_confirmation', locals: { email: @email, merge_token: @merge_token }
|
||||
= turbo_stream.hide_all '.fusion'
|
||||
= turbo_stream.hide_all '.new-account'
|
||||
= turbo_stream.show_all '.new-account-password-confirmation'
|
|
@ -198,7 +198,7 @@ describe FranceConnect::ParticulierController, type: :controller do
|
|||
let(:merge_token) { fci.create_merge_token! }
|
||||
let(:email) { 'EXISTING_account@a.com ' }
|
||||
let(:password) { 'my-s3cure-p4ssword' }
|
||||
let(:format) { :js }
|
||||
let(:format) { :turbo_stream }
|
||||
|
||||
subject { post :merge_with_existing_account, params: { merge_token: merge_token, email: email, password: password }, format: format }
|
||||
|
||||
|
@ -309,7 +309,7 @@ describe FranceConnect::ParticulierController, type: :controller do
|
|||
let(:fci) { FranceConnectInformation.create!(user_info) }
|
||||
let(:merge_token) { fci.create_merge_token! }
|
||||
let(:email) { ' Account@a.com ' }
|
||||
let(:format) { :js }
|
||||
let(:format) { :turbo_stream }
|
||||
|
||||
subject { post :merge_with_new_account, params: { merge_token: merge_token, email: email }, format: format }
|
||||
|
||||
|
@ -323,7 +323,7 @@ describe FranceConnect::ParticulierController, type: :controller do
|
|||
expect(fci.user.email).to eq(email.downcase.strip)
|
||||
expect(fci.merge_token).to be_nil
|
||||
expect(controller.current_user).to eq(fci.user)
|
||||
expect(response.body).to include("window.location.href='/'")
|
||||
expect(response).to redirect_to(root_path)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue