validate([ 'email' => ['required', 'email', 'max:255'], ]); $customer = $this->authService->sendPasswordResetLink($request->input('email')); if ($customer) { $this->activityLogger->log( event: 'password_forgot', logName: 'Customer', description: "Customer {$customer->email} yêu cầu link đặt lại mật khẩu", subject: $customer, ); } // Do not disclose whether the email exists. return response()->json([ 'error' => false, 'message' => 'Nếu email tồn tại, link đặt lại mật khẩu đã được gửi đến hộp thư của bạn.', ]); } public function showResetToken(string $token) { $customer = PasswordResetToken::findCustomer($token); if (!$customer) { return response()->json([ 'error' => true, 'message' => 'Link đặt lại mật khẩu không hợp lệ hoặc đã hết hạn.', ], 404); } return response()->json(['error' => false, 'data' => ['email' => $customer->email]]); } public function resetPassword(Request $request) { $data = $request->validate([ 'token' => ['required', 'string', 'size:' . PasswordResetToken::LENGTH], 'password' => ['required', Password::min(10), 'confirmed'], ]); $customer = $this->authService->resetPassword($data['token'], $data['password']); $this->activityLogger->log( event: 'password_reset', logName: 'Customer', description: "Customer {$customer->email} đặt lại mật khẩu qua email", subject: $customer, ); return response()->json([ 'error' => false, 'message' => 'Đặt lại mật khẩu thành công, vui lòng đăng nhập lại.', ]); } public function changePassword(ClientChangePasswordRequest $request) { $user = auth('client')->user(); try { $this->authService->changePassword( $user, $request->input('current_password'), $request->input('password'), ); } catch (\Illuminate\Validation\ValidationException $e) { return response()->json([ 'error' => true, 'message' => collect($e->errors())->flatten()->first(), ], 422); } $this->activityLogger->log( event: 'password_change', logName: 'Customer', description: "Customer {$user->email} đã đổi mật khẩu", subject: $user, ); return response()->json([ 'error' => false, 'message' => 'Đổi mật khẩu thành công', ]); } }