Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
69 lines
1.7 KiB
Ruby
69 lines
1.7 KiB
Ruby
class Api::V1::Profile::MfaController < Api::BaseController
|
|
before_action :check_mfa_feature_available
|
|
before_action :check_mfa_enabled, only: [:destroy, :backup_codes]
|
|
before_action :check_mfa_disabled, only: [:create, :verify]
|
|
before_action :validate_otp, only: [:verify, :backup_codes, :destroy]
|
|
before_action :validate_password, only: [:destroy]
|
|
|
|
def show; end
|
|
|
|
def create
|
|
mfa_service.enable_two_factor!
|
|
end
|
|
|
|
def verify
|
|
@backup_codes = mfa_service.verify_and_activate!
|
|
end
|
|
|
|
def destroy
|
|
mfa_service.disable_two_factor!
|
|
end
|
|
|
|
def backup_codes
|
|
@backup_codes = mfa_service.generate_backup_codes!
|
|
end
|
|
|
|
private
|
|
|
|
def mfa_service
|
|
@mfa_service ||= Mfa::ManagementService.new(user: current_user)
|
|
end
|
|
|
|
def check_mfa_enabled
|
|
render_could_not_create_error(I18n.t('errors.mfa.not_enabled')) unless current_user.mfa_enabled?
|
|
end
|
|
|
|
def check_mfa_feature_available
|
|
return if Chatwoot.mfa_enabled?
|
|
|
|
render json: {
|
|
error: I18n.t('errors.mfa.feature_unavailable')
|
|
}, status: :forbidden
|
|
end
|
|
|
|
def check_mfa_disabled
|
|
render_could_not_create_error(I18n.t('errors.mfa.already_enabled')) if current_user.mfa_enabled?
|
|
end
|
|
|
|
def validate_otp
|
|
authenticated = Mfa::AuthenticationService.new(
|
|
user: current_user,
|
|
otp_code: mfa_params[:otp_code]
|
|
).authenticate
|
|
|
|
return if authenticated
|
|
|
|
render_could_not_create_error(I18n.t('errors.mfa.invalid_code'))
|
|
end
|
|
|
|
def validate_password
|
|
return if current_user.valid_password?(mfa_params[:password])
|
|
|
|
render_could_not_create_error(I18n.t('errors.mfa.invalid_credentials'))
|
|
end
|
|
|
|
def mfa_params
|
|
params.permit(:otp_code, :password)
|
|
end
|
|
end
|