user(); return new UserResource($user); } /** * Update the current user * * This endpoint is independent of the organization. * * @operationId updateUser */ public function update(User $user, UserUpdateRequest $request): UserResource { if ($user->getKey() !== $this->user()->getKey()) { throw new AuthorizationException; } if ($request->hasPhotoKey()) { $photoDisk = (string) config('jetstream.profile_photo_disk', 'public'); $previousPhotoPath = $user->profile_photo_path; $newPhoto = $request->getPhoto(); if ($newPhoto === null) { $user->profile_photo_path = null; } else { $decoded = Base64File::decode($newPhoto); assert($decoded !== null); $extension = Base64File::extension($decoded['mime_type']); assert($extension !== null); $photoPath = 'profile-photos/'.Str::uuid().'.'.$extension; Storage::disk($photoDisk)->put($photoPath, $decoded['data'], 'public'); $user->profile_photo_path = $photoPath; } if ($previousPhotoPath !== null) { Storage::disk($photoDisk)->delete($previousPhotoPath); } } $emailToVerify = null; $email = $request->getEmail(); if ($email !== null && $email !== Str::lower($user->email)) { $emailToVerify = $email; $user->pending_email = $email; } if ($request->getName() !== null) { $user->name = $request->getName(); } if ($request->getTimezone() !== null) { $user->timezone = $request->getTimezone(); } if ($request->getWeekStart() !== null) { $user->week_start = $request->getWeekStart(); } $user->save(); if ($emailToVerify !== null) { Mail::to($emailToVerify)->send(new VerifyUpdatedEmailMail($user, $emailToVerify)); } return new UserResource($user); } /** * Resend the pending email update verification email. * * This endpoint is independent of the organization. * * @operationId resendUserEmailVerification * * @throws AuthorizationException Thrown when the authenticated user does not match the user whose email is pending verification. * @throws UserResendEmailVerificationNoPendingEmailApiException Thrown when the user does not have a pending email to verify. */ public function resendEmailVerification(User $user): JsonResponse { if ($user->getKey() !== $this->user()->getKey()) { throw new AuthorizationException; } if ($user->pending_email === null) { throw new UserResendEmailVerificationNoPendingEmailApiException; } Mail::to($user->pending_email) ->queue(new VerifyUpdatedEmailMail($user, $user->pending_email)); return response()->json(null, 204); } /** * Handles the deletion of a user. * * This endpoint is independent of the organization. * * @operationId deleteUser * * @param User $user The user instance to be deleted. * @param DeletionService $deletionService The service responsible for performing the user deletion. * @return JsonResponse A JSON response with a 204 No Content status upon successful deletion. * * @throws AuthorizationException Thrown when the authenticated user does not match the user to be deleted. * @throws CanNotDeleteUserWhoIsOwnerOfOrganizationWithMultipleMembers Thrown when the user to be deleted is the owner of an organization with multiple members. */ public function destroy(User $user, DeletionService $deletionService): JsonResponse { if ($user->getKey() !== $this->user()->getKey()) { throw new AuthorizationException; } $deletionService->deleteUser($user); return response()->json(null, 204); } }