Two accounts with same User E-Mail
I am trying to setup a multi-tenant app where each tenant is represented by an
Account
Upon signup via Jumpstarts
Accounts are separated by path
Users::RegistrationsController
an Account and associated Owner (a User)
is created.Accounts are separated by path
- example.com/users/sign_up
- example.com/:account_1
- example.com/:account_2
I want to achieve the following:
An Account Owner should be able to sign up again, with the same E-Mail address, and create a second
Account
and AccountUser
entry without creating a second User
. This would allow one User to own several accounts. Currently validations on Users::RegistrationsController#create
fail if a User with the same E-Mail address already exists.So I tried to edit the
`Users::RegistrationsController#build_resource`
method as follows:- Find User by E-Mail address from signup params
- If there is one, assign it to be
self.resource =
- Assign account signup data to account variable
def build_resource(hash = {})
# resource = User
existing_user = User.find_by(email: hash.dig(:email))
self.resource = existing_user || resource_class.new_with_session(hash, session)
# Jumpstart: Skip email confirmation on registration.
# Require confirmation when user changes their email only
resource.skip_confirmation!
# Registering to accept an invitation should display the invitation on sign up
if params[:invite] && (invite = AccountInvitation.find_by(token: params[:invite]))
@account_invitation = invite
# Build and display account fields in registration form if enabled
elsif Jumpstart.config.register_with_account?
account = resource.owned_accounts.select(&:new_record?).first
account ||= resource.owned_accounts.new
account.account_users.new(user: resource, admin: true)
end
end
Problem:
New Account and AccountUser rows are not created. But I can't figure out whats wrong.
Has anybody already implemented this behavior?
Problem:
New Account and AccountUser rows are not created. But I can't figure out whats wrong.
Has anybody already implemented this behavior?
Notifications
You’re not receiving notifications from this thread.