Skip to content

Commit

Permalink
feat: Add tos agreement to the omniauth registration form
Browse files Browse the repository at this point in the history
  • Loading branch information
AyakorK committed Dec 8, 2023
1 parent f733588 commit b39604b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/commands/decidim/create_omniauth_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -75,7 +77,6 @@ def create_or_find_user
@user.skip_confirmation! if verified_email
end

@user.tos_agreement = "1"
@user.save!
end

Expand Down
14 changes: 14 additions & 0 deletions app/views/decidim/devise/omniauth_registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@
</div>
</div>

<div class="card" id="card__tos">
<div class="card__content">
<h3><%= t(".tos_title") %></h3>

<p class="tos-text">
<%= strip_tags(translated_attribute(Decidim::StaticPage.find_by(slug: "terms-and-conditions", organization: current_organization).content)) %>
</p>

<div class="field">
<%= f.check_box :tos_agreement, label: t(".tos_agreement", link: link_to(t(".terms"), page_path("terms-and-conditions"))) %>
</div>
</div>
</div>

<%= f.hidden_field :email %>
<%= f.hidden_field :uid %>
<%= f.hidden_field :name %>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ 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,
:birth_date,
: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
Expand Down

0 comments on commit b39604b

Please sign in to comment.