Initial commit: monorepo Match Live TV.
Rails API, app Flutter, infrastruttura Docker/MediaMTX, sito marketing e documentazione di deploy. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
28
backend/app/controllers/public/invitations_controller.rb
Normal file
28
backend/app/controllers/public/invitations_controller.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module Public
|
||||
class InvitationsController < WebBaseController
|
||||
def show
|
||||
@token = params[:token]
|
||||
@invitation = TeamInvitation.pending.find_by(token_digest: Digest::SHA256.hexdigest(@token.to_s))
|
||||
unless @invitation
|
||||
redirect_to public_pricing_path, alert: "Invito non valido o scaduto"
|
||||
end
|
||||
end
|
||||
|
||||
def accept
|
||||
invitation = TeamInvitation.pending.find_by(token_digest: Digest::SHA256.hexdigest(params[:token].to_s))
|
||||
return redirect_to public_pricing_path, alert: "Invito non valido" unless invitation
|
||||
|
||||
if logged_in?
|
||||
if current_user.email.downcase != invitation.email.downcase
|
||||
redirect_to public_pricing_path, alert: "Questo invito è per #{invitation.email}"
|
||||
return
|
||||
end
|
||||
invitation.accept!(current_user)
|
||||
redirect_to public_team_dashboard_path(invitation.team), notice: "Sei entrato nella squadra!"
|
||||
else
|
||||
session[:pending_invite_token] = params[:token]
|
||||
redirect_to public_signup_path, notice: "Registrati con #{invitation.email} per accettare l'invito"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
47
backend/app/controllers/public/live_controller.rb
Normal file
47
backend/app/controllers/public/live_controller.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
module Public
|
||||
class LiveController < SiteBaseController
|
||||
layout "marketing_live"
|
||||
|
||||
ACTIVE_STATUSES = %w[live connecting reconnecting].freeze
|
||||
|
||||
def index
|
||||
@query = params[:q].to_s.strip
|
||||
@sessions = StreamSession
|
||||
.broadcasting
|
||||
.includes(:score_state, match: :team)
|
||||
.search_by_team_or_opponent(@query)
|
||||
.order(Arel.sql("started_at DESC NULLS LAST"), created_at: :desc)
|
||||
|
||||
@online_paths = Mediamtx::Client.new.online_path_names
|
||||
end
|
||||
|
||||
def show
|
||||
@session = StreamSession.includes(match: :team).find(params[:id])
|
||||
@match = @session.match
|
||||
@stream_closed = @session.terminal?
|
||||
@on_air = !@stream_closed && mediamtx_online?(@session)
|
||||
end
|
||||
|
||||
def status
|
||||
session = StreamSession.includes(match: :team).find(params[:id])
|
||||
closed = session.terminal?
|
||||
render json: {
|
||||
status: session.status,
|
||||
stream_closed: closed,
|
||||
live: !closed && (session.live? || mediamtx_online?(session)),
|
||||
on_air: !closed && mediamtx_online?(session),
|
||||
ended_at: session.ended_at,
|
||||
home_name: session.match.team.name,
|
||||
away_name: session.match.opponent_name,
|
||||
score: session.score_state&.as_cable_payload
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def mediamtx_online?(session)
|
||||
@online_paths_cache ||= Mediamtx::Client.new.online_path_names
|
||||
@online_paths_cache.include?(session.mediamtx_path_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
19
backend/app/controllers/public/pages_controller.rb
Normal file
19
backend/app/controllers/public/pages_controller.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module Public
|
||||
class PagesController < WebBaseController
|
||||
def home
|
||||
end
|
||||
|
||||
def features
|
||||
end
|
||||
|
||||
def pricing
|
||||
@plans = Plan.ordered
|
||||
end
|
||||
|
||||
def privacy
|
||||
end
|
||||
|
||||
def terms
|
||||
end
|
||||
end
|
||||
end
|
||||
33
backend/app/controllers/public/registrations_controller.rb
Normal file
33
backend/app/controllers/public/registrations_controller.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
module Public
|
||||
class RegistrationsController < WebBaseController
|
||||
def new
|
||||
redirect_to public_team_dashboard_path(current_user.teams.first) if logged_in? && current_user.teams.any?
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new(user_params.merge(role: "coach"))
|
||||
if @user.save
|
||||
session[:user_id] = @user.id
|
||||
if session[:pending_invite_token].present?
|
||||
token = session.delete(:pending_invite_token)
|
||||
invitation = TeamInvitation.pending.find_by(token_digest: Digest::SHA256.hexdigest(token))
|
||||
if invitation && invitation.email.downcase == @user.email.downcase
|
||||
invitation.accept!(@user)
|
||||
return redirect_to public_team_dashboard_path(invitation.team), notice: "Benvenuto nella squadra!"
|
||||
end
|
||||
end
|
||||
redirect_to new_public_team_path, notice: "Account creato. Ora crea la tua squadra."
|
||||
else
|
||||
flash.now[:alert] = @user.errors.full_messages.join(", ")
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:name, :email, :password, :password_confirmation)
|
||||
end
|
||||
end
|
||||
end
|
||||
15
backend/app/controllers/public/replay_controller.rb
Normal file
15
backend/app/controllers/public/replay_controller.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
module Public
|
||||
class ReplayController < SiteBaseController
|
||||
layout "marketing_live"
|
||||
|
||||
def show
|
||||
@session = StreamSession.includes(match: :team).find(params[:id])
|
||||
@recording = Recording.ready.find_by(stream_session: @session)
|
||||
@match = @session.match
|
||||
|
||||
unless @recording
|
||||
redirect_to public_live_path(@session), alert: "Replay non disponibile"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
24
backend/app/controllers/public/sessions_controller.rb
Normal file
24
backend/app/controllers/public/sessions_controller.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
module Public
|
||||
class SessionsController < WebBaseController
|
||||
def new
|
||||
redirect_to public_team_dashboard_path(current_user.teams.first) if logged_in? && current_user.teams.any?
|
||||
end
|
||||
|
||||
def create
|
||||
user = User.find_by(email: params[:email]&.downcase)
|
||||
if user&.authenticate(params[:password])
|
||||
session[:user_id] = user.id
|
||||
dest = user.teams.first ? public_team_dashboard_path(user.teams.first) : new_public_team_path
|
||||
redirect_to dest, notice: "Bentornato!"
|
||||
else
|
||||
flash.now[:alert] = "Email o password non validi"
|
||||
render :new, status: :unauthorized
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
reset_session
|
||||
redirect_to public_pricing_path, notice: "Disconnesso"
|
||||
end
|
||||
end
|
||||
end
|
||||
19
backend/app/controllers/public/site_base_controller.rb
Normal file
19
backend/app/controllers/public/site_base_controller.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module Public
|
||||
class SiteBaseController < ActionController::Base
|
||||
layout "marketing"
|
||||
|
||||
helper_method :current_user, :logged_in?
|
||||
|
||||
private
|
||||
|
||||
def current_user
|
||||
return @current_user if defined?(@current_user)
|
||||
|
||||
@current_user = User.find_by(id: session[:user_id]) if session[:user_id]
|
||||
end
|
||||
|
||||
def logged_in?
|
||||
current_user.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
119
backend/app/controllers/public/teams_controller.rb
Normal file
119
backend/app/controllers/public/teams_controller.rb
Normal file
@@ -0,0 +1,119 @@
|
||||
module Public
|
||||
class TeamsController < WebBaseController
|
||||
before_action :require_login!
|
||||
before_action :set_team, only: %i[
|
||||
dashboard billing checkout portal invite create_invitation
|
||||
remove_member destroy_invitation
|
||||
]
|
||||
|
||||
def new
|
||||
redirect_to public_team_dashboard_path(current_user.teams.first) if current_user.teams.any?
|
||||
end
|
||||
|
||||
def create
|
||||
if current_user.user_teams.where(role: "owner").exists?
|
||||
redirect_to public_team_dashboard_path(current_user.teams.first), alert: "Hai già una squadra"
|
||||
return
|
||||
end
|
||||
|
||||
team = Team.create!(team_params)
|
||||
UserTeam.create!(user: current_user, team: team, role: "owner")
|
||||
plan = params[:plan].presence_in(%w[free premium_light premium_full]) || "free"
|
||||
Billing::AssignPlan.call(team: team, plan_slug: plan)
|
||||
|
||||
if plan.in?(%w[premium_light premium_full]) && MatchLiveTv.stripe_enabled?
|
||||
redirect_to public_team_checkout_path(team, plan: plan)
|
||||
else
|
||||
redirect_to public_team_dashboard_path(team), notice: "Squadra creata con piano Free"
|
||||
end
|
||||
end
|
||||
|
||||
def dashboard
|
||||
require_team_owner!(@team)
|
||||
@entitlements = @team.entitlements
|
||||
@recordings = @team.recordings.ready.includes(stream_session: :match).order(created_at: :desc).limit(10)
|
||||
@members = @team.user_teams.includes(:user).where.not(role: "owner")
|
||||
@pending_invitations = @team.team_invitations.pending.order(created_at: :desc)
|
||||
end
|
||||
|
||||
def billing
|
||||
require_team_owner!(@team)
|
||||
@entitlements = @team.entitlements
|
||||
@plans = Plan.ordered
|
||||
end
|
||||
|
||||
def checkout
|
||||
require_team_owner!(@team)
|
||||
unless MatchLiveTv.stripe_enabled?
|
||||
redirect_to public_team_billing_path(@team), alert: "Pagamenti non ancora configurati sul server"
|
||||
return
|
||||
end
|
||||
|
||||
plan_slug = params[:plan].presence_in(%w[premium_light premium_full]) || "premium_light"
|
||||
url = Billing::Stripe::CheckoutSession.new(team: @team, user: current_user, plan_slug: plan_slug).url
|
||||
redirect_to url, allow_other_host: true
|
||||
end
|
||||
|
||||
def portal
|
||||
require_team_owner!(@team)
|
||||
unless MatchLiveTv.stripe_enabled?
|
||||
redirect_to public_team_billing_path(@team), alert: "Portale pagamenti non configurato"
|
||||
return
|
||||
end
|
||||
|
||||
url = Billing::Stripe::CheckoutSession.new(team: @team, user: current_user).portal_url
|
||||
redirect_to url, allow_other_host: true
|
||||
end
|
||||
|
||||
def invite
|
||||
require_team_owner!(@team)
|
||||
@entitlements = @team.entitlements
|
||||
end
|
||||
|
||||
def create_invitation
|
||||
require_team_owner!(@team)
|
||||
@entitlements = @team.entitlements
|
||||
staff_kind = params[:staff_kind].presence_in(TeamInvitation::STAFF_KINDS) || "transmission"
|
||||
@entitlements.assert_can_invite!(staff_kind: staff_kind)
|
||||
|
||||
email = params[:email]&.downcase&.strip
|
||||
token = TeamInvitation.generate_token
|
||||
@team.team_invitations.create!(
|
||||
email: email,
|
||||
token_digest: Digest::SHA256.hexdigest(token),
|
||||
role: "member",
|
||||
staff_kind: staff_kind,
|
||||
expires_at: 7.days.from_now
|
||||
)
|
||||
@invite_url = join_public_invitation_url(token: token)
|
||||
flash.now[:notice] = "Link invito generato (valido 7 giorni)"
|
||||
render :invite
|
||||
rescue Teams::EntitlementError => e
|
||||
redirect_to public_team_invite_path(@team), alert: e.message
|
||||
end
|
||||
|
||||
def remove_member
|
||||
require_team_owner!(@team)
|
||||
ut = @team.user_teams.find_by!(user_id: params[:user_id], role: "member")
|
||||
ut.destroy!
|
||||
redirect_to public_team_dashboard_path(@team), notice: "Accesso revocato"
|
||||
end
|
||||
|
||||
def destroy_invitation
|
||||
require_team_owner!(@team)
|
||||
inv = @team.team_invitations.pending.find(params[:invitation_id])
|
||||
inv.destroy!
|
||||
redirect_to public_team_dashboard_path(@team), notice: "Invito annullato"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_team
|
||||
@team = current_user.teams.find(params[:id])
|
||||
end
|
||||
|
||||
def team_params
|
||||
params.require(:team).permit(:name, :sport, :logo_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
18
backend/app/controllers/public/web_base_controller.rb
Normal file
18
backend/app/controllers/public/web_base_controller.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module Public
|
||||
class WebBaseController < SiteBaseController
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
private
|
||||
|
||||
def require_login!
|
||||
return if logged_in?
|
||||
|
||||
redirect_to public_login_path, alert: "Accedi per continuare"
|
||||
end
|
||||
|
||||
def require_team_owner!(team)
|
||||
membership = current_user.user_teams.find_by(team: team)
|
||||
redirect_to public_prezzi_path, alert: "Accesso non consentito" unless membership&.role == "owner"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user