getOrCreateQrSetting(); return response()->json([ 'data' => [ 'profile' => [ 'name' => $account->name, 'email' => $account->email, ], 'notifications' => [ 'notify_email' => $settings->notify_email ?: $account->email, 'product_updates' => (bool) ($settings->product_updates ?? true), 'notify_registrations' => (bool) ($settings->notify_registrations ?? true), 'notify_payouts' => (bool) ($settings->notify_payouts ?? true), ], ], ]); } public function updateSettings(Request $request): JsonResponse { $account = ladill_account(); $data = $request->validate([ 'notify_email' => ['nullable', 'email', 'max:255'], 'product_updates' => ['sometimes', 'boolean'], 'notify_registrations' => ['sometimes', 'boolean'], 'notify_payouts' => ['sometimes', 'boolean'], ]); $settings = QrSetting::updateOrCreate( ['user_id' => $account->id], [ 'notify_email' => $data['notify_email'] ?? $account->email, 'product_updates' => $request->boolean('product_updates'), 'notify_registrations' => $request->boolean('notify_registrations'), 'notify_payouts' => $request->boolean('notify_payouts'), ], ); return response()->json([ 'data' => [ 'notify_email' => $settings->notify_email, 'product_updates' => (bool) $settings->product_updates, 'notify_registrations' => (bool) $settings->notify_registrations, 'notify_payouts' => (bool) $settings->notify_payouts, ], ]); } public function updateProfile(Request $request): JsonResponse { $account = ladill_account(); $data = $request->validate([ 'name' => ['required', 'string', 'max:255'], 'phone_cc' => ['nullable', 'string', 'max:8'], 'phone' => ['nullable', 'string', 'max:32'], ]); $response = $this->identitySend('PUT', '/api/identity/profile', array_merge( ['user' => $account->public_id], $data, )); $this->rethrowValidation($response, 'name'); if ($response->successful()) { $account->update(['name' => $data['name']]); } return response()->json([ 'data' => ['name' => $account->fresh()->name, 'email' => $account->email], ]); } public function changePassword(Request $request): JsonResponse { $account = ladill_account(); $request->validate([ 'current_password' => ['required', 'string'], 'password' => ['required', 'string', 'min:8', 'confirmed'], ]); $response = $this->identitySend('POST', '/api/identity/auth/change-password', [ 'user' => $account->public_id, 'current_password' => $request->string('current_password'), 'password' => $request->string('password'), 'password_confirmation' => $request->string('password_confirmation'), ]); $this->rethrowValidation($response, 'current_password'); return response()->json(['data' => ['message' => 'Password updated.']]); } }