impress/app/controllers/neopets_connections_controller.rb
Emi Matchu 903d6a8a19 Disallow email addresses in Neopets usernames
People are evading the filtering in the description and they know it!
Boooo!
2025-06-22 11:16:26 -07:00

35 lines
962 B
Ruby

class NeopetsConnectionsController < ApplicationController
def create
connection = authorized_user.neopets_connections.build
connection.neopets_username = params[:neopets_connection][:neopets_username]
if connection.save
render json: connection
else
render json: {
errors: connection.errors,
full_error_messages: connection.errors.map(&:full_message)
}, status: :bad_request
end
end
def destroy
connection = authorized_user.neopets_connections.find_by_neopets_username(params[:id])
if connection
if connection.destroy
render json: connection
else
render json: {error: 'failure'}, status: :internal_server_error
end
else
render json: {error: 'not found'}, status: :not_found
end
end
def authorized_user
if user_signed_in? && current_user.id == params[:user_id].to_i
current_user
else
raise AccessDenied
end
end
end