diff --git a/backend/app/Http/Controllers/UserController.php b/backend/app/Http/Controllers/UserController.php new file mode 100644 index 0000000..d3fb581 --- /dev/null +++ b/backend/app/Http/Controllers/UserController.php @@ -0,0 +1,48 @@ +username != $user->username){ + abort(403); + } + $user->username = $request->username; + $user->email = $request->email; + $user->save(); + return $user; + } + public function updatePassword(User $user, Request $request){ + if (!Auth::check()){ + abort(403); + } + if(Auth::user()->username != $user->username){ + abort(403); + } + $user->makeVisible(['password']); + if (Hash::check($request->oldPassword, $user->password)) { + $user->password = Hash::make($request->newPassword); + $user->save(); + return $user; + } else { + abort(406); + } + } +} diff --git a/backend/database/migrations/2014_10_12_000000_create_users_table.php b/backend/database/migrations/2014_10_12_000000_create_users_table.php index 4371110..519d3ee 100644 --- a/backend/database/migrations/2014_10_12_000000_create_users_table.php +++ b/backend/database/migrations/2014_10_12_000000_create_users_table.php @@ -13,7 +13,7 @@ public function up(): void { Schema::create('users', function (Blueprint $table) { $table->id(); - $table->string('username'); + $table->string('username')->unique(); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); diff --git a/backend/routes/api.php b/backend/routes/api.php index af7f465..99e952b 100644 --- a/backend/routes/api.php +++ b/backend/routes/api.php @@ -28,6 +28,10 @@ Route::get('track/proposals', [\App\Http\Controllers\TrackController::class, 'proposals']); Route::post('track/users', [\App\Http\Controllers\TrackController::class, 'addUserToTrack']); - Route::post('proposals', [\App\Http\Controllers\ProposalController::class, 'create']); Route::get('proposal/{proposal}', [\App\Http\Controllers\ProposalController::class, 'show']); + + +Route::get('user', [\App\Http\Controllers\UserController::class, 'me']); +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 b4c224e..40a41dd 100644 --- a/frontend/src/components/Header.vue +++ b/frontend/src/components/Header.vue @@ -1,5 +1,6 @@