akkounts/app/controllers/settings_controller.rb
Râu Cao 4e2e13108c
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Update release notes draft
Refactor user preferences, add defaults from file
* Turn prefs into a flat hash structure, since nesting is not worth the
trouble
* Add a custom serializer class for prefs
* Add a config file for defaults and merge set prefs with unset ones
* Use booleans for "true" and "false", and integers where appropriate
2023-04-05 17:02:35 +02:00

53 lines
1.2 KiB
Ruby

class SettingsController < ApplicationController
before_action :authenticate_user!
before_action :set_main_nav_section
before_action :set_settings_section, only: ['show', 'update']
def index
redirect_to setting_path(:profile)
end
def show
@user = current_user
end
def update
@user = current_user
@user.preferences.merge! user_params[:preferences]
@user.save!
redirect_to setting_path(@settings_section), flash: {
success: 'Settings saved.'
}
end
def reset_password
current_user.send_reset_password_instructions
sign_out current_user
msg = "We have sent you an email with a link to reset your password."
redirect_to check_your_email_path, notice: msg
end
private
def set_main_nav_section
@current_section = :settings
end
def set_settings_section
@settings_section = params[:section]
allowed_sections = [:profile, :account, :lightning, :xmpp]
unless allowed_sections.include?(@settings_section.to_sym)
redirect_to setting_path(:profile)
end
end
def user_params
params.require(:user).permit(preferences: [
:lightning_notify_sats_received,
:xmpp_exchange_contacts_with_invitees
])
end
end