Files
simple-aircraft-manager-rails/app/controllers/profiles_controller.rb
T
rickyandClaude Opus 5.5 61c3749793 Deferrals, expirations, standard inspections, reminders, squawk fixes
- Squawks: defer an inoperative item under 91.213(d) once each condition
  is confirmed (pilots may too); deferred items stop grounding and are
  listed for awareness. Resolving can record the fix as a logbook entry
  (43.9 fields) or link an existing one
- Expiration dates on components (ELT battery, 91.207(c)) and documents;
  new document types (registration, airworthiness certificate, insurance,
  radio license). Expired replacement-critical parts and an expired
  registration (91.203) ground; others warn; registration warns 90 days out
- Standard inspections: one click adds annual, 100-hour, 91.411, 91.413,
  ELT (91.207(d)) and VOR (91.171) checks with the right rules, skipping
  ones already tracked and linking annual to 100-hour
- Weekly Monday reminder email to owners when something needs attention;
  profile opt-out; admin "send me this week's reminder"
- README feature table updated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 10:24:33 -05:00

34 lines
1.6 KiB
Ruby

class ProfilesController < ApplicationController
def edit
@user = current_user
end
# Changing the email or password needs the current password, so a session
# left open somewhere can't be turned into a takeover of the account.
def update
@user = current_user
attrs = params.require(:user).permit(:name, :email_address, :password, :password_confirmation, :reminder_emails)
attrs = attrs.except(:password, :password_confirmation) if attrs[:password].blank?
new_email = User.normalize_value_for(:email_address, attrs[:email_address].to_s) if attrs.key?(:email_address)
sensitive = (new_email && new_email != @user.email_address) || attrs.key?(:password)
# Checked before assigning: setting a new password replaces the digest at once.
if sensitive && !@user.authenticate_password(params.dig(:user, :current_password).to_s)
@user.assign_attributes(attrs.except(:password, :password_confirmation))
@user.errors.add(:base, "Enter your current password to change your email or password")
return render :edit, status: :unprocessable_entity
end
@user.assign_attributes(attrs)
if @user.save
@user.sessions.where.not(id: Current.session.id).destroy_all if attrs.key?(:password)
redirect_to root_path, notice: "Profile updated."
else
render :edit, status: :unprocessable_entity
end
end
def sign_out_others
count = current_user.sessions.where.not(id: Current.session.id).destroy_all.size
redirect_to edit_profile_path, notice: "Signed out #{helpers.pluralize(count, 'other session')}."
end
end