Add /connect route
All checks were successful
CI / scan_ruby (push) Successful in 17s
CI / scan_js (push) Successful in 12s
CI / lint (push) Successful in 12s
CI / test (push) Successful in 26s

This commit is contained in:
sto 2025-06-21 18:00:06 +02:00
parent 6fb5ba5f3e
commit ef3c63ea67
2 changed files with 28 additions and 5 deletions

View File

@ -1,10 +1,10 @@
class MessagesController < ApplicationController
include CompletionsConcern
skip_before_action :verify_authenticity_token, only: %i[ create cors_preflight_check ]
skip_before_action :require_authentication, only: %i[ create cors_preflight_check ]
skip_before_action :verify_authenticity_token, only: %i[ create connect cors_preflight_check ]
skip_before_action :require_authentication, only: %i[ create connect cors_preflight_check ]
before_action :cors_set_access_control_headers, only: %i[ create cors_preflight_check ]
before_action :cors_set_access_control_headers, only: %i[ create connect cors_preflight_check ]
before_action :set_contest, only: %i[ convert destroy ]
before_action :set_data, only: %i[ convert ]
@ -24,6 +24,27 @@ class MessagesController < ApplicationController
skip_authorization
end
def connect
skip_authorization
if !params.key?(:token)
respond_to do |format|
format.json { render json: { error: "no token provided" }, status: 400 }
end
else
@contest = Contest.find_by_token_for(:token, params[:token])
if @contest
respond_to do |format|
format.json { render json: { name: @contest.name }, status: 200 }
end
else
respond_to do |format|
format.json { render json: { error: "invalid token" }, status: 400 }
end
end
end
end
def create
skip_authorization
@ -37,12 +58,12 @@ class MessagesController < ApplicationController
end
else
respond_to do |format|
format.json { render json: { error: "invalid contest token" }, status: 400 }
format.json { render json: { error: "invalid token" }, status: 400 }
end
end
rescue
respond_to do |format|
format.json { render json: { error: "invalid contest token" }, status: 400 }
format.json { render json: { error: "invalid token" }, status: 400 }
end
end
end

View File

@ -24,7 +24,9 @@ Rails.application.routes.draw do
resource :session
resources :users
options "connect", to: "messages#cors_preflight_check"
options "message", to: "messages#cors_preflight_check"
post "connect", to: "messages#connect"
post "message", to: "messages#create"
get "public/:id", to: "contests#scoreboard"