From b39604bd17e1d37f99d560de8686dd3103421558 Mon Sep 17 00:00:00 2001 From: AyakorK Date: Fri, 8 Dec 2023 14:57:39 +0100 Subject: [PATCH] feat: Add tos agreement to the omniauth registration form --- .../decidim/create_omniauth_registration.rb | 3 ++- .../devise/omniauth_registrations/new.html.erb | 14 ++++++++++++++ config/locales/en.yml | 3 +++ config/locales/fr.yml | 3 +++ .../decidim/omniauth_registration_form_extend.rb | 9 ++++++--- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/commands/decidim/create_omniauth_registration.rb b/app/commands/decidim/create_omniauth_registration.rb index 36a79b9..40b6bcd 100644 --- a/app/commands/decidim/create_omniauth_registration.rb +++ b/app/commands/decidim/create_omniauth_registration.rb @@ -62,6 +62,8 @@ def create_or_find_user @user.email = (verified_email || form.email) @user.name = form.name @user.nickname = form.normalized_nickname + @user.tos_agreement = form.tos_agreement + @user.accepted_tos_version = form.current_organization.tos_version @user.newsletter_notifications_at = nil @user.password = generated_password @user.password_confirmation = generated_password @@ -75,7 +77,6 @@ def create_or_find_user @user.skip_confirmation! if verified_email end - @user.tos_agreement = "1" @user.save! end diff --git a/app/views/decidim/devise/omniauth_registrations/new.html.erb b/app/views/decidim/devise/omniauth_registrations/new.html.erb index 764f58a..6180d1e 100644 --- a/app/views/decidim/devise/omniauth_registrations/new.html.erb +++ b/app/views/decidim/devise/omniauth_registrations/new.html.erb @@ -69,6 +69,20 @@ +
+
+

<%= t(".tos_title") %>

+ +

+ <%= strip_tags(translated_attribute(Decidim::StaticPage.find_by(slug: "terms-and-conditions", organization: current_organization).content)) %> +

+ +
+ <%= f.check_box :tos_agreement, label: t(".tos_agreement", link: link_to(t(".terms"), page_path("terms-and-conditions"))) %> +
+
+
+ <%= f.hidden_field :email %> <%= f.hidden_field :uid %> <%= f.hidden_field :name %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 802d1bc..72a5ce5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -72,6 +72,9 @@ en: registration_info: Please complete your profile sign_up: Sign up subtitle: Create your account + terms: the terms and conditions of use + tos_agreement: By signing up you agree to %{link}. + tos_title: Terms of Service registrations: form: errors: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 8f700c3..9b333fe 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -72,6 +72,9 @@ fr: registration_info: Renseignez vos informations personnelles sign_up: Renseignez vos informations personnelles subtitle: Vous êtes sur le point de créer un compte sur la plateforme de pétitions du CESE. + terms: les termes et conditions d'utilisation + tos_agreement: En vous créant un compte, vous acceptez %{link}. + tos_title: Conditions d'utilisation registrations: form: errors: diff --git a/lib/extends/forms/decidim/omniauth_registration_form_extend.rb b/lib/extends/forms/decidim/omniauth_registration_form_extend.rb index 785007a..7d7084d 100644 --- a/lib/extends/forms/decidim/omniauth_registration_form_extend.rb +++ b/lib/extends/forms/decidim/omniauth_registration_form_extend.rb @@ -11,6 +11,7 @@ module OmniauthRegistrationFormExtend attribute :address, String attribute :postal_code, String attribute :city, String + attribute :tos_agreement, ::ActiveModel::Type::Boolean validates :email, "valid_email_2/email": { mx: true } validates :postal_code, @@ -18,10 +19,12 @@ module OmniauthRegistrationFormExtend :city, :address, :certification, - presence: true, unless: ->(form) { form.certification.blank? } + :tos_agreement, + presence: true, unless: ->(form) { form.tos_agreement.blank? } - validates :postal_code, numericality: { only_integer: true }, length: { is: 5 }, unless: ->(form) { form.certification.blank? } - validates :certification, acceptance: true, presence: true + validates :postal_code, numericality: { only_integer: true }, length: { is: 5 }, unless: ->(form) { form.tos_agreement.blank? } + validates :certification, acceptance: true, presence: true, unless: ->(form) { form.tos_agreement.blank? } + validates :tos_agreement, acceptance: true, presence: true validate :over_16? private