mirror of
https://github.com/oonyeje/Pearlception_Website_RoR.git
synced 2025-12-25 11:47:41 +00:00
- When creating a new company as an admin, a new database containing models for Runs, Grades, Results, Machines, and Oysters is migrated and created - When a user registers, they are automatically switched to their company's db in the server - When a user signs in they are also automatically swithched
38 lines
832 B
Ruby
38 lines
832 B
Ruby
class RegistrationsController < Devise::RegistrationsController
|
|
include ApplicationHelper
|
|
#protected
|
|
def new
|
|
Apartment::Tenant.switch!
|
|
end
|
|
|
|
|
|
def create
|
|
@user = User.new(sign_up_params)
|
|
|
|
if params[:company_serial]
|
|
params.require(:user).permit(:company_id)
|
|
company = Company.find_by(company_token: params[:company_serial])
|
|
|
|
if company
|
|
@user.company_id = company.id
|
|
if company.company_name == "IVA"
|
|
@user.admin = true
|
|
end
|
|
else
|
|
end
|
|
|
|
else
|
|
end
|
|
@user.save
|
|
sign_in @user
|
|
if !@user.admin
|
|
Apartment::Tenant.switch(Company.find(@user.company_id).company_name.gsub(/'/,'').gsub(/\s/,''))
|
|
end
|
|
redirect_to "/"
|
|
end
|
|
|
|
def sign_up_params
|
|
params.require(:user).permit(:email, :password, :password_confirmation)
|
|
end
|
|
end
|