Select Git revision
users_controller.rb
users_controller.rb 849 B
class UsersController < ApplicationController
before_action :authenticate_user!, only: [ :update_theme ]
def leaderboard
@workload_data = User.leaderboard
end
def update_theme
if current_user.present?
# Ensure darkmode parameter is valid (light, dark)
theme = params[:darkmode].to_s
if [ "light", "dark" ].include?(theme)
if current_user.update(darkmode: theme)
render json: { success: true, theme: theme }, status: :ok
else
render json: { success: false, errors: current_user.errors.full_messages }, status: :unprocessable_entity
end
else
render json: { success: false, error: "Invalid theme value" }, status: :bad_request
end
else
render json: { success: false, error: "User not authenticated" }, status: :unauthorized
end
end
end