improve registration and add oauth

This commit is contained in:
Alex Turchyn
2023-07-14 22:33:42 +03:00
parent f7ef99a624
commit 6f3fe1dd7b
20 changed files with 170 additions and 23 deletions
+16 -2
View File
@@ -1,6 +1,16 @@
# frozen_string_literal: true
class RegistrationsController < Devise::RegistrationsController
prepend_before_action :require_no_authentication, only: [:show]
def show; end
def create
super
Accounts.create_default_template(resource.account) if resource.account.persisted?
end
private
def build_resource(_hash = {})
@@ -8,17 +18,21 @@ class RegistrationsController < Devise::RegistrationsController
account.timezone = Accounts.normalize_timezone(account.timezone)
self.resource = account.users.new(user_params)
account.name ||= "#{resource.full_name}'s Company" if params[:action] == 'create'
end
def user_params
return {} if params[:user].blank?
params.require(:user).permit(:first_name, :last_name, :email, :password)
params.require(:user).permit(:first_name, :last_name, :email, :password).compact_blank.tap do |attrs|
attrs[:password] ||= SecureRandom.hex if params[:action] == 'create'
end
end
def account_params
return {} if params[:account].blank?
params.require(:account).permit(:name, :timezone)
params.require(:account).permit(:name, :timezone).compact_blank
end
end