Skip to content

Commit

Permalink
updated club on registration
Browse files Browse the repository at this point in the history
  • Loading branch information
baldarn committed Aug 28, 2024
1 parent c7111eb commit c9c7f20
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 37 deletions.
8 changes: 0 additions & 8 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ Rails/LexicallyScopedActionFilter:
Exclude:
- 'app/controllers/users/registrations_controller.rb'

# Offense count: 4
# Configuration parameters: Database, Include.
# SupportedDatabases: mysql
# Include: db/**/*.rb
Rails/NotNullColumn:
Exclude:
- 'db/migrate/20240828093926_add_address_columns_to_club.rb'

# Offense count: 1
# Configuration parameters: ForbiddenMethods, AllowedMethods.
# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all
Expand Down
15 changes: 13 additions & 2 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ class RegistrationsController < Devise::RegistrationsController

# POST /resource
def create
params[:user][:registering] = true
super

return turbo_stream if @user.errors.present?

@club = Club.create!(name: 'DA IMPOSTARE', email: params[:user][:email])
@club = Club.create!(
name: @user.club_name,
email: @user.club_email,
address: @user.club_address,
postal_code: @user.club_postal_code,
municipality: @user.club_municipality,
province: @user.club_province,
tax_code: @user.club_tax_code
)
@user.club = @club
@user.save
end
Expand Down Expand Up @@ -52,7 +61,9 @@ def destroy

# If you have extra params to permit, append them to the sanitizer.
def configure_sign_up_params
devise_parameter_sanitizer.permit(:sign_up, keys: %i[first_name last_name club_name])
devise_parameter_sanitizer.permit(:sign_up,
keys: %i[first_name last_name registering club_name club_email club_address
club_postal_code club_municipality club_province club_tax_code])
end

# If you have extra params to permit, append them to the sanitizer.
Expand Down
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class User < ApplicationRecord
scope :with_expiring_blsd,
-> { where(blsd_expires_at: Time.zone.today.beginning_of_day..6.months.from_now) }

attr_accessor :registering, :club_name, :club_email, :club_address, :club_postal_code,
:club_municipality, :club_province, :club_tax_code

validates :club_name, :club_email, :club_address, :club_postal_code, :club_municipality, :club_province,
:club_tax_code, presence: true, if: -> { registering == true }

def admin?
role == 'admin'
end
Expand Down
29 changes: 12 additions & 17 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email,
required: true,
autofocus: true,
input_html: { autocomplete: "email" }%>
<%= f.input :first_name,
required: true,
autofocus: true %>
<%= f.input :last_name,
required: true,
autofocus: true %>
<%= f.input :password,
required: true,
hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length),
input_html: { autocomplete: "new-password" } %>
<%= f.input :password_confirmation,
required: true,
input_html: { autocomplete: "new-password" } %>
<%= f.input :email,required: true, autofocus: true, input_html: { autocomplete: "email" }%>
<%= f.input :first_name,required: true, autofocus: true %>
<%= f.input :last_name,required: true, autofocus: true %>
<%= f.input :club_name, required: true, autofocus: true %>
<%= f.input :club_email, required: true, autofocus: true %>
<%= f.input :club_address, required: true, autofocus: true %>
<%= f.input :club_postal_code, required: true, autofocus: true %>
<%= f.input :club_municipality, required: true, autofocus: true %>
<%= f.input :club_province, required: true, autofocus: true %>
<%= f.input :club_tax_code, required: true, autofocus: true %>
<%= f.input :password,required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length), input_html: { autocomplete: "new-password" } %>
<%= f.input :password_confirmation, required: true, input_html: { autocomplete: "new-password" } %>
</div>
<div class="form-actions">
<%= f.button :submit, "Sign up" %>
Expand Down
6 changes: 6 additions & 0 deletions config/locales/simple_form.it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ it:
first_name: Nome
last_name: Cognome
email: Email
club_name: Nome Club
club_address: Indirizzo Club
club_postal_code: CAP Club
club_municipality: Comune Club
club_province: Provincia Club
club_tax_code: Codice Fiscale/PIva Club
member:
first_name: Nome
last_name: Cognome
Expand Down
10 changes: 5 additions & 5 deletions db/migrate/20240828093926_add_address_columns_to_club.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
class AddAddressColumnsToClub < ActiveRecord::Migration[7.2]
def change
change_table :clubs, bulk: true do |t|
t.string :address, null: false
t.string :postal_code, null: false
t.string :municipality, null: false
t.string :province, null: false
t.string :address, null: false, default: 'DA IMPOSTARE'
t.string :postal_code, null: false, default: 'DA IMPOSTARE'
t.string :municipality, null: false, default: 'DA IMPOSTARE'
t.string :province, null: false, default: 'DA IMPOSTARE'
t.string :tax_code, null: false, default: 'DA IMPOSTARE'
t.string :telephone
t.string :tax_code, null: false
end
end
end
10 changes: 5 additions & 5 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
t.string "email", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "address", null: false
t.string "postal_code", null: false
t.string "municipality", null: false
t.string "province", null: false
t.string "address", default: "DA IMPOSTARE", null: false
t.string "postal_code", default: "DA IMPOSTARE", null: false
t.string "municipality", default: "DA IMPOSTARE", null: false
t.string "province", default: "DA IMPOSTARE", null: false
t.string "tax_code", default: "DA IMPOSTARE", null: false
t.string "telephone"
t.string "tax_code", null: false
end

create_table "event_groups", force: :cascade do |t|
Expand Down

0 comments on commit c9c7f20

Please sign in to comment.