mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-23 07:09:39 +02:00
Implement invitation codes
This commit is contained in:
parent
533e6690c2
commit
b3a792c47d
11 changed files with 149 additions and 9 deletions
|
@ -37,4 +37,9 @@ class ApplicationController < ActionController::Base
|
|||
Current.user = nil
|
||||
reset_session
|
||||
end
|
||||
|
||||
def hosted_app?
|
||||
ENV["HOSTED"] == "true"
|
||||
end
|
||||
helper_method :hosted_app?
|
||||
end
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
class RegistrationsController < ApplicationController
|
||||
layout "auth"
|
||||
|
||||
before_action :set_user, only: :create
|
||||
before_action :claim_invite_code, only: :create, if: :hosted_app?
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new(user_params)
|
||||
|
||||
family = Family.new
|
||||
@user.family = family
|
||||
|
||||
|
@ -23,7 +24,17 @@ class RegistrationsController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def set_user
|
||||
@user = User.new user_params.except(:invite_code)
|
||||
end
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:name, :email, :password, :password_confirmation)
|
||||
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: "Invalid invite code, please try again."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue