39 lines
977 B
Ruby
39 lines
977 B
Ruby
class OnboardingController < ApplicationController
|
|
before_action :authenticate_user!
|
|
before_action :redirect_if_onboarding_complete, except: [ :complete ]
|
|
|
|
def index
|
|
# Display the onboarding form
|
|
end
|
|
|
|
def complete
|
|
if onboarding_params_valid?
|
|
current_user.update!(onboarding_params)
|
|
current_user.complete_onboarding!
|
|
|
|
flash[:notice] = "Bienvenue sur #{Rails.application.config.app_name} ! Votre profil a été configuré avec succès."
|
|
redirect_to dashboard_path
|
|
else
|
|
flash.now[:alert] = "Veuillez remplir tous les champs requis."
|
|
render :index
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def onboarding_params
|
|
params.require(:user).permit(:first_name, :last_name)
|
|
end
|
|
|
|
def onboarding_params_valid?
|
|
onboarding_params[:first_name].present? &&
|
|
onboarding_params[:last_name].present?
|
|
end
|
|
|
|
def redirect_if_onboarding_complete
|
|
if current_user&.onboarding_completed?
|
|
redirect_to dashboard_path
|
|
end
|
|
end
|
|
end
|