From 897bd0ff930bccaad8e316d5a146c81971d97bd7 Mon Sep 17 00:00:00 2001 From: dkecskes Date: Tue, 4 Nov 2025 18:43:20 +0100 Subject: [PATCH] Refactor password change method --- .../Controllers/Auth/RegisteredUserController.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/backend/app/Http/Controllers/Auth/RegisteredUserController.php b/backend/app/Http/Controllers/Auth/RegisteredUserController.php index f551047..13c9e3c 100644 --- a/backend/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/backend/app/Http/Controllers/Auth/RegisteredUserController.php @@ -92,14 +92,15 @@ class RegisteredUserController extends Controller return response()->noContent(); } - public function activate(Request $request) { + public function activate(Request $request) + { $request->validate([ 'token' => ['required', 'string', 'exists:users,activation_token'], 'password' => ['required', 'string', 'min:8'], ]); $user = User::where('activation_token', '=', $request->token)->first(); - + if (!$user) { return response()->json(['message' => 'Invalid activation token'], 400); } @@ -155,17 +156,13 @@ class RegisteredUserController extends Controller { $user = auth()->user(); - if ($user->role !== 'STUDENT') { - return response()->json(['message' => 'Only students...'], 403); - } - $request->validate([ - 'password' => ['required', 'string', 'min:8', 'confirmed'], + 'password' => ['required', 'string', 'min:8'], ]); $user->password = Hash::make($request->password); $user->save(); - return response()->json(['message' => 'Password successfully changed.']); + return response()->noContent(); } } \ No newline at end of file