the browser-facing portion of osu!
at master 1.6 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Http\Controllers; 7 8use App\Models\Tournament; 9use Auth; 10 11class TournamentsController extends Controller 12{ 13 public function __construct() 14 { 15 $this->middleware('auth', ['only' => [ 16 'register', 17 ]]); 18 19 parent::__construct(); 20 } 21 22 public function index() 23 { 24 return ext_view('tournaments.index', [ 25 'listing' => Tournament::getGroupedListing(), 26 ]); 27 } 28 29 public function show($id) 30 { 31 return ext_view('tournaments.show', [ 32 'tournament' => Tournament::findOrFail($id), 33 ]); 34 } 35 36 public function unregister($id) 37 { 38 $tournament = Tournament::findOrFail($id); 39 40 if (!$tournament->isRegistrationOpen()) { 41 return error_popup('registrations are closed!'); 42 } 43 44 $tournament->unregister(Auth::user()); 45 46 return ujs_redirect(route('tournaments.show', $tournament)); 47 } 48 49 public function register($id) 50 { 51 $tournament = Tournament::findOrFail($id); 52 $user = Auth::user(); 53 54 if (!$tournament->isRegistrationOpen()) { 55 return error_popup('registrations are closed!'); 56 } 57 58 if (!$tournament->isValidRank($user)) { 59 return error_popup('invalid rank!'); 60 } 61 62 $tournament->register($user); 63 64 return ujs_redirect(route('tournaments.show', $tournament)); 65 } 66}