2023-07-14 22:33:42 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class SessionsController < Devise::SessionsController
|
2023-09-16 01:06:29 +03:00
|
|
|
before_action :configure_permitted_parameters
|
|
|
|
|
|
2024-06-08 23:02:29 +03:00
|
|
|
around_action :with_browser_locale
|
|
|
|
|
|
2023-07-14 22:33:42 +03:00
|
|
|
def create
|
2024-02-15 10:27:04 +02:00
|
|
|
email = sign_in_params[:email].to_s.downcase
|
|
|
|
|
|
|
|
|
|
if Docuseal.multitenant? && !User.exists?(email:)
|
2024-04-17 00:10:20 +03:00
|
|
|
Rollbar.warning('Sign in new user') if defined?(Rollbar)
|
|
|
|
|
|
2023-07-14 22:33:42 +03:00
|
|
|
return redirect_to new_registration_path(sign_up: true, user: sign_in_params.slice(:email)),
|
2024-09-18 19:47:47 +03:00
|
|
|
notice: I18n.t('create_a_new_account')
|
2023-07-14 22:33:42 +03:00
|
|
|
end
|
|
|
|
|
|
2024-02-15 10:27:04 +02:00
|
|
|
if User.exists?(email:, otp_required_for_login: true) && sign_in_params[:otp_attempt].blank?
|
2025-08-14 09:25:35 +03:00
|
|
|
return render :otp, locals: { resource: User.new(sign_in_params) }, status: :unprocessable_content
|
2023-09-16 01:06:29 +03:00
|
|
|
end
|
|
|
|
|
|
2023-07-14 22:33:42 +03:00
|
|
|
super
|
|
|
|
|
end
|
2023-07-16 15:11:07 +03:00
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
2023-08-24 00:28:21 +03:00
|
|
|
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
|
|
|
|
|
|
2023-09-16 01:06:29 +03:00
|
|
|
def configure_permitted_parameters
|
|
|
|
|
devise_parameter_sanitizer.permit(:sign_in, keys: [:otp_attempt])
|
|
|
|
|
end
|
|
|
|
|
|
2023-10-18 22:56:28 +03:00
|
|
|
def set_flash_message(key, kind, options = {})
|
|
|
|
|
return if key == :alert && kind == 'already_authenticated'
|
2023-07-16 15:11:07 +03:00
|
|
|
|
2023-10-18 22:56:28 +03:00
|
|
|
super
|
2023-07-16 15:11:07 +03:00
|
|
|
end
|
2023-07-14 22:33:42 +03:00
|
|
|
end
|