2024-02-02 09:05:04 -06:00
|
|
|
class RegistrationsController < ApplicationController
|
|
|
|
layout "auth"
|
2024-02-02 16:06:55 +00:00
|
|
|
|
2024-02-02 17:49:28 -06:00
|
|
|
before_action :set_user, only: :create
|
|
|
|
before_action :claim_invite_code, only: :create, if: :hosted_app?
|
|
|
|
|
2024-02-02 09:05:04 -06:00
|
|
|
def new
|
|
|
|
@user = User.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
family = Family.new
|
|
|
|
@user.family = family
|
|
|
|
|
|
|
|
if @user.save
|
2024-03-07 19:15:50 +01:00
|
|
|
Transaction::Category.create_default_categories(@user.family)
|
2024-02-02 09:05:04 -06:00
|
|
|
login @user
|
2024-02-03 14:17:49 -06:00
|
|
|
flash[:notice] = t(".success")
|
2024-02-02 09:05:04 -06:00
|
|
|
redirect_to root_path
|
|
|
|
else
|
2024-02-03 14:17:49 -06:00
|
|
|
flash[:alert] = t(".failure")
|
2024-03-14 22:30:46 +08:00
|
|
|
render :new, status: :unprocessable_entity
|
2024-02-02 09:05:04 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2024-02-02 17:49:28 -06:00
|
|
|
def set_user
|
|
|
|
@user = User.new user_params.except(:invite_code)
|
|
|
|
end
|
|
|
|
|
2024-02-02 09:05:04 -06:00
|
|
|
def user_params
|
2024-02-02 17:49:28 -06:00
|
|
|
params.require(:user).permit(:name, :email, :password, :password_confirmation, :invite_code)
|
|
|
|
end
|
|
|
|
|
|
|
|
def claim_invite_code
|
|
|
|
unless InviteCode.claim! params[:user][:invite_code]
|
2024-02-03 14:17:49 -06:00
|
|
|
redirect_to new_registration_path, alert: t("registrations.create.invalid_invite_code")
|
2024-02-02 17:49:28 -06:00
|
|
|
end
|
2024-02-02 09:05:04 -06:00
|
|
|
end
|
|
|
|
end
|