Files
docuseal/app/controllers/sessions_controller.rb
T

41 lines
1.1 KiB
Ruby
Raw Normal View History

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
2023-07-14 22:33:42 +03:00
def create
if Docuseal.multitenant? && !User.exists?(email: sign_in_params[:email])
return redirect_to new_registration_path(sign_up: true, user: sign_in_params.slice(:email)),
notice: 'Create a new account'
end
2023-09-16 01:06:29 +03:00
if User.exists?(email: sign_in_params[:email], otp_required_for_login: true) && sign_in_params[:otp_attempt].blank?
return render :otp, locals: { resource: User.new(sign_in_params) }, status: :unprocessable_entity
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
def set_flash_message(key, kind, options = {})
return if key == :alert && kind == 'already_authenticated'
2023-07-16 15:11:07 +03:00
super
2023-07-16 15:11:07 +03:00
end
2023-07-14 22:33:42 +03:00
end