1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 05:09:38 +02:00
Maybe/app/controllers/registrations_controller.rb

42 lines
963 B
Ruby
Raw Normal View History

2024-02-02 09:05:04 -06:00
class RegistrationsController < ApplicationController
layout "auth"
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
Transaction::Category.create_default_categories(@user.family)
2024-02-02 09:05:04 -06:00
login @user
flash[:notice] = t(".success")
2024-02-02 09:05:04 -06:00
redirect_to root_path
else
flash[:alert] = t(".failure")
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]
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