mirror of https://github.com/docusealco/docuseal
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.7 KiB
56 lines
1.7 KiB
# frozen_string_literal: true
|
|
|
|
class SessionsController < Devise::SessionsController
|
|
before_action :configure_permitted_parameters
|
|
|
|
around_action :with_browser_locale
|
|
|
|
def create
|
|
email = sign_in_params[:email].to_s.downcase
|
|
|
|
if Docuseal.multitenant? && !User.exists?(email:)
|
|
Rollbar.warning('Sign in new user') if defined?(Rollbar)
|
|
|
|
return redirect_to new_registration_path(sign_up: true, user: sign_in_params.slice(:email)),
|
|
notice: I18n.t('create_a_new_account')
|
|
end
|
|
|
|
if User.exists?(email:, otp_required_for_login: true) && sign_in_params[:otp_attempt].blank?
|
|
return render :otp, locals: { resource: User.new(sign_in_params) }, status: :unprocessable_content
|
|
end
|
|
|
|
super
|
|
end
|
|
|
|
private
|
|
|
|
def after_sign_in_path_for(...)
|
|
if params[:redir].present?
|
|
return console_redirect_index_path(redir: params[:redir]) if params[:redir].starts_with?(Docuseal::CONSOLE_URL)
|
|
|
|
return params[:redir]
|
|
end
|
|
|
|
super
|
|
end
|
|
|
|
def configure_permitted_parameters
|
|
devise_parameter_sanitizer.permit(:sign_in, keys: [:otp_attempt])
|
|
end
|
|
|
|
# Sign-out lands the user on the Clerk Account Portal so a fresh sign-in
|
|
# establishes the apex __session cookie shared across all Bloombilt apps.
|
|
# Replaces Devise's default respond_to_on_destroy, which renders the local
|
|
# password sign-in page that the Clerk migration deliberately leaves
|
|
# unlinked from the UI.
|
|
def respond_to_on_destroy
|
|
redirect_to ApplicationController::ACCOUNT_PORTAL_SIGN_IN_URL, allow_other_host: true
|
|
end
|
|
|
|
def set_flash_message(key, kind, options = {})
|
|
return if key == :alert && kind == 'already_authenticated'
|
|
|
|
super
|
|
end
|
|
end
|