mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
- Views use lazy t(".key") lookups; sentences with values or links stay
whole (interpolation, _html keys); counts use one/other plurals
- Stored-value labels (statuses, types, priorities...) are LabelSets read
from labels: in the current locale; field names and validation messages
under activerecord:; flash and activity text under flash:
- Services, models, helpers, mailer subjects, the logbook PDF, procedures
templates, records package README and transcription warnings localized;
the PDF reuses LogbookEntry#certification_statement instead of a copy
- Scripts read js: strings from a JSON tag via app/javascript/i18n.js
- Dates through I18n.l (app, weekday, month_year, long formats); html lang
follows the locale
- APP_LOCALE picks the language (falls back to English); missing
translations raise in development and tests
- README: Translating section and APP_LOCALE
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
2.3 KiB
Ruby
49 lines
2.3 KiB
Ruby
# Profile → Two-factor: set up an authenticator app (TOTP) for password and
|
|
# emailed-link sign-in, turn it off, or make new recovery codes.
|
|
class TwoFactorsController < ApplicationController
|
|
rate_limit to: 10, within: 5.minutes, only: %i[create destroy recovery_codes], with: -> { redirect_to edit_profile_path(anchor: "two-factor"), alert: t("flash.two_factors.try_again_later") }
|
|
|
|
def new
|
|
return redirect_to(back_path, notice: t("flash.two_factors.two_factor_is_already")) if current_user.otp_enabled?
|
|
session[:pending_otp_secret] ||= User.new_otp_secret
|
|
@secret = session[:pending_otp_secret]
|
|
svg = RQRCode::QRCode.new(User.otp_uri(@secret, current_user.email_address)).as_svg(module_size: 4, use_path: true, viewbox: true)
|
|
@qr_data_uri = "data:image/svg+xml;base64,#{Base64.strict_encode64(svg)}"
|
|
end
|
|
|
|
def create
|
|
secret = session[:pending_otp_secret]
|
|
return redirect_to(new_two_factor_path(return_to: params[:return_to])) unless secret
|
|
if User.valid_otp?(secret, params[:code])
|
|
session.delete(:pending_otp_secret)
|
|
@codes = current_user.enable_otp!(secret)
|
|
log_security("turned on two-factor")
|
|
render :codes
|
|
else
|
|
redirect_to new_two_factor_path(return_to: params[:return_to]), alert: t("flash.two_factors.that_code_didn_t")
|
|
end
|
|
end
|
|
|
|
def recovery_codes
|
|
return redirect_to(edit_profile_path(anchor: "two-factor"), alert: t("flash.two_factors.that_code_didn_t_2")) unless current_user.verify_second_factor(params[:code])
|
|
@codes = current_user.enable_otp!(current_user.otp_secret)
|
|
log_security("made new recovery codes")
|
|
render :codes
|
|
end
|
|
|
|
def destroy
|
|
return redirect_to(edit_profile_path(anchor: "two-factor"), alert: t("flash.two_factors.that_code_didn_t_3")) unless current_user.verify_second_factor(params[:code])
|
|
current_user.disable_otp!
|
|
log_security("turned off two-factor")
|
|
redirect_to edit_profile_path(anchor: "two-factor"), notice: t("flash.two_factors.two_factor_is_off")
|
|
end
|
|
|
|
private
|
|
|
|
# Back to a signing invitation the user came from, else the profile.
|
|
def back_path = params[:return_to].to_s.match?(%r{\A/sign/[\w-]+\z}) ? params[:return_to] : edit_profile_path(anchor: "two-factor")
|
|
helper_method :back_path
|
|
|
|
def log_security(what) = Rails.logger.info("[auth] #{current_user.email_address} #{what}")
|
|
end
|