]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/UserController.php
server calculated scoring
[alttp.git] / app / Http / Controllers / UserController.php
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Events\UserChanged;
6 use App\Models\User;
7 use Illuminate\Http\Request;
8
9 class UserController extends Controller
10 {
11
12         public function setLanguage(Request $request) {
13                 $user = $request->user();
14                 if (!$user) return;
15
16                 $validatedData = $request->validate([
17                         'language' => 'required|in:de,en',
18                 ]);
19
20                 $user->locale = $validatedData['language'];
21                 $user->update();
22
23                 return $user->toJson();
24         }
25
26         public function setStreamLink(Request $request, User $user) {
27                 $this->authorize('setStreamLink', $user);
28
29                 $validatedData = $request->validate([
30                         'stream_link' => 'required|url',
31                 ]);
32
33                 $user->stream_link = $validatedData['stream_link'];
34                 $user->update();
35
36                 UserChanged::dispatch($user);
37
38                 return $user->toJson();
39         }
40
41         public function single(Request $request, $id) {
42                 $user = User::findOrFail($id);
43                 $this->authorize('view', $user);
44                 $user->load('participation');
45                 $user->load('participation.tournament');
46                 return $user->toJson();
47         }
48
49 }