From 5a3c3fbfb9ebf91cf7a92fed931f5f5d4dd19dd6 Mon Sep 17 00:00:00 2001 From: scammo Date: Thu, 4 Jan 2024 16:34:58 +0100 Subject: [PATCH] root can create users and read all users --- .../app/Http/Controllers/UserController.php | 27 +++++ backend/database/seeders/DatabaseSeeder.php | 8 +- backend/routes/api.php | 2 + frontend/src/components/Header.vue | 5 +- frontend/src/router/index.js | 9 +- frontend/src/views/orga/Profile.vue | 2 +- frontend/src/views/orga/Root.vue | 101 ++++++++++++++++++ frontend/src/views/orga/RootTracks.vue | 44 -------- 8 files changed, 140 insertions(+), 58 deletions(-) create mode 100644 frontend/src/views/orga/Root.vue delete mode 100644 frontend/src/views/orga/RootTracks.vue diff --git a/backend/app/Http/Controllers/UserController.php b/backend/app/Http/Controllers/UserController.php index d3fb581..b80b6b3 100644 --- a/backend/app/Http/Controllers/UserController.php +++ b/backend/app/Http/Controllers/UserController.php @@ -10,6 +10,16 @@ class UserController extends Controller { + public function index(){ + if (!Auth::check()){ + abort(403); + } + if(Auth::user()->username != "root"){ + abort(403); + } + return User::all(); + } + public function me(){ if (!Auth::check()){ abort(403); @@ -29,6 +39,23 @@ public function update(User $user, Request $request){ $user->save(); return $user; } + + + public function create(Request $request){ + if (!Auth::check()){ + abort(403); + } + if(Auth::user()->username != "root"){ + abort(403); + } + $user = new User(); + $user->username = $request->username; + $user->email = $request->email; + $user->password = Hash::make($request->password); + $user->save(); + return $user; + } + public function updatePassword(User $user, Request $request){ if (!Auth::check()){ abort(403); diff --git a/backend/database/seeders/DatabaseSeeder.php b/backend/database/seeders/DatabaseSeeder.php index 6fd870c..f452eae 100644 --- a/backend/database/seeders/DatabaseSeeder.php +++ b/backend/database/seeders/DatabaseSeeder.php @@ -14,18 +14,12 @@ class DatabaseSeeder extends Seeder */ public function run(): void { + $rootUser = new User(); $rootUser->username = 'root'; $rootUser->email = 'root@chaostreff-flensburg.de'; $rootUser->password = Hash::make('password'); $rootUser->email_verified_at = now(); $rootUser->save(); - - $rootUser = new User(); - $rootUser->username = 'scammo'; - $rootUser->email = 'samuel@chaostreff-flensburg.de'; - $rootUser->password = Hash::make('test123'); - $rootUser->email_verified_at = now(); - $rootUser->save(); } } diff --git a/backend/routes/api.php b/backend/routes/api.php index 99e952b..fc5623c 100644 --- a/backend/routes/api.php +++ b/backend/routes/api.php @@ -33,5 +33,7 @@ Route::get('user', [\App\Http\Controllers\UserController::class, 'me']); +Route::get('users', [\App\Http\Controllers\UserController::class, 'index']); +Route::post('user', [\App\Http\Controllers\UserController::class, 'create']); Route::post('user/{user}', [\App\Http\Controllers\UserController::class, 'update']); Route::post('user/{user}/password', [\App\Http\Controllers\UserController::class, 'updatePassword']); diff --git a/frontend/src/components/Header.vue b/frontend/src/components/Header.vue index 40a41dd..8ac8f8a 100644 --- a/frontend/src/components/Header.vue +++ b/frontend/src/components/Header.vue @@ -1,12 +1,11 @@ + \ No newline at end of file diff --git a/frontend/src/views/orga/RootTracks.vue b/frontend/src/views/orga/RootTracks.vue deleted file mode 100644 index d2004fe..0000000 --- a/frontend/src/views/orga/RootTracks.vue +++ /dev/null @@ -1,44 +0,0 @@ - - \ No newline at end of file