Add /connect route
This commit is contained in:
parent
6fb5ba5f3e
commit
ef3c63ea67
@ -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
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user