[ [ 'code' => 'InvalidPasswordProvidedException', 'status' => '400', 'detail' => 'The password provided was invalid for this account.', ], ], ]; private const array THROTTLED_ERROR = [ 'errors' => [ [ 'code' => 'TooManyRequestsHttpException', 'status' => '429', 'detail' => 'Your email address has been changed too many times today. Please try again later.', ], ], ]; #[Endpoint('Get account', 'Returns profile details for the authenticated user.')] #[ResponseFromResource(AccountResource::class, User::class, resourceKey: 'user')] public function index(Request $request): AccountResource { return AccountResource::make($request->user()); } /** * Update the authenticated user's email address. */ #[Endpoint('Update account email', "Updates the authenticated user's email address after verifying their current password.")] #[BodyParam('password', 'string', 'The current account password.', required: true, example: 'current-password')] #[ScribeResponse(status: 204, description: 'Email address updated.')] #[ScribeResponse(self::INVALID_PASSWORD_ERROR, status: 400, description: 'The current password is invalid.')] #[ScribeResponse(self::THROTTLED_ERROR, status: 429, description: 'The account has changed email too many times in the current throttle window.')] public function updateEmail(UpdateEmailRequest $request, UpdatesUserEmails $emails): JsonResponse { $emails->update($request->user(), $request->string('email')->toString()); return new JsonResponse([], Response::HTTP_NO_CONTENT); } /** * Update the authenticated user's password. All existing sessions will be logged * out immediately. * * @throws Throwable */ #[Endpoint('Update account password', "Updates the authenticated user's password and revokes other active sessions where supported.")] #[BodyParam('current_password', 'string', 'The current account password.', required: true, example: 'current-password')] #[BodyParam('password_confirmation', 'string', 'Confirmation matching the new password.', required: true, example: 'correct-horse-battery-staple')] #[ScribeResponse(status: 204, description: 'Password updated.')] #[ScribeResponse(self::INVALID_PASSWORD_ERROR, status: 400, description: 'The current password is invalid.')] public function updatePassword(UpdatePasswordRequest $request, UpdatesUserPasswords $passwords): JsonResponse { $passwords->update($request->user(), $request->string('password')->toString()); return new JsonResponse([], Response::HTTP_NO_CONTENT); } #[Endpoint('Update account avatar', "Stores the uploaded image as the authenticated user's avatar and deletes the one it replaces.")] #[BodyParam('avatar', 'file', 'PNG, JPEG, SVG, WebP, AVIF or ICO image of at most 10 MiB.', required: true)] #[ResponseFromResource(AccountResource::class, User::class, description: 'Avatar updated.', resourceKey: 'user')] public function updateAvatar(UpdateAvatarRequest $request, ReplacesUserAvatars $avatars): AccountResource { return AccountResource::make($avatars->replace($request->user(), $request->avatar())); } #[Endpoint('Delete account avatar', "Deletes the authenticated user's avatar.")] #[ScribeResponse(status: 204, description: 'Avatar deleted.')] public function deleteAvatar(Request $request, ReplacesUserAvatars $avatars): JsonResponse { $avatars->replace($this->authenticatedUser($request), null); return new JsonResponse([], Response::HTTP_NO_CONTENT); } }